Class BaseServerAuthenticator
- Namespace
- FishMMO.Server.Implementation
- Assembly
- FishMMO.Server.dll
Abstract base MonoBehaviour authenticator that routes FishNet transport callbacks to an engine-independent BaseAuthenticatorCore<TConnection> instance. All handshake, TTL, rate-limit, and worker logic lives in the core; this class bridges FishNet lifecycle events (broadcasts, connection state) to the core.
public abstract class BaseServerAuthenticator : Authenticator, IServerAuthenticator
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourAuthenticatorBaseServerAuthenticator
- Implements
- Derived
- Inherited Members
-
Authenticator.InitializedAuthenticator.NetworkManagerAuthenticator.OnRemoteConnection(NetworkConnection)MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.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.nameObject.hideFlags
Fields
workerCts
CancellationTokenSource for async workers. Created in InitializeWorkers, cancelled in ShutdownWorkers.
protected CancellationTokenSource workerCts
Field Value
Properties
Core
The engine-independent authenticator core. Created by InitializeCoreInstance().
protected abstract BaseAuthenticatorCore<NetworkConnection> Core { get; }
Property Value
- BaseAuthenticatorCore<NetworkConnection>
LogPrefix
Display name used in log messages. Defaults to the concrete class name.
protected virtual string LogPrefix { get; }
Property Value
Server
The server instance providing access to AccountManager and other infrastructure.
public IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour> Server { get; set; }
Property Value
- IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour>
ShutdownToken
Exposed to subclasses so fire-and-forget async operations (e.g. renewal token issuance) can cooperatively cancel during server shutdown rather than accessing disposed database handles after FishMMO.Server.Implementation.Server.PerformShutdown() completes.
protected CancellationToken ShutdownToken { get; }
Property Value
Methods
AreWorkersDrained()
Returns true when all bounded channels are empty and no worker tasks are still running. Used by the server shutdown coroutine to poll for completion without blocking the main thread.
public virtual bool AreWorkersDrained()
Returns
CreateAccountManager()
Creates the appropriate IAccountManager<TConnection> for this authenticator type. SRP authenticators return an SrpAccountManager, token authenticators return a TokenAccountManager.
public abstract IAccountManager<NetworkConnection> CreateAccountManager()
Returns
- IAccountManager<NetworkConnection>
EnqueueMainThreadAction(Action)
Thread-safe enqueue of an action to be executed on the main Unity thread.
protected void EnqueueMainThreadAction(Action action)
Parameters
actionAction
InitializeCoreInstance()
Creates the protocol-specific core instance. Called at the start of InitializeWorkers() before workers are started. Subclasses must create and store their typed core reference here.
protected abstract void InitializeCoreInstance()
InitializeOnce(NetworkManager)
Initializes this script for use.
public override void InitializeOnce(NetworkManager networkManager)
Parameters
networkManagerNetworkManager
InitializeWorkers()
Creates the core instance and starts async workers. Called after Server is assigned.
public void InitializeWorkers()
InvokeClientAuthenticationResult(NetworkConnection, bool)
Invokes the client authentication result event for post-authentication logic.
protected void InvokeClientAuthenticationResult(NetworkConnection conn, bool authenticated)
Parameters
connNetworkConnectionauthenticatedbool
IsConnectionAwaitingQueueAdmission(NetworkConnection)
Whether this connection is waiting for login-queue admission, and so should be exempt from the handshake timeout. Only the Login Server has a queue; the default is false everywhere else.
protected virtual bool IsConnectionAwaitingQueueAdmission(NetworkConnection conn)
Parameters
connNetworkConnection
Returns
OnAuthSweep()
Override for subclass-specific periodic auth state cleanup. Called every frame; implementations should use bounded scan/remove to stay cheap.
protected virtual void OnAuthSweep()
OnAuthentication(NetworkConnection, bool)
Invokes the authentication result event for a connection. On success, the stale-auth sweep no longer purges this connection.
public virtual void OnAuthentication(NetworkConnection conn, bool authenticated)
Parameters
connNetworkConnectionauthenticatedbool
Remarks
Every core reports its result through here on the main thread, so this is where a successful connection leaves both pending-authentication trackers: the core's (EndAuthTracking(TConnection), which otherwise kept the slot until its TTL ran out and then logged the connection as recycled) and the handshake-timeout map. A connection normally left the map when its handshake completed (EndHandshakeWindow(int)); the removal here is the backstop.
OnConnectionStopped(NetworkConnection)
Override to release subclass-owned per-connection state when a remote connection stops. Called before the core purges its own auth state for the connection.
protected virtual void OnConnectionStopped(NetworkConnection conn)
Parameters
connNetworkConnectionThe connection that stopped.
OnUpdate()
Override for subclass-specific per-frame logic (e.g., additional rate-limit sweeps).
protected virtual void OnUpdate()
RegisterProtocolHandlers(NetworkManager)
Registers protocol-specific broadcast handlers (e.g., SRP or token auth). Called once during InitializeOnce(NetworkManager).
protected abstract void RegisterProtocolHandlers(NetworkManager networkManager)
Parameters
networkManagerNetworkManager
ResolveRateLimitKey(NetworkConnection)
Resolves the real client IP for rate limiting. Requires the IP to have been recovered from a verified connection token or auth token. Returns null if the real IP is not yet available — callers MUST disconnect the client. Never falls back to proxy IP or ClientId.
protected string? ResolveRateLimitKey(NetworkConnection conn)
Parameters
connNetworkConnection
Returns
Remarks
Every game server (Login, World and Scene alike) sits behind the same L4 UDP proxy and binds to loopback, so conn.GetAddress() is 127.0.0.1 for every client on every server type. Falling back to it would put all pre-authentication clients in one rate-limit bucket; falling back to ClientId would hand each reconnect a fresh bucket and disable per-IP limiting altogether. The real IP comes only from the IPFetch-issued connection token.
ShutdownWorkers()
Shuts down async workers, disposes resources, and drains the main-thread queue.
public virtual void ShutdownWorkers()
TryMintConnectionToken(NetworkConnection, out string)
Mints a connection token for conn's next hop, binding the real
IP this server already verified for it.
protected bool TryMintConnectionToken(NetworkConnection conn, out string token)
Parameters
connNetworkConnectiontokenstring
Returns
- bool
True when a token was minted; false when the real IP or key is unavailable.
Remarks
Lets the server a client is currently authenticated to hand it a token for the server it is about to connect to (Login → World, World → Scene). Every game server sits behind the same L4 UDP proxy, so the next hop needs a token to learn the client's real IP, and only a party that already knows that IP can issue one.
The IPFetch-issued token cannot be reused for this: it is spent on the first handshake and expires after 60 seconds, long before a player finishes character select. Minting per hop also avoids a second HTTP round-trip to IPFetch and works no matter how long the client sat in the login queue.
Format is byte-identical to IPFetch's (see LoginServerController): payload
realIp|expiryUnix, HMAC-SHA256 over the payload with the shared key, both
halves base64url-encoded. Uses the "shared" key so the no-keyId verification path
resolves it.
UnregisterProtocolHandlers(NetworkManager)
Unregisters broadcast handlers and event subscriptions that were registered in InitializeOnce(NetworkManager). Subclasses overriding RegisterProtocolHandlers(NetworkManager) should override this method to unregister their protocol-specific handlers as well. Called during FishMMO.Server.Implementation.BaseServerAuthenticator.OnDestroy() to prevent handler accumulation if the authenticator is destroyed and re-initialized.
protected virtual void UnregisterProtocolHandlers(NetworkManager networkManager)
Parameters
networkManagerNetworkManager
Events
ConnectionStopping
Raised when a remote connection stops, BEFORE this authenticator forgets the connection's account.
public event Action<NetworkConnection> ConnectionStopping
Event Type
- Action<NetworkConnection>
Remarks
Server behaviours receive their disconnects here (SubscribeToConnectionEvents()),
not from ServerManager.OnRemoteConnectionState. FishNet initialises the authenticator with the
NetworkManager, long before any behaviour, so its handler was always first on that event: the account
mapping was already gone when the behaviours ran, and every GetAccountNameByConnection in a disconnect
handler came back empty. KickRequestSystem never deleted a kick request, so the pending-kick gate refused
the account as "already online" for the request's full three-minute lifetime after every kick.
Each subscriber runs in its own try/catch: one that throws must not cost the others their cleanup, nor this
authenticator its own.
OnAuthenticationResult
Event triggered when server authentication completes for a connection.
public override event Action<NetworkConnection, bool> OnAuthenticationResult
Event Type
OnClientAuthenticationResult
Event triggered for custom post-authentication logic in server behaviours.
public event Action<NetworkConnection, bool> OnClientAuthenticationResult