refactor(battle-node): WireConstants for SIO event names + crypto RNG battle id

This commit is contained in:
gamer147
2026-06-01 11:53:01 -04:00
parent 133346e3e8
commit ef3d7bb82b
4 changed files with 45 additions and 12 deletions

View File

@@ -112,10 +112,10 @@ public sealed class BattleSession
{
switch (frame.EventName)
{
case "msg" when frame.BinaryAttachments.Count == 1:
case WireConstants.MsgEvent when frame.BinaryAttachments.Count == 1:
await HandleMsgEventAsync(frame);
return;
case "alive" when frame.BinaryAttachments.Count == 1:
case WireConstants.AliveEvent when frame.BinaryAttachments.Count == 1:
await HandleAliveEventAsync(frame);
return;
}
@@ -178,14 +178,14 @@ public sealed class BattleSession
var aliveEnv = new MsgEnvelope(
Uri: NetworkBattleUri.Gungnir,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId,
Uuid: "node-stub",
Uuid: WireConstants.ServerUuid,
Bid: null,
Try: 0,
Cat: EmitCategory.General,
PubSeq: null,
PlaySeq: null,
Body: new AlivePushBody(Scs: "ONLINE", Ocs: "ONLINE"));
await PushNoStockAsync(aliveEnv, eventName: "alive");
Body: new AlivePushBody(Scs: WireConstants.OnlineStatus, Ocs: WireConstants.OnlineStatus));
await PushNoStockAsync(aliveEnv, eventName: WireConstants.AliveEvent);
}
catch (Exception ex)
{
@@ -272,7 +272,7 @@ public sealed class BattleSession
private MsgEnvelope BuildAckedEnvelope(NetworkBattleUri uri) => new(
uri,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId,
Uuid: "node-stub",
Uuid: WireConstants.ServerUuid,
Bid: null,
Try: 0,
Cat: EmitCategory.General,
@@ -283,7 +283,7 @@ public sealed class BattleSession
private MsgEnvelope BuildBattleFinishNoContest() => new(
NetworkBattleUri.BattleFinish,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId,
Uuid: "node-stub",
Uuid: WireConstants.ServerUuid,
Bid: null,
Try: 0,
Cat: EmitCategory.Battle,
@@ -317,10 +317,10 @@ public sealed class BattleSession
return Array.Empty<long>();
}
private Task PushOrderedAsync(MsgEnvelope env, string eventName = "synchronize") =>
private Task PushOrderedAsync(MsgEnvelope env, string eventName = WireConstants.SynchronizeEvent) =>
EncodeAndSendAsync(Outbound.AssignAndArchive(env), eventName);
private Task PushNoStockAsync(MsgEnvelope env, string eventName = "synchronize") =>
private Task PushNoStockAsync(MsgEnvelope env, string eventName = WireConstants.SynchronizeEvent) =>
EncodeAndSendAsync(Outbound.WrapNoStock(env), eventName);
private async Task EncodeAndSendAsync(MsgEnvelope env, string eventName)