Table of Contents

Class TokenAuthenticatorCore<TConnection>

Namespace
FishMMO.Auth.Implementation
Assembly
FishMMO-ServerAuth.dll

Engine-independent token-based authenticator core for World/Scene servers. Extends BaseAuthenticatorCore<TConnection> with a bounded-channel token auth worker that decrypts, verifies, and revocation-checks client-supplied auth tokens issued by the LoginServer.

Subclasses supply transport-specific callbacks (broadcast, database validation).

public abstract class TokenAuthenticatorCore<TConnection> : BaseAuthenticatorCore<TConnection>

Type Parameters

TConnection

The type representing a network connection.

Inheritance
TokenAuthenticatorCore<TConnection>
Inherited Members

Constructors

TokenAuthenticatorCore(ITokenAccountManager<TConnection>)

Initializes the token authenticator core.

protected TokenAuthenticatorCore(ITokenAccountManager<TConnection> accountManager)

Parameters

accountManager ITokenAccountManager<TConnection>

Token account manager instance.

Properties

IsWorkerIdle

Returns true when no async worker operations are in-flight. Subclasses with bounded-channel workers should override to check channel emptiness. Default returns true.

public override bool IsWorkerIdle { get; }

Property Value

bool

RequiresRealIp

Whether this authenticator requires the auth token to carry a verified real IP.

protected virtual bool RequiresRealIp { get; }

Property Value

bool

Remarks

True by default, because that is the setting that cannot be wrong by accident: behind an L4 proxy GetConnectionAddress returns the proxy's loopback for every client, so the token-embedded IP is the only trustworthy one and the handshake rate limiter has nothing else to key off.

Override to false only where clients reach this authenticator directly. The IP is put into the token by whoever issued it, and an issuer that never saw a real IP cannot supply one — so in a deployment without the proxy this requirement rejects tokens that are otherwise entirely valid, and no player can enter the world.

TokenChannelCapacity

Default maximum pending token auth requests in the bounded channel. Configurable via .cfg AuthTokenChannelCapacity.

public int TokenChannelCapacity { get; set; }

Property Value

int

TokenWorkerCount

Default number of concurrent token auth worker tasks. Configurable via .cfg AuthTokenWorkerCount.

public int TokenWorkerCount { get; set; }

Property Value

int

Methods

CheckTokenRevocationAsync(string)

Checks whether a token has been revoked, using its SHA-256 hex hash.

protected abstract Task<bool> CheckTokenRevocationAsync(string tokenHash)

Parameters

tokenHash string

SHA-256 hex hash of the raw token.

Returns

Task<bool>

True if the token is revoked.

FetchSigningKeyAsync(long, long)

Fetches the HMAC signing key for the given login server ID from the database. Returns null if the key is not found, too short, or a database error occurred; the caller will substitute a random dummy key for timing equalization when null is returned.

protected abstract Task<byte[]> FetchSigningKeyAsync(long loginServerId, long signingKeyId)

Parameters

loginServerId long

Login server database ID.

signingKeyId long

Returns

Task<byte[]>

A fresh copy of the HMAC key, or null.

InitializeWorkersCore(CancellationToken)

Subclass-specific worker initialization: create channels and start worker tasks. Called after the base generates the cookie key.

protected override void InitializeWorkersCore(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Token for signalling worker shutdown.

IsConnectionActive(TConnection)

Returns whether the connection is currently active (connected and not disposed).

protected abstract bool IsConnectionActive(TConnection conn)

Parameters

conn TConnection

The connection to check.

Returns

bool

true if the connection is still active; otherwise, false.

OnAuthenticationResult(TConnection, bool)

Called when authentication completes (success or failure). Implementations should call their engine's authenticate/reject methods here.

protected abstract void OnAuthenticationResult(TConnection conn, bool authenticated)

Parameters

conn TConnection

The authenticated (or rejected) connection.

authenticated bool

True if authentication succeeded.

OnTokenAuthReceived(TConnection, byte[], uint)

Gate for an incoming token auth broadcast. Validates connection state and enqueues for async processing. No decryption or database work occurs here.

public void OnTokenAuthReceived(TConnection conn, byte[] encryptedToken, uint seq)

Parameters

conn TConnection

The network connection.

encryptedToken byte[]

AES-GCM encrypted auth token from client.

seq uint

Broadcast sequence number.

OnTokenAuthSuccessAsync(TConnection, string, AccessLevel, long)

Invoked once after a successful token authentication (and the resulting auth-result broadcast). Override to mint and push a fresh auth token to the client over the existing AES-GCM session channel, extending the effective session lifetime past the original LoginServer-issued token's expiration.

Exceptions thrown here are caught by the caller and logged as warnings; they do not invalidate the just-completed authentication.

protected virtual Task OnTokenAuthSuccessAsync(TConnection conn, string accountName, AccessLevel accessLevel, long loginServerId)

Parameters

conn TConnection

The newly authenticated connection.

accountName string

Account name extracted from the verified token.

accessLevel AccessLevel

Access level extracted from the verified token.

loginServerId long

Login server ID extracted from the verified token (used to look up the HMAC signing key for the renewal).

Returns

Task

ShutdownWorkersCore()

Subclass-specific worker shutdown: complete channel writers, null channel references, and clear subclass-specific state. Called BEFORE the base zeroes the cookie key.

protected override void ShutdownWorkersCore()

StoreClientRealIp(TConnection, string)

Stores the real client IP recovered from a verified auth token (v4+). Override in server-specific subclasses to write to ConnectionIpCache.

protected virtual void StoreClientRealIp(TConnection conn, string realIp)

Parameters

conn TConnection
realIp string

TryLoginAsync(ClientAuthenticationResult, string)

Attempts to complete login for a newly authenticated token connection. Override to apply server-type-specific login logic.

protected virtual Task<ClientAuthenticationResult> TryLoginAsync(ClientAuthenticationResult defaultResult, string username)

Parameters

defaultResult ClientAuthenticationResult

The result to return if no override logic modifies it.

username string

Account name being authenticated.

Returns

Task<ClientAuthenticationResult>

The final ClientAuthenticationResult to send to the client.