Fix 3rd-player lobby ready-up and board shape fallback

3rd-player ready-up (two root causes):
- Server: LobbyReadyStatusPush to additional players was deserialized
  without PropertyNameCaseInsensitive, so after the 3rd player readied
  (converting JSON to camelCase) all subsequent pushes went to Guid.Empty
  → 3rd player never received ready/start notifications
- Client: ready_status push handler treated all non-hosts as "guest",
  so i_am_ready was incorrectly set from guestReady for additional players
  → their ready state was clobbered every time host/guest readied
- Server: JoinCustomLobbyResponse now includes IsAdditionalPlayer flag
  so the client can correctly distinguish guest from 3rd+ player

Board shape fallback:
- GameEngine.cs 2-player overload and GameReadyHandler N-player path both
  now treat "Default"/null BoardShape as AutoShape(playerCount) rather than
  hardcoded "Rectangle", fixing old sessions and ranked matches

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:
dingo
2026-03-26 16:00:15 -04:00
co-authored by Claude Happy
parent cf473d812c
commit e9097214fb
6 changed files with 57 additions and 40 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ public static class GameEngine
{
(p1AccountId, p1Deck, p1ArchSpirit, 0, 0),
(p2AccountId, p2Deck, p2ArchSpirit, 1, 1),
}, "FFA", rules?.BoardShape ?? "Rectangle", rules);
}, "FFA", rules?.BoardShape is null or "" or "Default" ? "Rectangle" : rules.BoardShape, rules);
/// <summary>
/// N-player Initialize overload. Each player entry carries their account ID,
+2 -1
View File
@@ -261,7 +261,8 @@ public sealed record JoinCustomLobbyResponse(
string GuestDisplayName,
int MaxPlayers,
string GameMode,
int TeamCount);
int TeamCount,
bool IsAdditionalPlayer = false); // true for 3rd+ players (not host or first guest)
public sealed record LeaveCustomLobbyResponse(Guid LobbyId);
@@ -169,16 +169,17 @@ internal sealed class GameJoinCustomLobbyHandler : GameHandlerBase, IMessageHand
return ServerMessage.Reply("game.custom.join.ack", message.Seq,
new JoinCustomLobbyResponse(
LobbyId : lobby.Id,
Status : lobby.Status == CustomLobbyStatus.Full ? "WaitingForReady" : "WaitingForPlayers",
ActiveRules : GameCreateCustomLobbyHandler.ToDto(effective, lobby.Password != null, lobby.BoardShapeOverride),
GameSessionId : null,
HostAccountId : lobby.HostAccountId,
HostDisplayName : hostName,
GuestAccountId : accountId,
GuestDisplayName: guestName,
MaxPlayers : lobby.MaxPlayers,
GameMode : lobby.GameMode,
TeamCount : lobby.TeamCount));
LobbyId : lobby.Id,
Status : lobby.Status == CustomLobbyStatus.Full ? "WaitingForReady" : "WaitingForPlayers",
ActiveRules : GameCreateCustomLobbyHandler.ToDto(effective, lobby.Password != null, lobby.BoardShapeOverride),
GameSessionId : null,
HostAccountId : lobby.HostAccountId,
HostDisplayName : hostName,
GuestAccountId : accountId,
GuestDisplayName : guestName,
MaxPlayers : lobby.MaxPlayers,
GameMode : lobby.GameMode,
TeamCount : lobby.TeamCount,
IsAdditionalPlayer : !isFirstGuest));
}
}
@@ -129,7 +129,9 @@ internal sealed class GameLobbyReadyHandler : GameHandlerBase, IMessageHandler
pushTasks.Add(_clientPush.PushAsync(lobby.GuestAccountId.Value.ToString(), readyPush, ct));
if (lobby.AdditionalPlayersJson != null)
{
var addlPush = JsonSerializer.Deserialize<List<AdditionalLobbyPlayer>>(lobby.AdditionalPlayersJson);
var addlPush = JsonSerializer.Deserialize<List<AdditionalLobbyPlayer>>(
lobby.AdditionalPlayersJson,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
if (addlPush != null)
foreach (var ap in addlPush)
pushTasks.Add(_clientPush.PushAsync(ap.AccountId.ToString(), readyPush, ct));
@@ -3,6 +3,7 @@ namespace SOR.Game.Handlers;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using SOR.Database.Contexts;
using SOR.Game.Grid;
using SOR.Database.Entities.Catalog;
using SOR.Database.Entities.Collection;
using SOR.Database.Enums;
@@ -194,11 +195,14 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler
entry.TeamIndex));
}
var boardShape = rules?.BoardShape is null or "" or "Default"
? BoardShapeGenerator.AutoShape(playerList.Count)
: rules.BoardShape;
state = GameEngine.Initialize(
session.Id,
playerList.AsReadOnly(),
session.GameMode,
rules?.BoardShape ?? "Rectangle",
boardShape,
rules);
}