Retrieval and display of game servers is now working

This commit is contained in:
2026-09-04 18:55:57 -05:00
parent 7524d01347
commit 7f716a57ca
6 changed files with 117 additions and 23 deletions

View File

@@ -151,11 +151,20 @@ module W3DHubLauncher
def step_server_list def step_server_list
@initialization_container.append do @initialization_container.append do
tagline "Requesting server listing..." tagline "Requesting server listing..."
caption "Found 21 servers <c=0f0>OK</c>", margin_left: LARGE_PADDING
end end
after(1000) do Worker::Api.servers do |result|
next_step @initialization_container.append do
if result.okay?
MemCache[:servers] = JSON.parse(result.data).map { |s| Worker::Api::GameServer.new(s) }
caption "Received #{MemCache[:servers].size} servers <c=0f0>OK</c>", margin_left: LARGE_PADDING
else
caption "Failed to retrieve server listing.", color: 0xff_ff8800, margin_left: LARGE_PADDING
end
next_step
end
end end
end end

View File

@@ -4,45 +4,75 @@ module W3DHubLauncher
include GuiExt include GuiExt
def setup def setup
@games_filter = []
# game bar container # game bar container
flow(width: 1.0, height: 60) do flow(width: 1.0, height: 60) do
flow(width: 220, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: ALPHA_GRAY) do widget(width: 220, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: ALPHA_GRAY, hover: { background_nine_slice_color: ALPHA_BLACK }, active: { background_nine_slice_color: ALPHA_GRAY }) do |w|
flow(width: 1.0, height: 40, margin_left: PADDING, v_align: :center, h_align: :center) do flow(width: 1.0, height: 40, margin_left: PADDING, v_align: :center, h_align: :center) do
image safe_get_image("#{ROOT_PATH}/media/icons/menuGrid.png"), height: 40, color: 0xff_bbbbbb image safe_get_image("#{ROOT_PATH}/media/icons/menuGrid.png"), height: 40, color: 0xff_bbbbbb
link "ALL SERVERS", text_size: 24, font: FONT_BLACK, height: 1.0, text_v_align: :center link "ALL SERVERS", text_size: 24, font: FONT_BLACK, height: 1.0, text_v_align: :center
end end
w.subscribe(:clicked_left_mouse_button) do
@games_filter.clear
populate_server_list
end
end end
flow(fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: ALPHA_GRAY, margin_left: PADDING) do flow(fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: ALPHA_GRAY, margin_left: PADDING) do
image safe_get_image("#{ROOT_PATH}/data/cache/apb.png"), height: 1.0, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0x88_5e5c64, border_thickness_bottom: 3, border_color_bottom: 0xff_3584e4, tip: "Red Alert: A Path Beyond" MemCache[:applications].each do |app|
image safe_get_image("#{ROOT_PATH}/data/cache/ren.png"), height: 1.0, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0, tip: "Command & Conquer: Renegade" next unless app.game?
image safe_get_image("#{ROOT_PATH}/data/cache/tsr.png"), height: 1.0, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0, tip: "Tiberian Sun: Reborn"
image safe_get_image("#{ROOT_PATH}/data/cache/woa.png"), height: 1.0, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0, tip: "Battle for Dune: War of Assassins" image(safe_get_image("#{ROOT_PATH}/data/cache/#{app.id}.png"), height: 1.0, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0x88_5e5c64, border_thickness_bottom: 3, border_color_bottom: 0xff_3584e4, tip: app.name) do |btn|
if shift_down?
@games_filter << app.id
@games_filter.uniq!
else
@games_filter.clear
@games_filter << app.id
end
populate_server_list
end
# image safe_get_image("#{ROOT_PATH}/data/cache/ren.png"), height: 1.0, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0, tip: "Command & Conquer: Renegade"
# image safe_get_image("#{ROOT_PATH}/data/cache/tsr.png"), height: 1.0, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0, tip: "Tiberian Sun: Reborn"
# image safe_get_image("#{ROOT_PATH}/data/cache/woa.png"), height: 1.0, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0, tip: "Battle for Dune: War of Assassins"
end
end end
end end
# game content container # game content container
stack(width: 1.0, fill: true, margin_top: LARGE_PADDING, scroll: true) do @servers_container = stack(width: 1.0, fill: true, margin_top: LARGE_PADDING, scroll: true) do
10.times do end
widget(width: 1.0, height: 48, padding_top: HALF_PADDING, padding_bottom: HALF_PADDING, margin_bottom: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: ALPHA_GRAY, hover: { background_nine_slice_color: 0xff_5e5c64 } , active: { background_nine_slice_color: 0xaa_5e5c64 }) do
# FIXME: Remember and use last used filter
populate_server_list
end
def populate_server_list
@servers_container.clear do
(MemCache[:servers] || []).select { |s| @games_filter.empty? ? true : @games_filter.include?(s.game) }.sort_by { |s| s.player_count }.reverse.each do |server|
app = MemCache[:applications].find { |a| a.id == server.game }
widget(width: 1.0, height: 48, padding_top: HALF_PADDING, padding_bottom: HALF_PADDING, margin_bottom: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: server.channel == "release" ? ALPHA_GRAY : 0xaa_c64600, hover: { background_nine_slice_color: 0xff_5e5c64 } , active: { background_nine_slice_color: 0xaa_5e5c64 }) do
# app icon container # app icon container
image(safe_get_image("#{ROOT_PATH}/data/cache/apb.png"), tip: "Red Alert: A Path Beyond", width: 48, height: 1.0, margin_left: HALF_PADDING) image(safe_get_image("#{ROOT_PATH}/data/cache/#{app.id}.png"), tip: app.name, width: 48, height: 1.0, margin_left: HALF_PADDING)
# friend name and status container
# server name, region, and times container
stack(fill: true, height: 1.0, margin_left: HALF_PADDING) do stack(fill: true, height: 1.0, margin_left: HALF_PADDING) do
stack(v_align: :center) do stack(v_align: :center) do
# server name # server name
server_name = ["Really Long Server Name Goes Here", "[US][W3D Hub] APB Game Night", "[US][W3D Hub] APB Co-op 3.7", "Really Long Server Name Goes Here Really Long Server Name Goes Here"].sample caption server.name, text_wrap: :none, tip: server.name
caption server_name, text_wrap: :none, tip: server_name
# server info # server info
a = ["North America", "South America", "Europe", "Asia", "Antarctica", "Arctica", "Oceania"] inscription "#{server.channel}#{server.region}#{server.time_elapsed} / #{server.match_remaining_time}", text_wrap: :none, margin_top: -HALF_PADDING
inscription "#{a.sample} • 13:52 / #{rand > 0.5 ? '∞' : '30:00'}", text_wrap: :none, margin_top: -HALF_PADDING
end end
end end
# server map # server map
stack(width: 256, height: 1.0, margin_left: HALF_PADDING) do stack(width: 256, height: 1.0, margin_left: HALF_PADDING) do
stack(width: 1.0, fill: true, v_align: :center) do stack(width: 1.0, fill: true, v_align: :center) do
server_map = ["RA_Under", "C&C Superduple Long Map Name Goes Here", "RA_NorthByNorthWest", "RA_HostileWatersParadox", "RA_PacificThreat"].sample caption server.current_map, tip: server.current_map, text_wrap: :none, width: 1.0, text_align: :center
caption server_map, tip: server_map, text_wrap: :none, width: 1.0, text_align: :center
inscription "map", text_wrap: :none, width: 1.0, text_align: :center, margin_top: -HALF_PADDING inscription "map", text_wrap: :none, width: 1.0, text_align: :center, margin_top: -HALF_PADDING
end end
end end
@@ -50,10 +80,11 @@ module W3DHubLauncher
# server player count # server player count
stack(width: 96, height: 1.0, margin_left: HALF_PADDING) do stack(width: 96, height: 1.0, margin_left: HALF_PADDING) do
stack(width: 1.0, fill: true, v_align: :center) do stack(width: 1.0, fill: true, v_align: :center) do
caption format("%d / %d", rand(60), rand(60..127)), width: 1.0, text_align: :center caption format("%d / %d", server.player_count, server.max_players), width: 1.0, text_align: :center
inscription "players", text_wrap: :none, width: 1.0, text_align: :center, margin_top: -HALF_PADDING inscription "players", text_wrap: :none, width: 1.0, text_align: :center, margin_top: -HALF_PADDING
end end
end end
# server ping # server ping
flow(width: 96, height: 1.0, margin_left: HALF_PADDING, margin_right: HALF_PADDING) do flow(width: 96, height: 1.0, margin_left: HALF_PADDING, margin_right: HALF_PADDING) do
stack(fill: true, height: 1.0, v_align: :center) do stack(fill: true, height: 1.0, v_align: :center) do

