mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 17:22:35 +00:00
Improvements to server list updater, iirc.
This commit is contained in:
@@ -11,7 +11,11 @@ class W3DHub
|
|||||||
@@instance = ServerListUpdater.new
|
@@instance = ServerListUpdater.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_accessor :auto_reconnect
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
@auto_reconnect = false
|
||||||
|
|
||||||
logger.info(LOG_TAG) { "Starting emulated SignalR Server List Updater..." }
|
logger.info(LOG_TAG) { "Starting emulated SignalR Server List Updater..." }
|
||||||
run
|
run
|
||||||
end
|
end
|
||||||
@@ -20,6 +24,11 @@ class W3DHub
|
|||||||
Thread.new do
|
Thread.new do
|
||||||
begin
|
begin
|
||||||
connect
|
connect
|
||||||
|
|
||||||
|
while W3DHub::BackgroundWorker.alive?
|
||||||
|
connect if @auto_reconnect
|
||||||
|
sleep 1
|
||||||
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
puts e
|
puts e
|
||||||
puts e.backtrace
|
puts e.backtrace
|
||||||
@@ -34,7 +43,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def connect
|
def connect
|
||||||
auto_reconnect = false
|
@auto_reconnect = false
|
||||||
|
|
||||||
logger.debug(LOG_TAG) { "Requesting connection token..." }
|
logger.debug(LOG_TAG) { "Requesting connection token..." }
|
||||||
response = Excon.post("https://gsh.w3dhub.com/listings/push/v2/negotiate?negotiateVersion=1", headers: Api::DEFAULT_HEADERS, body: "")
|
response = Excon.post("https://gsh.w3dhub.com/listings/push/v2/negotiate?negotiateVersion=1", headers: Api::DEFAULT_HEADERS, body: "")
|
||||||
@@ -44,7 +53,21 @@ class W3DHub
|
|||||||
endpoint = "https://gsh.w3dhub.com/listings/push/v2?id=#{id}"
|
endpoint = "https://gsh.w3dhub.com/listings/push/v2?id=#{id}"
|
||||||
|
|
||||||
logger.debug(LOG_TAG) { "Connecting to websocket..." }
|
logger.debug(LOG_TAG) { "Connecting to websocket..." }
|
||||||
|
this = self
|
||||||
WebSocket::Client::Simple.connect(endpoint, headers: Api::DEFAULT_HEADERS) do |ws|
|
WebSocket::Client::Simple.connect(endpoint, headers: Api::DEFAULT_HEADERS) do |ws|
|
||||||
|
ws.on(:open) do
|
||||||
|
logger.debug(LOG_TAG) { "Requesting json protocol, v1..." }
|
||||||
|
ws.send({ protocol: "json", version: 1 }.to_json + "\x1e")
|
||||||
|
|
||||||
|
logger.debug(LOG_TAG) { "Subscribing to server changes..." }
|
||||||
|
Store.server_list.each_with_index do |server, i|
|
||||||
|
i += 1
|
||||||
|
mode = 1 # 2 full details, 1 basic details
|
||||||
|
out = { "type": 1, "invocationId": "#{i}", "target": "SubscribeToServerStatusUpdates", "arguments": [server.id, mode] }
|
||||||
|
ws.send(out.to_json + "\x1e")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
ws.on(:message) do |msg|
|
ws.on(:message) do |msg|
|
||||||
msg = msg.data.split("\x1e").first
|
msg = msg.data.split("\x1e").first
|
||||||
|
|
||||||
@@ -60,37 +83,25 @@ class W3DHub
|
|||||||
id, data = hash[:arguments]
|
id, data = hash[:arguments]
|
||||||
server = Store.server_list.find { |s| s.id == id }
|
server = Store.server_list.find { |s| s.id == id }
|
||||||
server_updated = server&.update(data)
|
server_updated = server&.update(data)
|
||||||
States::Interface.instance&.update_server_browser(server) if server_updated
|
|
||||||
|
BackgroundWorker.foreground_job(-> {}, ->(result){ States::Interface.instance&.update_server_browser(server) }) if server_updated
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ws.on(:open) do
|
|
||||||
logger.debug(LOG_TAG) { "Requesting json protocol, v1..." }
|
|
||||||
ws.send({ protocol: "json", version: 1 }.to_json + "\x1e")
|
|
||||||
|
|
||||||
logger.debug(LOG_TAG) { "Subscribing to server changes..." }
|
|
||||||
Store.server_list.each_with_index do |server, i|
|
|
||||||
i += 1
|
|
||||||
mode = 1 # 2 full details, 1 basic details
|
|
||||||
out = { "type": 1, "invocationId": "#{i}", "target": "SubscribeToServerStatusUpdates", "arguments": [server.id, mode] }
|
|
||||||
ws.send(out.to_json + "\x1e")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ws.on(:close) do |e|
|
ws.on(:close) do |e|
|
||||||
p e
|
p e
|
||||||
auto_reconnect = true
|
this.auto_reconnect = true
|
||||||
|
ws.close
|
||||||
end
|
end
|
||||||
|
|
||||||
ws.on(:error) do |e|
|
ws.on(:error) do |e|
|
||||||
p e
|
p e
|
||||||
auto_reconnect = true
|
this.auto_reconnect = true
|
||||||
|
ws.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
connect if auto_reconnect
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user