Fix N-player lobby: premature start, unready for seat 3+, stale reconnect
GameLobbyReadyHandler: change else→else if (isGuest) so additional players (seat 3+) no longer incorrectly set GuestReady=true. When Player 3 called ready the else-branch marked GuestReady, making the all-ready check fire as soon as the host was also ready — starting the game without Player 2 ever clicking ready, leaving 2/3 clients in a starting state and 1 stuck in the lobby. Also: update DeckId for additional players in AdditionalPlayersJson; push ready_status to additional player connections. GameUnreadyHandler: handle additional players (seat 3+) by updating isReady in AdditionalPlayersJson via JsonNode; push unready status to all participants including additional players. Previously threw NOT_IN_LOBBY for anyone beyond the primary guest. Game.gd: guard _on_auth_reconnect with 'state is non-empty' so stale session_id values from ended games don't trigger spurious game.ready calls. Also clear session_id in the game.over handler so it never lingers past the end of a session. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -81,23 +81,27 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
throw new GameException("NOT_IN_LOBBY");
|
||||
|
||||
// Update deck and first-turn pref, then mark ready.
|
||||
// IMPORTANT: additional players (isAdditional) must NOT fall into the else-guest branch,
|
||||
// as that would incorrectly set GuestReady = true and trigger premature game start.
|
||||
if (isHost)
|
||||
{
|
||||
lobby.HostDeckId = req.DeckId;
|
||||
lobby.HostFirstTurnPref = req.FirstTurnPref;
|
||||
lobby.HostReady = true;
|
||||
}
|
||||
else
|
||||
else if (isGuest)
|
||||
{
|
||||
lobby.GuestDeckId = req.DeckId;
|
||||
lobby.GuestFirstTurnPref = req.FirstTurnPref;
|
||||
lobby.GuestReady = true;
|
||||
}
|
||||
// For additional players (isAdditional): readiness is tracked in AdditionalPlayersJson below.
|
||||
// Do NOT touch HostReady / GuestReady here.
|
||||
|
||||
await _gameDb.SaveChangesAsync(ct);
|
||||
|
||||
// Update readiness in AdditionalPlayersJson for players 3+.
|
||||
if (!isHost && !isGuest && lobby.AdditionalPlayersJson != null)
|
||||
// Update readiness and deck in AdditionalPlayersJson for players 3+.
|
||||
if (isAdditional && lobby.AdditionalPlayersJson != null)
|
||||
{
|
||||
var addl = JsonSerializer.Deserialize<List<AdditionalLobbyPlayerReady>>(
|
||||
lobby.AdditionalPlayersJson,
|
||||
@@ -105,12 +109,15 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
?? new();
|
||||
var entry = addl.FirstOrDefault(p => p.AccountId == accountId);
|
||||
if (entry != null)
|
||||
{
|
||||
entry.IsReady = true;
|
||||
entry.DeckId = req.DeckId;
|
||||
}
|
||||
lobby.AdditionalPlayersJson = JsonSerializer.Serialize(addl);
|
||||
await _gameDb.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
// Push updated ready status to all participants.
|
||||
// Push updated ready status to all participants (host, guest, and additional players).
|
||||
var readyPush = ServerMessage.Push("game.custom.lobby.ready_status",
|
||||
new LobbyReadyStatusPush(lobby.Id, lobby.HostReady, lobby.GuestReady));
|
||||
|
||||
@@ -120,6 +127,13 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
|
||||
};
|
||||
if (lobby.GuestAccountId.HasValue)
|
||||
pushTasks.Add(_clientPush.PushAsync(lobby.GuestAccountId.Value.ToString(), readyPush, ct));
|
||||
if (lobby.AdditionalPlayersJson != null)
|
||||
{
|
||||
var addlPush = JsonSerializer.Deserialize<List<AdditionalLobbyPlayer>>(lobby.AdditionalPlayersJson);
|
||||
if (addlPush != null)
|
||||
foreach (var ap in addlPush)
|
||||
pushTasks.Add(_clientPush.PushAsync(ap.AccountId.ToString(), readyPush, ct));
|
||||
}
|
||||
await Task.WhenAll(pushTasks);
|
||||
|
||||
// All-ready check: host + guest must be ready; for 3+ players all must be ready.
|
||||
|
||||
Reference in New Issue
Block a user