Phase 4: Spectator support — SpectatorRegistryService + handlers
- SpectatorRegistryService singleton: ConcurrentDictionary<Guid, ImmutableHashSet<Guid>> tracking spectators per session. Static Instance for use in static base-class helpers. - GameEngine.ToDtoSpectator: delegates to ToDto(state, "") — both hands hidden. - GameHandlerBase.PushStateToPlayersAsync: extended to push hand-hidden state_update to all registered spectators via SpectatorRegistryService.Instance. - GameHandlerBase.FinalizeGameAsync: pushes game.over to spectators then calls RemoveSession to evict the entry from the registry. - GameSpectateHandler (game.spectate): validates session Active, registers spectator, returns current spectator-view state as ack. - GameStopSpectatingHandler (game.spectate.stop): unregisters the caller. - GameMessages.cs: SpectateRequest/Response, StopSpectatingRequest/Response. - ServiceRegistration.cs: register SpectatorRegistryService singleton + both handlers. 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:
@@ -124,6 +124,12 @@ public sealed record JoinCustomLobbyRequest(Guid LobbyId, Guid DeckId, string? P
|
||||
/// <summary>Leave or cancel a custom lobby.</summary>
|
||||
public sealed record LeaveCustomLobbyRequest(Guid LobbyId);
|
||||
|
||||
/// <summary>Join a game session as a spectator.</summary>
|
||||
public sealed record SpectateRequest(Guid SessionId);
|
||||
|
||||
/// <summary>Stop spectating a game session.</summary>
|
||||
public sealed record StopSpectatingRequest(Guid SessionId);
|
||||
|
||||
/// <summary>List open custom lobbies. NameSearch filters by lobby name (case-insensitive contains).</summary>
|
||||
public sealed record ListCustomLobbiesRequest(
|
||||
int Page = 1,
|
||||
@@ -182,6 +188,12 @@ public sealed record JoinCustomLobbyResponse(
|
||||
|
||||
public sealed record LeaveCustomLobbyResponse(Guid LobbyId);
|
||||
|
||||
/// <summary>Ack for game.spectate — spectator receives current filtered game state.</summary>
|
||||
public sealed record SpectateResponse(GameStateDto State);
|
||||
|
||||
/// <summary>Ack for game.spectate.stop.</summary>
|
||||
public sealed record StopSpectatingResponse(Guid SessionId);
|
||||
|
||||
public sealed record ListCustomLobbiesResponse(
|
||||
IEnumerable<CustomLobbyDto> Lobbies,
|
||||
int TotalCount,
|
||||
|
||||
Reference in New Issue
Block a user