Quality pass from the 2026-06-04 BattleNode review (audit in the outer
repo). All changes are behavior-preserving — identical wire bytes,
verified by the full 1008-test suite staying green.
- Name scattered magic numbers: crypto key/IV lengths, outbound-sequencer
base, WS receive buffer / EIO ping / SID length, polite-close timeout,
upgrade-credential keys, battle-id digit math, deterministic-turn spin.
- resultCode = 1 -> (int)ReceiveNodeResultCode.Success across body records.
- Pong "3" -> EngineIoPacketType.Pong; remove dead NoOpBotParticipant.Touch
(replace with #pragma warning disable CS0067).
- Wire-flag enums, serialized as numbers via JsonNumberEnumConverter:
turnState -> TurnState{First,Second}, isSelf -> CardOwner{Opponent,Self},
open -> ChoiceVisibility{Hidden,Open}.
- isOfficial / isInvoke -> bool / bool? via new NumericBoolJsonConverter
(reads/writes 0/1; TDD'd). Scoped to the BattleNode wire boundary only;
MatchContext and the HTTP/AI-start path stay int (AI-start uses -1 as a
sentinel, so it is not boolean).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
using SVSim.BattleNode.Protocol;
|
|
|
|
namespace SVSim.BattleNode.Reliability;
|
|
|
|
/// <summary>
|
|
/// Per-session outbound ledger. Assigns monotonic playSeq to ordered pushes and archives
|
|
/// them for future Resume retransmit (v2). No-stock control pushes (BattleFinish/JudgeResult/Resume)
|
|
/// are wrapped with no playSeq and skip the archive.
|
|
/// </summary>
|
|
public sealed class OutboundSequencer
|
|
{
|
|
/// <summary>First playSeq assigned. Starts at 1, not 0 — 0 is reserved for no-stock /
|
|
/// unsequenced pushes (which carry a null PlaySeq via <see cref="WrapNoStock"/>).</summary>
|
|
private const long FirstPlaySeq = 1;
|
|
|
|
private long _next = FirstPlaySeq;
|
|
private readonly Dictionary<long, MsgEnvelope> _archive = new();
|
|
|
|
public IReadOnlyDictionary<long, MsgEnvelope> Archive => _archive;
|
|
|
|
public MsgEnvelope AssignAndArchive(MsgEnvelope envelope)
|
|
{
|
|
var seq = _next++;
|
|
var stamped = envelope with { PlaySeq = seq };
|
|
_archive[seq] = stamped;
|
|
return stamped;
|
|
}
|
|
|
|
public MsgEnvelope WrapNoStock(MsgEnvelope envelope) =>
|
|
envelope with { PlaySeq = null };
|
|
|
|
/// <summary>
|
|
/// Drop all archived envelopes. Called from BattleSession's terminate cascade so
|
|
/// the archive — the heavy state — is released the moment the battle ends, rather
|
|
/// than waiting for the participant to be GC'd. <c>_next</c> is left untouched:
|
|
/// a participant emitting after Clear is a bug, not a recovery case, but the seq
|
|
/// stream stays monotonic so a stray emit doesn't silently re-use a playSeq value.
|
|
/// </summary>
|
|
public void Clear() => _archive.Clear();
|
|
}
|