View File

@@ -110,12 +110,33 @@ module W3DHubLauncher
# ------------ query / request handlers ------------ # ------------ query / request handlers ------------
# #
def fetch_url(query) def fetch_url(query)
result = CyberarmEngine::Result.new
method = query.data["method"]
url = query.data["url"]
headers = query.data["headers"] || DEFAULT_HEADERS
body = query.data["body"]
Sync do |task|
task.with_timeout(DEFAULT_NETWORK_TIMEOUT) do
Async::HTTP::Internet.send(method, url, headers, body) do |response|
if response.success?
result.data = response.read
end
# rescue StandardError => e
# result.error = e
end
# rescue Async::TimeoutError
# result.error = e
end
end
deliver_response(result, query)
end end
def download_url(query) def download_url(query)
result = CyberarmEngine::Result.new result = CyberarmEngine::Result.new
method = query.data["method"] method = query.data["method"]
url = query.data["url"] url = query.data["url"]
path = query.data["path"] path = query.data["path"]
@@ -218,6 +239,22 @@ module W3DHubLauncher
deliver_response(result, query) deliver_response(result, query)
end end
def servers(query)
hash = {
"method" => "get",
"url" => "https://gsh.w3d.cyberarm.dev/listings/getAll/v2?statusLevel=2",
"headers" => DEFAULT_HEADERS,
"body" => query.data["body"]
}
# inject data into query
query = Request::Query.new(query.type, query.request_id, hash)
response = fetch_url(query)
deliver_response(response.result, query)
end
def install_application(query) def install_application(query)
end end

