mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 01:02:34 +00:00
Added semi-functional websocket implementation of signalR for live server list changes (seems a bit chatty though with some servers only having time remaining changing, fixed crash when a user has an active login but their profile picture was removed, fixed not explicitly saving Cache.fetch'ed items as binary 'wb' resulting in corrupt profile image.
This commit is contained in:
60
lib/api/server_list_updater.rb
Normal file
60
lib/api/server_list_updater.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
class W3DHub
|
||||
class Api
|
||||
class ServerListUpdater
|
||||
class Connection < ::Protocol::WebSocket::Connection
|
||||
def read
|
||||
if (buffer = super)
|
||||
buffer.split("\x1e").map { |json| parse(json) }
|
||||
end
|
||||
end
|
||||
|
||||
def read1
|
||||
read1&.first
|
||||
end
|
||||
|
||||
def write(object)
|
||||
super(dump(object) + "\x1e")
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Properly start up and monitor for updates to server list
|
||||
def initialize
|
||||
Async do |task|
|
||||
headers = [["User-Agent", "Cyberarm's Websocket Testing"]]
|
||||
|
||||
internet = Async::HTTP::Internet.instance
|
||||
|
||||
response = internet.post("https://gsh.w3dhub.com/listings/push/v2/negotiate?negotiateVersion=1", headers, [""])
|
||||
data = JSON.parse(response.read, symbolize_names: true)
|
||||
|
||||
# TODO: Replace with Api.server_list
|
||||
response = internet.get("https://gsh.w3dhub.com/listings/getAll/v2?statusLevel=2", headers, [""])
|
||||
servers = JSON.parse(response.read, symbolize_names: true)
|
||||
|
||||
id = data[:connectionToken]
|
||||
endpoint = Async::HTTP::Endpoint.parse("https://gsh.w3dhub.com/listings/push/v2?id=#{id}", alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
|
||||
|
||||
Async::WebSocket::Client.connect(endpoint, headers: headers, handler: WSS::Connection) do |connection|
|
||||
connection.write({ protocol: "json", version: 1 })
|
||||
connection.flush
|
||||
pp connection.read
|
||||
connection.write({ "type": 6 })
|
||||
|
||||
servers.each_with_index do |server, i|
|
||||
i += 1
|
||||
out = { "type": 1, "invocationId": "#{i}", "target": "SubscribeToServerStatusUpdates", "arguments": [server[:id], 2] }
|
||||
connection.write(out)
|
||||
end
|
||||
|
||||
while (message = connection.read)
|
||||
connection.write({ type: 6 }) if message.first[:type] == 6
|
||||
|
||||
# TODO: process messages (of type 3?)
|
||||
pp message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -15,8 +15,8 @@ class W3DHub
|
||||
else
|
||||
response = internet.get(uri, [["user-agent", W3DHub::Api::USER_AGENT]])
|
||||
|
||||
if response.success?#status == 200
|
||||
response.save(path)
|
||||
if response.success?
|
||||
response.save(path, "wb")
|
||||
|
||||
path
|
||||
end
|
||||
|
||||
@@ -48,9 +48,10 @@ class W3DHub
|
||||
|
||||
Cache.fetch(internet, account.avatar_uri)
|
||||
|
||||
populate_account_info; page(W3DHub::Pages::Games)
|
||||
populate_account_info
|
||||
page(W3DHub::Pages::Games)
|
||||
else
|
||||
# An error occurred, enable account entry
|
||||
# An error occurred, enable account entry
|
||||
# NOTE: Too many incorrect entries causes lock out (Unknown duration)
|
||||
@username.enabled = true
|
||||
@password.enabled = true
|
||||
@@ -68,8 +69,13 @@ class W3DHub
|
||||
end
|
||||
|
||||
if Store.account
|
||||
populate_account_info
|
||||
page(W3DHub::Pages::Games)
|
||||
Async do
|
||||
internet = Async::HTTP::Internet.instance
|
||||
Cache.fetch(internet, Store.account.avatar_uri)
|
||||
|
||||
populate_account_info
|
||||
page(W3DHub::Pages::Games)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user