mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Updated server browser to order servers by player count, then by ping.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
class W3DHub
|
class W3DHub
|
||||||
class Api
|
class Api
|
||||||
class ServerListServer
|
class ServerListServer
|
||||||
|
NO_OR_BAD_PING = 1_000_000
|
||||||
|
|
||||||
attr_reader :id, :game, :address, :port, :region, :channel, :ping, :status
|
attr_reader :id, :game, :address, :port, :region, :channel, :ping, :status
|
||||||
|
|
||||||
def initialize(hash)
|
def initialize(hash)
|
||||||
@@ -12,7 +14,7 @@ class W3DHub
|
|||||||
@port = @data[:port]
|
@port = @data[:port]
|
||||||
@region = @data[:region]
|
@region = @data[:region]
|
||||||
@channel = @data[:channel] || "release"
|
@channel = @data[:channel] || "release"
|
||||||
@ping = -1
|
@ping = NO_OR_BAD_PING
|
||||||
|
|
||||||
@status = Status.new(@data[:status])
|
@status = Status.new(@data[:status])
|
||||||
|
|
||||||
@@ -55,7 +57,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ping = -1 if @ping.zero?
|
@ping = NO_OR_BAD_PING if @ping.zero?
|
||||||
|
|
||||||
@ping
|
@ping
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -196,11 +196,11 @@ class W3DHub
|
|||||||
|
|
||||||
def ping_icon(server)
|
def ping_icon(server)
|
||||||
case server.ping
|
case server.ping
|
||||||
when 0..160
|
when 0..150
|
||||||
@ping_icons[:good]
|
@ping_icons[:good]
|
||||||
when 161..250
|
when 151..200
|
||||||
@ping_icons[:fair]
|
@ping_icons[:fair]
|
||||||
when 251..1_000
|
when 201..1_000
|
||||||
@ping_icons[:poor]
|
@ping_icons[:poor]
|
||||||
when 1_001..5_000
|
when 1_001..5_000
|
||||||
@ping_icons[:bad]
|
@ping_icons[:bad]
|
||||||
@@ -210,7 +210,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ping_tip(server)
|
def ping_tip(server)
|
||||||
server.ping.negative? ? "Ping failed" : "Ping #{server.ping}ms"
|
server.ping == W3DHub::Api::ServerListServer::NO_OR_BAD_PING ? "Ping failed" : "Ping #{server.ping}ms"
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_element_by_tag(container, tag, list = [])
|
def find_element_by_tag(container, tag, list = [])
|
||||||
@@ -292,7 +292,7 @@ class W3DHub
|
|||||||
@server_list_container.children.sort_by! do |child|
|
@server_list_container.children.sort_by! do |child|
|
||||||
s = Store.server_list.find { |s| s.id == child.style.tag }
|
s = Store.server_list.find { |s| s.id == child.style.tag }
|
||||||
|
|
||||||
[s.status.player_count, s.id]
|
[s.status.player_count, -s.ping]
|
||||||
end.reverse!.each_with_index do |child, i|
|
end.reverse!.each_with_index do |child, i|
|
||||||
next if @selected_server_container && child == @selected_server_container
|
next if @selected_server_container && child == @selected_server_container
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user