feat(battle-node): in-memory IBattleSessionStore + PendingBattle
This commit is contained in:
13
SVSim.BattleNode/Sessions/IBattleSessionStore.cs
Normal file
13
SVSim.BattleNode/Sessions/IBattleSessionStore.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace SVSim.BattleNode.Sessions;
|
||||
|
||||
public interface IBattleSessionStore
|
||||
{
|
||||
/// <summary>Register a battle minted by the matching bridge, awaiting a WS connect.</summary>
|
||||
void RegisterPending(PendingBattle battle);
|
||||
|
||||
/// <summary>Look up the pending battle. Returns null if not present.</summary>
|
||||
PendingBattle? TryGetPending(string battleId);
|
||||
|
||||
/// <summary>Mark a battle as no longer pending (e.g. on successful connect or explicit close).</summary>
|
||||
bool RemovePending(string battleId);
|
||||
}
|
||||
17
SVSim.BattleNode/Sessions/InMemoryBattleSessionStore.cs
Normal file
17
SVSim.BattleNode/Sessions/InMemoryBattleSessionStore.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions;
|
||||
|
||||
public sealed class InMemoryBattleSessionStore : IBattleSessionStore
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, PendingBattle> _pending = new();
|
||||
|
||||
public void RegisterPending(PendingBattle battle) =>
|
||||
_pending[battle.BattleId] = battle;
|
||||
|
||||
public PendingBattle? TryGetPending(string battleId) =>
|
||||
_pending.TryGetValue(battleId, out var b) ? b : null;
|
||||
|
||||
public bool RemovePending(string battleId) =>
|
||||
_pending.TryRemove(battleId, out _);
|
||||
}
|
||||
7
SVSim.BattleNode/Sessions/PendingBattle.cs
Normal file
7
SVSim.BattleNode/Sessions/PendingBattle.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace SVSim.BattleNode.Sessions;
|
||||
|
||||
/// <summary>
|
||||
/// Sparse pre-connect record: enough to validate the incoming WS connect and resolve
|
||||
/// the viewer. Full BattleSession is created on connect.
|
||||
/// </summary>
|
||||
public sealed record PendingBattle(string BattleId, long ViewerId);
|
||||
Reference in New Issue
Block a user