refactor(battle-node): extract InitNetworkHandler
This commit is contained in:
@@ -3,6 +3,7 @@ using SVSim.BattleNode.Lifecycle;
|
||||
using SVSim.BattleNode.Protocol;
|
||||
using SVSim.BattleNode.Protocol.Bodies;
|
||||
using SVSim.BattleNode.Sessions.Dispatch;
|
||||
using SVSim.BattleNode.Sessions.Dispatch.Handlers;
|
||||
using SVSim.BattleNode.Sessions.Participants;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions;
|
||||
@@ -33,7 +34,10 @@ public sealed class BattleSession
|
||||
// Per-URI handlers consulted before the legacy switch. Populated incrementally (Tasks 5-14);
|
||||
// each registered URI is served by its handler and its legacy switch arm goes dead.
|
||||
private static readonly IReadOnlyDictionary<NetworkBattleUri, IFrameHandler> Handlers =
|
||||
new Dictionary<NetworkBattleUri, IFrameHandler>();
|
||||
new Dictionary<NetworkBattleUri, IFrameHandler>
|
||||
{
|
||||
[NetworkBattleUri.InitNetwork] = new InitNetworkHandler(),
|
||||
};
|
||||
|
||||
private FrameDispatchContext BuildContext(IBattleParticipant from, MsgEnvelope env) =>
|
||||
new()
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using SVSim.BattleNode.Lifecycle;
|
||||
using SVSim.BattleNode.Protocol;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
|
||||
|
||||
internal sealed class InitNetworkHandler : IFrameHandler
|
||||
{
|
||||
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx)
|
||||
{
|
||||
if (ctx.SenderPhase != BattleSessionPhase.AwaitingInitNetwork)
|
||||
return Array.Empty<DispatchRoute>();
|
||||
|
||||
var routes = new List<DispatchRoute>
|
||||
{
|
||||
new(ctx.From, BattleFrames.BuildAck(NetworkBattleUri.InitNetwork), true),
|
||||
};
|
||||
ctx.SenderPhase = BattleSessionPhase.AwaitingInitBattle;
|
||||
return routes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user