Table of Contents

Class LoginQueueSystem

Namespace
FishMMO.Server.Implementation.LoginServer
Assembly
FishMMO.Server.dll

Manages a FIFO login queue for clients arriving when the server is at authentication capacity. Queued clients stay connected at the QUIC layer and receive periodic position updates via LoginQueuePositionBroadcast. When admitted (position reaches 0), the client re-initiates the handshake and proceeds through normal authentication.

Update rate: The LoginQueueUpdateRateSeconds config key controls how often position updates are broadcast. This is server-authoritative only — clients cannot request faster updates.

Admission rate: Clients are admitted from the queue at a server-configured rate (LoginQueueAdmissionRatePerSecond) to prevent the newly-admitted clients from immediately re-saturating auth capacity.

When it engages: only when a handshake would push the number of connections mid-authentication past the authenticator's pending cap (AuthMaxPendingConnections, default 1,000 on the login server: what its SRP verify and proof channels hold between them, see PendingAuthRules.DefaultLoginPendingCap). The authenticator finds this system in the behaviour registry when it needs it, so the system has to be listed in the LoginServer scene's behaviours for the queue to exist at all.

Threading: main thread only. Every entry point is reached from a FishNet callback, the authenticator's handshake path or its per-frame sweep, all of which run on the main thread.

[CreateAssetMenu(fileName = "LoginQueueSystem", menuName = "FishMMO/Server/LoginServer/Login Queue System", order = 1)]
public class LoginQueueSystem : ServerBehaviour, IServerBehaviour<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>, IServerBehaviour, IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>, IServerComponent
Inheritance
Object
ScriptableObject
LoginQueueSystem
Implements
IServerBehaviour<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>
IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>
Inherited Members
ScriptableObject.SetDirty()
ScriptableObject.CreateInstance<T>()
Object.GetEntityId()
Object.MemberwiseClone()
Object.GetInstanceID()
Object.GetHashCode()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.Destroy(Object)
Object.DestroyImmediate(Object)
Object.DontDestroyOnLoad(Object)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindObjectOfType<T>()
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Object.FindObjectsByType<T>()
Object.FindObjectsByType<T>(FindObjectsInactive)
Object.ToString()
Object.name
Object.hideFlags

Fields

DefaultAdmissionRatePerSecond

Admissions per second when LoginQueueAdmissionRatePerSecond is not configured.

public const float DefaultAdmissionRatePerSecond = 50

Field Value

float

Remarks

Fifty: under what the SRP pipeline completes, so the queue drains into it rather than refilling the pending cap it is waiting on. The bottleneck is the proof stage, two workers by default, each proof several database round trips (the lockout reads, the online check, the token write) plus the SRP arithmetic — tens of milliseconds, so somewhere near a hundred a second between them. The old five a second took a hundred seconds to drain a full queue of 500 while the pipeline sat mostly idle. An admitted client that finds the cap still full is re-admitted at once rather than sent to the back (FishMMO.Server.Implementation.LoginServer.LoginQueueSystem.recentlyAdmitted), so a rate slightly above the pipeline costs a retry, not a place.

Properties

QueuedCount

Returns the current number of clients in the queue.

public int QueuedCount { get; }

Property Value

int

Methods

InitializeOnce()

Called once to initialize the behaviour. Must be implemented by derived classes.

public override ServerComponentInitializationStatus InitializeOnce()

Returns

ServerComponentInitializationStatus

Remarks

Behaviours that need to await I/O (database registration, for example) must override InitializeOnceAsync(CancellationToken) instead of blocking in here. The Unity main thread must never block on I/O: it is the thread that drains async continuations, so blocking it can deadlock startup before the transport ever binds.

IsAwaitingAdmission(NetworkConnection)

Returns whether conn is waiting in the queue or has just been admitted and is expected to re-handshake.

public bool IsAwaitingAdmission(NetworkConnection conn)

Parameters

conn NetworkConnection

Returns

bool

Remarks

The admitted-but-not-yet-re-handshaked window matters as much as the queue itself: an admitted client is popped off the queue, so it is no longer "queued", yet it is still unauthenticated and still waiting on us. Treating only the queue as exempt from the handshake timeout would let that window be disconnected out from under a client the server itself just invited back.

IsQueued(NetworkConnection)

Returns whether conn is currently waiting in the queue.

public bool IsQueued(NetworkConnection conn)

Parameters

conn NetworkConnection

Returns

bool

Remarks

Used by the authenticator's handshake-timeout sweep: a queued connection is intentionally left unauthenticated for as long as the wait lasts, which would otherwise look identical to a client that connected and never handshook.

OnClientDisconnected(NetworkConnection)

Removes a disconnected client from the queue and the recently-admitted set.

public void OnClientDisconnected(NetworkConnection conn)

Parameters

conn NetworkConnection

Remarks

Preferred over the ClientId-only overload when the caller still holds the connection: the entry goes immediately rather than lingering until the next purge sweep, which keeps reported positions and the queue count honest and stops the admission loop from having to step over it.

Must be called on the main thread — the queue itself is not thread-safe, which is why the ClientId-only overload deliberately touches nothing but the concurrent recently-admitted set.

OnClientDisconnected(int)

Immediately removes a disconnected client from both the queue and the recently-admitted set. Call from connection-stopped handlers to prevent wasted admission ticks on dead connections.

public void OnClientDisconnected(int clientId)

Parameters

clientId int

The FishNet client ID that disconnected.

OnDeinitialize()

Called when the behaviour is being deinitialized. Must be implemented by derived classes.

public override void OnDeinitialize()

OnUpdate(float)

Override this method in derived classes that need per-frame updates. Guaranteed to run only when the behaviour is initialized and Server is non-null.

protected override void OnUpdate(float deltaTime)

Parameters

deltaTime float

Time elapsed since last frame.

TryEnqueue(NetworkConnection)

Attempts to enqueue a connection that was deferred by the auth cap. Returns true if the client was queued; false if the queue is full and the client should be rejected outright.

public bool TryEnqueue(NetworkConnection conn)

Parameters

conn NetworkConnection

The network connection to queue.

Returns

bool

true if queued; false if the queue is at capacity.