Files
SVSimServer/SVSim.BattleNode/Sessions/Dispatch/FrameDispatchContext.cs
gamer147 9b8a7f1e37 refactor(battlenode): name sender-only vs both-sides handshake checks (§D)
Behavior-preserving; 231 BattleNode tests green.

FrameDispatchContext.BothAfterReady() -> BothSidesAfterReady() (7 call sites). The
4 inline `SenderPhase == AfterReady` checks in TurnEndHandler/TurnEndFinalHandler now
read a new SenderIsAfterReady property. Both carry cross-referencing docs so the
Bot-arm (sender-only) vs PvP-arm (both-sides) distinction is explicit at the type.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 07:49:27 -04:00

42 lines
2.3 KiB
C#

using SVSim.BattleNode.Protocol;
using SVSim.BattleNode.Sessions.Participants; // IHasHandshakePhase
namespace SVSim.BattleNode.Sessions.Dispatch;
/// <summary>Everything a handler reads or mutates for one inbound frame. <see cref="A"/>/<see cref="B"/>
/// are the session's positional participants (preserved so handlers that iterate participants in a
/// stable order — e.g. the mulligan barrier — match the legacy switch byte-for-byte). <see cref="From"/>
/// is the sender; <see cref="Other"/> is the non-sender.</summary>
internal sealed class FrameDispatchContext
{
internal required IBattleParticipant A { get; init; }
internal required IBattleParticipant B { get; init; }
internal required IBattleParticipant From { get; init; }
internal required IBattleParticipant Other { get; init; }
internal required MsgEnvelope Env { get; init; }
internal required BattleType Type { get; init; }
internal required string BattleId { get; init; }
internal required BattleSessionState State { get; init; }
/// <summary>The dispatching participant's handshake phase (null for a non-IHasHandshakePhase
/// participant, e.g. NoOpBot). Setting it advances the sender.</summary>
internal HandshakePhase? SenderPhase
{
get => (From as IHasHandshakePhase)?.Phase;
set { if (From is IHasHandshakePhase p && value is { } v) p.Phase = v; }
}
/// <summary>Just the SENDER has finished the handshake — says nothing about the opponent. The
/// Bot arms gate on this (the bot has no handshake phase of its own); contrast
/// <see cref="BothSidesAfterReady"/>, which the PvP arms require. The sender-only vs both-sides
/// distinction is load-bearing for the Bot/PvP split (see TurnEndHandler / TurnEndFinalHandler).</summary>
internal bool SenderIsAfterReady => SenderPhase == HandshakePhase.AfterReady;
/// <summary>BOTH participants have finished the handshake. Reads A/B (not From/Other) so the
/// result is identical regardless of which side sent the frame. Contrast
/// <see cref="SenderIsAfterReady"/> (sender only).</summary>
internal bool BothSidesAfterReady() =>
(A as IHasHandshakePhase)?.Phase == HandshakePhase.AfterReady &&
(B as IHasHandshakePhase)?.Phase == HandshakePhase.AfterReady;
}