View File

@@ -44,7 +44,8 @@ module W3DHubLauncher
end end
# returns current list of servers as reported from GSH / cache # returns current list of servers as reported from GSH / cache
def self.servers def self.servers(&block)
Worker::Request.new(:servers, "", &block)
end end
# returns news for application # returns news for application

View File

@@ -32,6 +32,10 @@ module W3DHubLauncher
"ff_#{extended_data("colour","#000000").sub("#", "")}".to_i(16) "ff_#{extended_data("colour","#000000").sub("#", "")}".to_i(16)
end end
def game?
@type.include?("game")
end
def servicable? def servicable?
@servicable @servicable
end end

View File

@@ -3,7 +3,10 @@ module W3DHubLauncher
class Api class Api
# Designed to work with cyberarm's Game Server Hub service data, may work with W3D Hub's service with degraded metadata. # Designed to work with cyberarm's Game Server Hub service data, may work with W3D Hub's service with degraded metadata.
class GameServer class GameServer
attr_reader :id, :game, :channel, :address, :port, :region, :version attr_reader :id, :game, :channel, :address, :port, :region,
:name, :password, :current_map, :player_count, :max_players,
:match_start_time, :estimated_end_time, :match_remaining_time,
:teams, :next_map, :version
def initialize(data) def initialize(data)
# main data # main data
@@ -43,6 +46,15 @@ module W3DHubLauncher
@version = data["version"] || "838" @version = data["version"] || "838"
@next_map = data["status"]["nextmap"] || "" @next_map = data["status"]["nextmap"] || ""
end end
# TODO: implement :)
def time_elapsed
"00:00"
end
def password?
@password
end
end end
class Team class Team