Phase 3: GameTurnTimerService — per-turn auto-end timer

- GameTurnTimerService singleton manages CancellationTokenSource per session.
  Fires AutoEndTurnAsync on expiry: acquires row lock, calls GameEngine.EndTurn,
  saves state, pushes to players, finalizes game if turn-limit reached.
  Caps effective delay by TimeLimitMinutes remaining wall time.
- FinalizeGameAsync (GameHandlerBase) calls GameTurnTimerService.Instance?.CancelTimer
  so all game-over paths (attack, concede, force-concede) cleanly cancel timers.
- GamePlaceArchSpiritHandler: injects timer service; ResetTimer when bothPlaced.
- GameEndTurnHandler: injects timer service; ResetTimer on normal end-turn,
  CancelTimer (via FinalizeGameAsync) on turn-limit game-over.
- ServiceRegistration: singleton + AddHostedService delegate for lifetime callbacks.
- GameHandlerBase: SaveStateAsync, PushStateToPlayersAsync, FinalizeGameAsync
  promoted from protected static → internal static for timer service access.

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:11:15 -04:00
co-authored by Claude Happy
parent 93d27e9270
commit 2c40fb036f
5 changed files with 231 additions and 19 deletions
@@ -27,6 +27,11 @@ public static class ServiceRegistration
// Monitors active sessions for player inactivity.
services.AddHostedService<GameInactivityMonitorService>();
// Manages per-session turn timers; registered as singleton so handlers can inject it,
// and as a hosted service so it receives app-lifetime Start/Stop callbacks.
services.AddSingleton<GameTurnTimerService>();
services.AddHostedService(sp => sp.GetRequiredService<GameTurnTimerService>());
services.AddTransient<IMessageHandler, GameReadyHandler>();
services.AddTransient<IMessageHandler, GameGetStateHandler>();
services.AddTransient<IMessageHandler, GameGetActiveSessionHandler>();