From 9c7dc098aa753aa1a379432b8c7d4007affed82d Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 26 Mar 2026 09:05:40 -0400 Subject: [PATCH] Fix 3 multiplayer bugs: type error, reconnect, lobby count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - game_screen.gd: fix Parser Error on line 270 — use 'as Environment' cast instead of ': Variant' annotation for WorldEnvironment.environment - Game.gd: auto-resend game.ready on auth_success reconnect so the game session is restored when the WebSocket reconnects mid-game - lobby_browser_row.gd: show real N/Max player count instead of hardcoded "1/2" / "2/2" - CustomLobbyDto: add MaxPlayers, CurrentPlayerCount, GameMode, TeamCount - GameListCustomLobbiesHandler: compute currentPlayerCount from GuestAccountId + AdditionalPlayersJson; pass new fields to DTO Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- Client/origin-client/autoloads/Game.gd | 9 +++++++ .../free_play/components/lobby_browser_row.gd | 7 ++--- .../origin-client/scenes/game/game_screen.gd | 2 +- Server/src/SOR.Game/GameMessages.cs | 6 ++++- .../Handlers/GameListCustomLobbiesHandler.cs | 26 +++++++++++++++++-- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Client/origin-client/autoloads/Game.gd b/Client/origin-client/autoloads/Game.gd index 5fba220..ec77f6e 100644 --- a/Client/origin-client/autoloads/Game.gd +++ b/Client/origin-client/autoloads/Game.gd @@ -59,6 +59,7 @@ var _state_version : int = -1 func _ready() -> void: Network.message_received.connect(_on_server_push) Auth.session_expired.connect(_clear_state) + Auth.auth_success.connect(_on_auth_reconnect) func _clear_state() -> void: @@ -69,6 +70,14 @@ func _clear_state() -> void: _state_version = -1 +## Called on every auth_success (initial login AND reconnects). +## If we have an active session, resend game.ready so the server +## re-registers this connection and we get state updates again. +func _on_auth_reconnect(_uid: String, _dn: String) -> void: + if not session_id.is_empty(): + send_ready() + + ## Start spectating a game session. State is applied from the server ack. func start_spectating(sid: String) -> void: is_spectating = true diff --git a/Client/origin-client/scenes/free_play/components/lobby_browser_row.gd b/Client/origin-client/scenes/free_play/components/lobby_browser_row.gd index a60e76c..7fe736d 100644 --- a/Client/origin-client/scenes/free_play/components/lobby_browser_row.gd +++ b/Client/origin-client/scenes/free_play/components/lobby_browser_row.gd @@ -14,14 +14,15 @@ var _has_password: bool = false func setup(lobby: Dictionary, has_deck: bool) -> void: var has_pw : bool = lobby.get("rules", {}).get("hasPassword", false) - var has_guest : bool = lobby.get("hasGuest", false) var host_name : String = lobby.get("hostDisplayName", "?") + var cur_p : int = int(lobby.get("currentPlayerCount", 1 + (1 if lobby.get("hasGuest", false) else 0))) + var max_p : int = int(lobby.get("maxPlayers", 2)) _lobby_id = str(lobby.get("lobbyId", "")) _has_password = has_pw name_label.text = lobby.get("lobbyName", "?") - host_label.text = "Host: %s [%s]" % [host_name, "2/2" if has_guest else "1/2"] + host_label.text = "Host: %s [%d/%d]" % [host_name, cur_p, max_p] password_icon.visible = has_pw - join_btn.disabled = not has_deck + join_btn.disabled = not has_deck or cur_p >= max_p join_btn.pressed.connect(func(): join_requested.emit(_lobby_id, _has_password), CONNECT_ONE_SHOT) diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 678c542..1531195 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -267,7 +267,7 @@ func _ready() -> void: func _process(delta: float) -> void: - var env := $WorldEnvironment.environment + var env := $WorldEnvironment.environment as Environment if env != null: env.sky_rotation.y += delta * SKY_ROTATION_SPEED diff --git a/Server/src/SOR.Game/GameMessages.cs b/Server/src/SOR.Game/GameMessages.cs index cc50353..060cde2 100644 --- a/Server/src/SOR.Game/GameMessages.cs +++ b/Server/src/SOR.Game/GameMessages.cs @@ -622,7 +622,11 @@ public sealed record CustomLobbyDto( bool HasGuest, string? GuestDisplayName, CustomRulesDto Rules, - DateTimeOffset CreatedAt); + DateTimeOffset CreatedAt, + int MaxPlayers = 2, + int CurrentPlayerCount = 1, + string GameMode = "FFA", + int TeamCount = 1); /// Summary of an in-progress custom game, shown in the Active Games browser. public sealed record ActiveLobbyDto( diff --git a/Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs b/Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs index e995fe7..06d30c1 100644 --- a/Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs @@ -1,5 +1,6 @@ namespace SOR.Game.Handlers; +using System.Text.Json; using Microsoft.EntityFrameworkCore; using SOR.Database.Contexts; using SOR.Database.Enums; @@ -72,7 +73,23 @@ internal sealed class GameListCustomLobbiesHandler : GameHandlerBase, IMessageHa .Select(a => new { a.Id, Name = a.DisplayName ?? a.UserName ?? a.Id.ToString() }) .ToDictionaryAsync(a => a.Id, a => a.Name, ct); - var dtos = lobbies.Select(l => new CustomLobbyDto( + var dtos = lobbies.Select(l => + { + var additionalCount = 0; + if (l.AdditionalPlayersJson is not null) + { + try + { + var arr = JsonSerializer.Deserialize(l.AdditionalPlayersJson); + additionalCount = arr?.Length ?? 0; + } + catch { } + } + var currentPlayerCount = 1 + + (l.GuestAccountId.HasValue ? 1 : 0) + + additionalCount; + + return new CustomLobbyDto( LobbyId : l.Id, LobbyName : l.Name, HostAccountId : l.HostAccountId, @@ -101,7 +118,12 @@ internal sealed class GameListCustomLobbiesHandler : GameHandlerBase, IMessageHa MpBuff : l.MpBuffOverride ?? GameRules.Default.MpBuff, StartingRandomTilePct : l.StartingRandomTilePctOverride ?? GameRules.Default.StartingRandomTilePct, HasPassword : l.Password != null), - CreatedAt : l.CreatedAt)); + CreatedAt : l.CreatedAt, + MaxPlayers : l.MaxPlayers, + CurrentPlayerCount : currentPlayerCount, + GameMode : l.GameMode, + TeamCount : l.TeamCount); + }); return ServerMessage.Reply("game.custom.list.ack", message.Seq, new ListCustomLobbiesResponse(