refactor(battle-node): de-magic wire flags and scattered constants

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>
This commit is contained in:
gamer147
2026-06-04 20:46:09 -04:00
parent ed88683fa0
commit 24180d5b4b
38 changed files with 304 additions and 95 deletions

View File

@@ -26,4 +26,9 @@ internal static class BattleFrameDefaults
/// the client's <c>JudgeOperation</c> doesn't read it.
/// </summary>
public const int OpponentJudgeSpin = 100;
/// <summary>Spin value the PvP relay stamps on the Judge / OpponentTurnStart handover frames
/// in the deterministic-turn slice. 0 = no animation seed; per-turn spin is deferred
/// (see the real-spin design). The client self-generates its turn-open and doesn't read it.</summary>
public const int DeterministicTurnSpin = 0;
}

View File

@@ -33,7 +33,7 @@ public static class ServerBattleFrames
EmblemId: selfCtx.EmblemId,
DegreeId: selfCtx.DegreeId,
FieldId: selfCtx.FieldId,
IsOfficial: selfCtx.IsOfficial,
IsOfficial: selfCtx.IsOfficial != 0,
OppoId: oppoViewerId,
Seed: seed),
OppoInfo: new MatchedOppoInfo(
@@ -43,7 +43,7 @@ public static class ServerBattleFrames
EmblemId: oppoCtx.EmblemId,
DegreeId: oppoCtx.DegreeId,
FieldId: oppoCtx.FieldId,
IsOfficial: oppoCtx.IsOfficial,
IsOfficial: oppoCtx.IsOfficial != 0,
OppoId: selfViewerId,
Seed: seed,
OppoDeckCount: oppoCtx.SelfDeckCardIds.Count),
@@ -51,10 +51,10 @@ public static class ServerBattleFrames
bid: battleId);
public static MsgEnvelope BuildBattleStart(
MatchContext selfCtx, MatchContext oppoCtx, long selfViewerId, int turnState) =>
MatchContext selfCtx, MatchContext oppoCtx, long selfViewerId, TurnState turnState) =>
EnvelopeForPush(NetworkBattleUri.BattleStart,
new BattleStartBody(
TurnState: turnState, // 0 = this side goes first, 1 = second. Caller decides.
TurnState: turnState, // First = this side goes first, Second = second. Caller decides.
BattleType: selfCtx.BattleType,
SelfInfo: new BattleStartSelfInfo(
Rank: BattleFrameDefaults.PlayerRank,