Session Management
Moongate v2 keeps transport and gameplay concerns separated.
Session Types
GameNetworkSession
Transport-level state:
SessionIdClient(MoongateTCPClient)RemoteEndPoint- protocol
State - pending bytes buffer
- seed/account/auth flags
- compression/encryption flags
Operations:
SetState(...)SetSeed(...)MarkAuthenticated(...)EnterGame(...)- compression/encryption toggles
GameSession
Gameplay/protocol context tied to GameNetworkSession:
SessionIdClientVersionAccountIdCharacterIdCharacter(UOMobileEntity)- movement and ping state (
MoveSequence,MoveTime,MoveCredit,PingSequence)
Session Store Service
IGameNetworkSessionService / GameNetworkSessionService:
GetOrCreate(MoongateTCPClient client)TryGet(long sessionId, out GameSession session)GetAll()snapshotRemove(...),Clear(),Count
Storage is a concurrent dictionary keyed by connection session id.
Lifecycle
- client connects
NetworkServicecallsGetOrCreate(...)- transport state progresses through handshake/auth/game states
- disconnect removes session from store
Why This Split
- transport concerns (socket/middleware/protocol framing) stay isolated
- game logic operates on
GameSession - easier testing and future protocol transitions
Previous: Game Loop | Next: Event System