Fix up Play Now server selection logic, again 😁

This commit is contained in:
2026-01-20 15:36:57 -06:00
parent d4e4697983
commit e2496d0a09

View File

@@ -251,18 +251,22 @@ class W3DHub
server_options = Store.server_list.select do |server| server_options = Store.server_list.select do |server|
server.game == app_id && server.game == app_id &&
server.channel == channel && server.channel == channel &&
!server.status.password && !server.status.password &&
server.status.player_count < server.status.max_players server.status.player_count < server.status.max_players
end
# sort by player count HIGH to LOW
# and by ping LOW to HIGH
server_options.sort! do |a, b|
[b.status.player_count, a.ping] <=> [a.status.player_count, b.ping]
end end
server_options.sort_by! { |s| [s.status.player_count, s.ping] }.reverse!
# try to find server with lowest ping and matching version # try to find server with lowest ping and matching version
found_server = server_options.find { |server| server.version == app_data[:installed_version] } found_server = server_options.find { |server| server.version == app_data[:installed_version] }
# try to find server with lowest ping and undefined version # try to find server with lowest ping and undefined version
found_server ||= server_options.find { |server| server.version == Api::ServerListServer::NO_OR_DEFAULT_VERSION } found_server ||= server_options.find { |server| server.version == Api::ServerListServer::NO_OR_DEFAULT_VERSION }
found_server || nil found_server
end end
def play_now(app_id, channel) def play_now(app_id, channel)