refactor(battle-node): unify IMatchingBridge.RegisterBattle signature

Single RegisterBattle(p1, p2?, type) with contract validation throws on
invalid combinations (Pvp requires both; Bot requires p2==null; Scripted
accepts either). PendingBattle carries Type + P1 + nullable P2. Handler
+ controller adapt; v1.2 behaviour preserved because Scripted is the
only type used today (Phase 2 adds Pvp, Phase 3 adds Bot).
This commit is contained in:
gamer147
2026-06-01 20:00:52 -04:00
parent acd0997cfb
commit d665f88067
8 changed files with 111 additions and 37 deletions

View File

@@ -93,18 +93,20 @@ public sealed class BattleNodeWebSocketHandler
ctx.Response.StatusCode = StatusCodes.Status404NotFound;
return;
}
if (pending.ViewerId != viewerId)
if (pending.P1.ViewerId != viewerId)
{
_log.LogWarning(
"WS upgrade viewer-id mismatch on BattleId={Bid}: bridge expected={Expected}, decrypted={Got}.",
battleId, pending.ViewerId, viewerId);
battleId, pending.P1.ViewerId, viewerId);
ctx.Response.StatusCode = StatusCodes.Status401Unauthorized;
return;
}
var ws = await ctx.WebSockets.AcceptWebSocketAsync();
_store.RemovePending(battleId);
var session = new BattleSession(ws, battleId, viewerId, pending.Context, _loggerFactory.CreateLogger<BattleSession>());
// Phase 1: handler still constructs the old single-WS BattleSession.
// Task 9 switches to BattleSessionV2 + RealParticipant + ScriptedBotParticipant.
var session = new BattleSession(ws, battleId, viewerId, pending.P1.Context, _loggerFactory.CreateLogger<BattleSession>());
await session.RunAsync(ctx.RequestAborted);
}