Files
sor/Server/src/SOR.Game/Handlers/GameConcedeHandler.cs
T
4fa4c21b6e Feat: game explorer, action log result capture, session purge
DB / Server:
- Added ResultJson (jsonb, nullable) to GameActionLog entity + EF migration
- Updated SaveStateAsync to accept resultJson (optional, default null)
- All 11 action handlers now serialize GameEngine.ToDto() result into the log

Admin — GameSessionsPage:
- Session IDs are now clickable links → /game/sessions/{id}
- "Abandon All Active" bulk button (previous)
- "Purge All" button (SuperAdmin only, JS confirm) — hard-deletes all sessions
  and action logs via cascade

Admin — GameSessionDetailPage (/game/sessions/{id}):
- Session header: status badge, P1/P2 display names (click to copy GUID)
- Info cards: Player 1, Player 2, Created timestamp, Duration/WinCondition
- Action log table: seq#, time, actor name (click to copy GUID), action type
- Expandable Payload (JSON) and Result (JSON) per row
- Actor display names resolved from SorIdentityDbContext

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>
2026-03-09 09:33:40 -04:00

66 lines
2.2 KiB
C#

namespace SOR.Game.Handlers;
using System.Text.Json;
using SOR.Database.Contexts;
using SOR.Networking.Abstractions.Messaging;
using SOR.Networking.Abstractions.Push;
using SOR.Networking.Abstractions.Transport;
using SOR.Shared.Networking;
/// <summary>
/// game.concede — the calling player forfeits the match.
/// </summary>
internal sealed class GameConcedeHandler : GameHandlerBase, IMessageHandler
{
private readonly IMessageSerializer _serializer;
private readonly GameDbContext _gameDb;
private readonly SorIdentityDbContext _identityDb;
private readonly IClientPush _clientPush;
public GameConcedeHandler(
IMessageSerializer serializer,
GameDbContext gameDb,
SorIdentityDbContext identityDb,
IClientPush clientPush)
{
_serializer = serializer;
_gameDb = gameDb;
_identityDb = identityDb;
_clientPush = clientPush;
}
public string MessageType => "game.concede";
public async Task<IServerMessage?> HandleAsync(
IClientMessage message,
AuthenticatedConnection connection,
CancellationToken ct)
{
var req = _serializer.DeserializePayload<GameConcedeRequest>(message.Payload);
var actorId = connection.UserId;
var session = await LoadActiveSessionAsync(_gameDb, req.SessionId, actorId, ct);
var state = GameEngine.Deserialize(session.StateJson!);
var newState = GameEngine.Concede(state, actorId);
var dto = GameEngine.ToDto(newState, actorId);
await SaveStateAsync(_gameDb, session, newState, actorId, "game.concede",
JsonSerializer.Serialize(req), ct, JsonSerializer.Serialize(dto));
var winnerId = session.PlayerOneAccountId.ToString() == actorId
? session.PlayerTwoAccountId
: session.PlayerOneAccountId;
await FinalizeGameAsync(
_gameDb, _identityDb, _clientPush,
session,
winnerAccountId: winnerId,
loserAccountId: Guid.Parse(actorId),
winCondition: "concede",
ct);
return ServerMessage.Reply("game.concede.ack", message.Seq,
new GameConcedeResponse(dto));
}
}