Class SeatRegistry
- Namespace
- Unity.Multiplayer.Core
The server's seating plan: maps each player token to a seat, so a player who drops and reconnects within the grace window gets the same seat (and, through the adapter, the same player object) back.
public sealed class SeatRegistry
- Inheritance
-
SeatRegistry
- Inherited Members
Remarks
Engine-free: time is passed in (any monotonic clock in seconds), so the adapter feeds it Unity's realtime clock and tests feed it numbers. Not thread-safe; the adapter calls it from Unity's main thread.
Life of a seat: Claim(ulong, ConnectionPayload, double, bool) occupies the lowest free seat for a new token. Release(ulong, double) (the connection dropped) holds it for GraceSeconds; a Claim(ulong, ConnectionPayload, double, bool) with the same token in that time takes it back. Expire(double) frees held seats whose time ran out; Free(string) frees one at once (a kick). Held seats count as taken: a new player cannot sit in a seat someone may return to.
The host's seat (claimed with isHost: true) is never taken over while occupied: a join presenting
its token from a different connection is refused (Refused), not treated as a
stale-connection reconnect, since the host never legitimately comes back through Claim(ulong, ConnectionPayload, double, bool) (UM-T77).
Constructors
SeatRegistry(int, double)
A registry with capacity seats that holds a dropped player's seat for graceSeconds.
public SeatRegistry(int capacity, double graceSeconds)
Parameters
Exceptions
- ArgumentOutOfRangeException
capacityis below one orgraceSecondsis negative or NaN.
Properties
Capacity
The number of seats.
public int Capacity { get; }
Property Value
Count
Seats taken, occupied or held.
public int Count { get; }
Property Value
GraceSeconds
How long a dropped player's seat is held, in seconds.
public double GraceSeconds { get; }
Property Value
HeldCount
Seats held for a player who dropped.
public int HeldCount { get; }
Property Value
OccupiedCount
Seats with a connected client in them.
public int OccupiedCount { get; }
Property Value
Seats
A snapshot of every taken seat, by index.
public IReadOnlyList<Seat> Seats { get; }
Property Value
Methods
Claim(ulong, ConnectionPayload, double, bool)
Seats the connection clientId for payload's player token: back in
its held seat, in place of a stale connection with the same token, or in the lowest free seat.
public SeatClaim Claim(ulong clientId, ConnectionPayload payload, double now, bool isHost = false)
Parameters
clientIdulongThe new connection.
payloadConnectionPayloadThe approved payload (token, name and colour).
nowdoubleThe current time in seconds; held seats that ran out by then are freed first and do not come back.
isHostboolTrue only for the host's own seat (AdmitLocal(ulong, ConnectionPayload, double)): marks the seat so a later join presenting the same token, from a different connection, is refused instead of taking the host's live seat over (UM-T77) — the host never goes through this method again to legitimately reclaim it.
Returns
Exceptions
- ArgumentNullException
payloadis null.- InvalidOperationException
clientIdalready sits in another player's seat.
Clear()
Empties the registry (the session ended).
public void Clear()
CountExcept(string)
Seats taken by anyone other than playerToken: the number of players a newcomer with
that token competes with (what ConnectionApprovalValidator calls connected players).
public int CountExcept(string playerToken)
Parameters
playerTokenstring
Returns
Expire(double)
Frees every held seat whose grace window has run out by now.
public IReadOnlyList<Seat> Expire(double now)
Parameters
nowdouble
Returns
- IReadOnlyList<Seat>
The seats freed (status Released), by index; empty when none.
Free(string)
Frees playerToken's seat at once, occupied or held.
public Seat Free(string playerToken)
Parameters
playerTokenstring
Returns
- Seat
The released seat, or null when the token had none.
Free(ulong)
Frees the seat of the connection clientId at once, with no grace window (a kick).
public Seat Free(ulong clientId)
Parameters
clientIdulong
Returns
- Seat
The released seat, or null when the client had none.
Release(ulong, double)
The connection clientId dropped: its seat is held until now +
GraceSeconds (freed at once when the grace is zero).
public Seat Release(ulong clientId, double now)
Parameters
Returns
- Seat
The seat after the change (Held or Released), or null when the client had no seat (for example it was already replaced).
Rename(ulong, string, PlayerColor)
The player on connection clientId now plays as displayName in
color (an accepted rename, UM-T55); the seat keeps them across a reconnect too.
public Seat Rename(ulong clientId, string displayName, PlayerColor color)
Parameters
clientIdulongdisplayNamestringcolorPlayerColor
Returns
- Seat
The seat after the change, or null when the client has none.
TryGetByClient(ulong, out Seat)
The seat of a connected client.
public bool TryGetByClient(ulong clientId, out Seat seat)
Parameters
Returns
TryGetByIndex(int, out Seat)
The seat (occupied or held) at index.
public bool TryGetByIndex(int index, out Seat seat)
Parameters
Returns
TryGetByToken(string, out Seat)
The seat (occupied or held) of a player token.
public bool TryGetByToken(string playerToken, out Seat seat)