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:
dingo
2026-03-18 23:14:24 -04:00
co-authored by Claude Happy
parent 2c40fb036f
commit 02d469490b
7 changed files with 198 additions and 5 deletions
+6
View File
@@ -932,6 +932,12 @@ public static class GameEngine
// ── DTO projection ────────────────────────────────────────────────────────
/// <summary>
/// Build a spectator-safe GameStateDto — both players' hands are hidden (null).
/// </summary>
public static GameStateDto ToDtoSpectator(GameState state)
=> ToDto(state, string.Empty); // Empty string matches neither player → both hands hidden.
/// <summary>
/// Build a client-safe GameStateDto for a specific player's perspective.
/// Opponent's hand is hidden (null); only the count is shown.