Table of Contents

Class LoginServerService

Namespace
FishMMO.Database.Npgsql.Services
Assembly
FishMMO-DB.dll

Login server registration and management service. Uses EF Core compiled queries for hot paths and the BaseService execution strategy for retries.

public sealed class LoginServerService : BaseService<LoginServerEntity>, ILoginServerService, IFetchByKeyAction<long, LoginServerData>
Inheritance
LoginServerService
Implements
Inherited Members

Constructors

LoginServerService(INpgsqlDbContextFactory)

Initializes a new instance of LoginServerService.

public LoginServerService(INpgsqlDbContextFactory dbContextFactory)

Parameters

dbContextFactory INpgsqlDbContextFactory

DbContext factory for creating contexts.

Exceptions

ArgumentNullException

Thrown when dbContextFactory is null.

Methods

DeleteAsync(long, CancellationToken)

Deletes a login server registration.

public Task<DatabaseResult> DeleteAsync(long serverId, CancellationToken cancellationToken = default)

Parameters

serverId long

Server ID to delete. Must be greater than 0.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

DatabaseResult indicating success or failure with error details.

Remarks

Success: Server registration removed from database. If the server does not exist, this operation still succeeds. Failure cases:

  • VALIDATION_ERROR: Invalid server ID (less than or equal to 0)
  • DATABASE_ERROR: Unexpected database error

FetchAsync(long, CancellationToken)

Fetches an entity for the given key.

public Task<DatabaseResult<LoginServerData>> FetchAsync(long serverId, CancellationToken cancellationToken = default)

Parameters

serverId long
cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<LoginServerData>>

PersistAsync(string, string, ushort, CancellationToken)

Adds or updates a login server registration.

public Task<DatabaseResult<LoginServerData>> PersistAsync(string name, string address, ushort port, CancellationToken cancellationToken = default)

Parameters

name string

Server name (unique identifier). Must not be null or whitespace.

address string

Server address. Must not be null or whitespace.

port ushort

Server port.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<LoginServerData>>

DatabaseResult containing LoginServerData with server ID and details on success.

Remarks

Success: Returns complete server data including generated ID. Failure cases:

  • VALIDATION_ERROR: Invalid name or address (null/whitespace)
  • UNIQUE_VIOLATION: A unique constraint was violated (non-transient). Note: normal concurrent registration by name is handled via UPSERT and should not produce this.
  • DATABASE_ERROR: Unexpected database error

PulseAsync(long, CancellationToken)

Updates the last pulse timestamp for a login server (heartbeat).

public Task<DatabaseResult> PulseAsync(long serverId, CancellationToken cancellationToken = default)

Parameters

serverId long

Server ID. Must be greater than 0.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

DatabaseResult indicating success or failure with error details.

Remarks

Success: Pulse timestamp updated. Failure cases:

  • VALIDATION_ERROR: Invalid server ID (less than or equal to 0)
  • ENTITY_NOT_FOUND: Server does not exist
  • DATABASE_ERROR: Unexpected database error