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:
@@ -65,15 +65,15 @@ public class ServerBattleFramesTests
|
||||
Assert.That(body.SelfInfo.EmblemId, Is.EqualTo("888"));
|
||||
Assert.That(body.SelfInfo.DegreeId, Is.EqualTo("777"));
|
||||
Assert.That(body.SelfInfo.FieldId, Is.EqualTo(42));
|
||||
Assert.That(body.SelfInfo.IsOfficial, Is.EqualTo(1));
|
||||
Assert.That(body.SelfInfo.IsOfficial, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildBattleStart_HasTurnStateZero_AndUsesContextBattleType()
|
||||
{
|
||||
var env = ServerBattleFrames.BuildBattleStart(FixtureCtx(), FakeOpponentCtx(), selfViewerId: 1, turnState: 0);
|
||||
var env = ServerBattleFrames.BuildBattleStart(FixtureCtx(), FakeOpponentCtx(), selfViewerId: 1, turnState: TurnState.First);
|
||||
var body = (BattleStartBody)env.Body;
|
||||
Assert.That(body.TurnState, Is.EqualTo(0));
|
||||
Assert.That(body.TurnState, Is.EqualTo(TurnState.First));
|
||||
Assert.That(body.BattleType, Is.EqualTo(11));
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class ServerBattleFramesTests
|
||||
BattleType = 42,
|
||||
};
|
||||
|
||||
var env = ServerBattleFrames.BuildBattleStart(ctx, FakeOpponentCtx(), selfViewerId: 1, turnState: 0);
|
||||
var env = ServerBattleFrames.BuildBattleStart(ctx, FakeOpponentCtx(), selfViewerId: 1, turnState: TurnState.First);
|
||||
var body = (BattleStartBody)env.Body;
|
||||
|
||||
Assert.That(body.SelfInfo.ClassId, Is.EqualTo("7"));
|
||||
|
||||
@@ -87,7 +87,7 @@ public class TypedBodyWireShapeTests
|
||||
[Test]
|
||||
public void BuildBattleStart_SerializesAllWireKeysAndPreservesBattlePointAsymmetry()
|
||||
{
|
||||
var env = ServerBattleFrames.BuildBattleStart(FixtureCtx(), FakeOpponentCtx(), selfViewerId: 906243102, turnState: 0);
|
||||
var env = ServerBattleFrames.BuildBattleStart(FixtureCtx(), FakeOpponentCtx(), selfViewerId: 906243102, turnState: TurnState.First);
|
||||
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
var node = JsonNode.Parse(json)!.AsObject();
|
||||
|
||||
Reference in New Issue
Block a user