PlayerSessions
A worker's view of which gateway currently speaks for each player session, and how new that claim is.
Nebula · Packages/com.1by3.nebula/Runtime/Protocol/PlayerSessions.cspublic sealed class PlayerSessionsA worker's view of which gateway currently speaks for each player session, and how new that claim is. Every session (WelcomeMsg.ClientId) is claimed by a gateway through SpawnPlayerMsg with a connection generation; a later claim with a higher generation moves the session to that gateway (the client reconnected elsewhere), and anything an older gateway says about the session afterwards (a despawn, inputs) is stale and ignored. When a gateway link is lost its sessions are orphaned: kept for a grace period so the same or another gateway can reclaim them, then handed back to the caller to despawn. Plain C#, no Unity or transport types: the worker feeds it gateway keys (id + incarnation) and a clock.
Fields
EndedWithoutPawnSeconds
public const double EndedWithoutPawnSeconds = 10;How long, at least, an ended session is kept when the caller does not hold its pawn: long enough for a handover that was in flight when the end arrived to land, so the end is still here to remove the pawn.
Properties
Count
public int Count { get; }OrphanCount
public int OrphanCount { get; }Methods
GatewayKey
public static string GatewayKey(string gatewayId, uint incarnation);TryGet
public bool TryGet(ulong id, out Session session);Register
public Claim Register(ulong id, ulong generation, string gateway);
public Claim Register(ulong id, ulong generation, string gateway, out string previousGateway);A gateway claims the session with generation. See Claim for what happened.
Adopt
public void Adopt(ulong id, ulong generation, string gateway);
public void Adopt(ulong id, ulong generation, string gateway, OrphanKind orphan, double reclaimRemaining, double now, double graceSeconds);Seed a session this worker inherited with an entity (a handover carries the owner's session with it), so the gateway's inputs are accepted at once. Never lowers a generation already known.
ReclaimRemaining
public static double ReclaimRemaining(Session session, double now, double graceSeconds);Seconds left before Expire gives up on an orphaned session; 0 once it is due, and for a session that is not an orphan.
Release
public bool Release(ulong id, ulong generation, double now);A gateway says the session's link ended. True when that is current news: the session becomes an orphan and Expire hands it back after the grace unless a claim renews it. False when a newer claim exists elsewhere, so the release is stale and must be ignored. An unknown session is treated as current.
End
public bool End(ulong id, ulong generation, double now);A gateway says the session is over, not merely disconnected: the player said goodbye or was kicked. Like Release, and fenced the same way, but Expire hands the session back on its next pass instead of after the grace. Returns false for a stale end (a newer claim exists elsewhere).
Accept
public bool Accept(ulong id, string gateway);May gateway drive the session right now (inputs, server RPCs)? True for the claiming gateway and for a session this worker has never had a claim for (it learns the gateway lazily then).
Remove
public void Remove(ulong id);GatewayLost
public void GatewayLost(string gateway, double now);The gateway's link dropped: its sessions wait for a reclaim until Expire gives up on them.
GatewayReturned
public void GatewayReturned(string gateway);The same gateway (same incarnation) is back: its sessions are no longer orphans, except the ones it released (their clients left).
Expire
public void Expire(double now, double graceSeconds, List<ulong> expired);
public void Expire(double now, double graceSeconds, List<ulong> expired, Func<ulong, bool> holdsPawn);Drop every orphan older than graceSeconds, and every ended session, and list its id, so the caller despawns the pawn. Every ended session counts as one whose pawn the caller holds.
Nested types
Session
public sealed class SessionProvides the session API.
Fields
Id
public ulong Id;Generation
public ulong Generation;Gateway
public string Gateway = "";The gateway that speaks for the session: "#".
Orphaned
public bool Orphaned;Released
public bool Released;The orphan is a release: the gateway said the client's link ended. Only a newer claim renews it. An orphan that is not released only lost its gateway's link to this worker, and the same gateway coming back renews it too (GatewayReturned).
Ended
public bool Ended;The session is over and waits for nobody: the player said goodbye or was kicked (End). Always a release too. Expire hands it back at once, whatever the grace.
OrphanedAt
public double OrphanedAt;Properties
Orphan
public OrphanKind Orphan { get; }Why the session is an orphan, or OrphanKind.None while a gateway speaks for it.
OrphanKind
public enum OrphanKind : byteWhy a session is waiting for a reclaim. Carried in a handover (AuthorityTransferMsg.SessionOrphan).
Members
| Name | Value | Description |
|---|---|---|
None | 0 | A gateway speaks for the session. |
Released | 1 | The gateway said the client's link ended (PlayerSessions.Release). |
GatewayLost | 2 | The gateway's link to the worker dropped (PlayerSessions.GatewayLost). |
Ended | 3 | The session is over: the player said goodbye or was kicked (PlayerSessions.End). The pawn is removed as soon as the worker that owns it hears of it, with no reclaim grace. |
Claim
public enum ClaimLists the supported claim values.
Members
| Name | Value | Description |
|---|---|---|
New | First time this worker hears of the session. | |
Repeat | The same gateway, same generation: a repeat (the gateway re-announcing after a link blip). | |
Reclaimed | A newer generation: the session now lives on the claiming gateway. | |
Stale | An older generation than the one held: the claimant lost the client to another gateway. |