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:
@@ -1,3 +1,4 @@
|
||||
using SVSim.BattleNode.Protocol;
|
||||
using SVSim.BattleNode.Protocol.Bodies;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions.Dispatch;
|
||||
@@ -195,8 +196,8 @@ internal static class KnownListBuilder
|
||||
if (d.TryGetValue("selectCard", out var scRaw) && scRaw is IDictionary<string, object?> sc)
|
||||
{
|
||||
sc.TryGetValue("open", out var openRaw);
|
||||
var open = (int)AsLong(openRaw);
|
||||
if (open != 0 && sc.TryGetValue("cardId", out var idsRaw) && idsRaw is IEnumerable<object?> ids)
|
||||
var open = (ChoiceVisibility)(int)AsLong(openRaw);
|
||||
if (open != ChoiceVisibility.Hidden && sc.TryGetValue("cardId", out var idsRaw) && idsRaw is IEnumerable<object?> ids)
|
||||
selectCard = new SelectCardEntry(ids.Select(AsLong).ToList(), open);
|
||||
}
|
||||
result.Add(new KeyActionEntry(type, cardId, selectCard));
|
||||
@@ -217,7 +218,7 @@ internal static class KnownListBuilder
|
||||
d.TryGetValue("isSelf", out var isSelfRaw);
|
||||
result.Add(new OppoTargetEntry(
|
||||
TargetIdx: (int)AsLong(targetIdxRaw),
|
||||
IsSelf: (int)AsLong(isSelfRaw)));
|
||||
IsSelf: (CardOwner)(int)AsLong(isSelfRaw)));
|
||||
}
|
||||
return result.Count == 0 ? null : result;
|
||||
}
|
||||
@@ -247,14 +248,14 @@ internal static class KnownListBuilder
|
||||
IdxList: AsIntList(idxRaw) ?? new List<int>(),
|
||||
From: (int)AsLong(fromRaw),
|
||||
To: (int)AsLong(toRaw),
|
||||
IsSelf: (int)AsLong(isSelfRaw),
|
||||
IsSelf: (CardOwner)(int)AsLong(isSelfRaw),
|
||||
Skill: skillRaw as string ?? "",
|
||||
CardId: d.TryGetValue("cardId", out var c) ? AsLong(c) : null,
|
||||
Clan: d.TryGetValue("clan", out var cl) ? (int)AsLong(cl) : null,
|
||||
Cost: d.TryGetValue("cost", out var co) ? (int)AsLong(co) : null,
|
||||
SkillKeyCardIdx: AsIntList(d.TryGetValue("skillKeyCardIdx", out var sk) ? sk : null),
|
||||
RandomTargetIdx: AsIntList(d.TryGetValue("randomTargetIdx", out var rt) ? rt : null),
|
||||
IsInvoke: d.TryGetValue("isInvoke", out var iv) ? (int)AsLong(iv) : null,
|
||||
IsInvoke: d.TryGetValue("isInvoke", out var iv) ? AsLong(iv) != 0 : null,
|
||||
AttachTarget: d.TryGetValue("attachTarget", out var at) ? at as string : null));
|
||||
}
|
||||
return result.Count == 0 ? null : result;
|
||||
|
||||
Reference in New Issue
Block a user