mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-05-06 09:28:18 +00:00
60 lines
1.7 KiB
Ruby
60 lines
1.7 KiB
Ruby
module W3DHubLauncher
|
|
class Worker
|
|
Response = Data.define(:status, :request_id, :data)
|
|
|
|
def initialize
|
|
@threads = []
|
|
@requests = []
|
|
|
|
@settings = # Settings.new
|
|
|
|
# next available request_id to assign incoming requests
|
|
@request_id = 0
|
|
|
|
# listen for requests from frontend
|
|
listener = Thread.new { listen }
|
|
# connect to and monitor GSH web service
|
|
@threads << Thread.new { game_server_hub_websocket }
|
|
# connect to and monitor Backend web service
|
|
@threads << Thread.new { backend_websocket }
|
|
|
|
@w3dhub_api = W3DHubLauncher::W3DHubApi.new
|
|
|
|
listener.join
|
|
end
|
|
|
|
def listen
|
|
loop do
|
|
query = Ractor.receive
|
|
pp query
|
|
|
|
case query.type
|
|
when Request::FETCH_URL
|
|
when Request::DOWNLOAD_URL
|
|
when Request::W3DHUB_API_CALL
|
|
Async do
|
|
result = @w3dhub_api.send(query.data[:call], *(query.data[:arguments] || []))
|
|
response = Response.new(result.okay? ? Request::STATUS_COMPLETE : Request::STATUS_ERROR, query.request_id, result)
|
|
Ractor.main.send(response)
|
|
end
|
|
when Request::LAUNCHER_UPDATE_SETTINGS
|
|
result = CyberarmEngine::Result.new
|
|
FileUtils.mkdir_p(W3DHubLauncher::CONFIG_PATH) # FAILABLE!
|
|
File.write("#{W3DHubLauncher::CONFIG_PATH}/settings.json", query.data) # FAILABLE!
|
|
result.data = query.data
|
|
response = Response.new(result.okay? ? Request::STATUS_COMPLETE : Request::STATUS_ERROR, query.request_id, result)
|
|
Ractor.main.send(response)
|
|
else
|
|
raise "UNKNOWN REQUEST"
|
|
end
|
|
end
|
|
end
|
|
|
|
def game_server_hub_websocket
|
|
end
|
|
|
|
def backend_websocket
|
|
end
|
|
end
|
|
end
|