Table of Contents

Interface ICharacterService

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

Service interface for managing character entities in the database. Handles core character operations including creation, retrieval, updates, and deletion.

public interface ICharacterService : ICountByKeyAction<string>, IDeleteByKeyVersionedAction<long>, IFetchByKeyAction<long, CharacterData?>, IFetchByKeyAction<string, CharacterData?>, IFetchManyByKeyAction<string, CharacterData>, IPersistAction<CharacterData>
Inherited Members

Remarks

All write operations (Create*, Persist*, Delete*, Set*, Update*) in this service use execution strategies to ensure transient database failures are automatically retried according to the retry policy configured on the DbContext. This is critical because ExecuteSqlRawAsync and SaveChangesAsync do not automatically retry on transient failures without an execution strategy wrapper. BaseService provides execution wrappers for retry and centralized exception mapping; explicit transactions are used only when a write requires multiple database statements.

All methods return DatabaseResult or DatabaseResult<T> to provide structured error information through the DatabaseException system, helping distinguish between: - Validation failures (invalid parameters) - Business rule violations (name already exists) - Database errors (connection issues, constraint violations, timeouts) - Entity not found errors - Unexpected runtime errors

Write operations prefer single-statement SQL (UPDATE/INSERT/DELETE, UPSERT/CTEs) to preserve atomicity and avoid race conditions when multiple servers or clients modify data simultaneously. When more than one database statement is unavoidable, the implementation uses an explicit transaction wrapper.

Methods

AnyOnlineAsync(string, CancellationToken)

Checks whether any non-deleted character on the given account is currently online.

Task<DatabaseResult<bool>> AnyOnlineAsync(string account, CancellationToken cancellationToken = default)

Parameters

account string

The account name.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<bool>>

A DatabaseResult<T> containing true if at least one character is online, false otherwise.

ClearCombatLoggedAsync(long, CancellationToken)

Clears the combat-logout flag on a character.

Task<DatabaseResult> ClearCombatLoggedAsync(long characterId, CancellationToken cancellationToken = default)

Parameters

characterId long

Character to clear.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

Remarks

Used when the scene server that held a character's body is judged to be gone, so the character is no longer waiting for a body that will never be handed back.

ClearMuteAsync(long, CancellationToken)

Lifts one character's chat mute.

Task<DatabaseResult> ClearMuteAsync(long characterId, CancellationToken cancellationToken = default)

Parameters

characterId long

Character to unmute.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

Success, or DB_NOT_FOUND when no such character exists.

CreateCharacterAsync(CharacterData, CancellationToken)

Creates a new character in the database.

Task<DatabaseResult<long>> CreateCharacterAsync(CharacterData characterData, CancellationToken cancellationToken = default)

Parameters

characterData CharacterData

The character data to create.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<long>>

A DatabaseResult<T> containing the newly inserted character ID on success, or a failure with AlreadyExists if the name is taken, ValidationError for invalid input, or DatabaseError for unexpected failures.

Remarks

Uses a single-statement SQL insert (CTE-based) with execution strategy wrapping to ensure transient database failures are automatically retried. Character names are stored with a lowercase version for case-insensitive uniqueness.

FetchAdminAsync(long, CancellationToken)

Fetches one character in the operator projection, deleted rows included.

Task<DatabaseResult<CharacterAdminData>> FetchAdminAsync(long characterId, CancellationToken cancellationToken = default)

Parameters

characterId long

The character to fetch.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<CharacterAdminData>>

Remarks

Unlike every game-facing fetch this does not filter deleted rows out: the whole point of an operator view is to see the row that a player can no longer see.

FetchAdminByAccountAsync(string, bool, CancellationToken)

Every character on one account, in the operator projection.

Task<DatabaseResult<IReadOnlyList<CharacterAdminData>>> FetchAdminByAccountAsync(string accountName, bool includeDeleted, CancellationToken cancellationToken = default)

Parameters

accountName string

The owning account.

includeDeleted bool

Whether soft-deleted characters are included.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<IReadOnlyList<CharacterAdminData>>>

Remarks

An exact match on the account, not a prefix search filtered afterwards. Reusing the search for this looked equivalent and is not: its match is a prefix, so another account whose name merely starts the same way shares the result set, and on a page boundary that pushes the account's own characters out of the page entirely. An account detail page that quietly omits characters is worse than one that fails.

FetchAsync(string, bool?, CancellationToken)

Task<DatabaseResult<CharacterData?>> FetchAsync(string characterName, bool? selected, CancellationToken cancellationToken = default)

Parameters

characterName string
selected bool?
cancellationToken CancellationToken

Returns

Task<DatabaseResult<CharacterData?>>

FetchByAccountAsync(string, bool?, CancellationToken)

Fetches a character by account name with an optional selected filter.

Task<DatabaseResult<CharacterData?>> FetchByAccountAsync(string accountName, bool? selected, CancellationToken cancellationToken = default)

Parameters

accountName string

The account name.

selected bool?

If provided, filters by the selected status.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<CharacterData?>>

A DatabaseResult<T> containing the character data, or null if not found.

FetchByAccountAsync(string, CancellationToken)

Fetches a character by account name. Returns the first matching character.

Task<DatabaseResult<CharacterData?>> FetchByAccountAsync(string accountName, CancellationToken cancellationToken = default)

Parameters

accountName string

The account name.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<CharacterData?>>

A DatabaseResult<T> containing the character data, or null if not found.

FetchChatMuteAsync(long, CancellationToken)

Reads both mutes that apply to a character: its own and its account's.

Task<DatabaseResult<CharacterChatMuteState>> FetchChatMuteAsync(long characterId, CancellationToken cancellationToken = default)

Parameters

characterId long

Character to read.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<CharacterChatMuteState>>

Both mutes, or DB_NOT_FOUND when no such character exists.

Remarks

One statement joining the two rows, because either mute silences the character; a caller that read only the character's would let a muted account talk through a new character. Deleted characters are excluded.

FetchInWorldCharacterAsync(string, CancellationToken)

Returns the account's character that currently holds a session, if any.

Task<DatabaseResult<CharacterData?>> FetchInWorldCharacterAsync(string account, CancellationToken cancellationToken = default)

Parameters

account string

Account to inspect.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<CharacterData?>>

The in-world character, or null when the account has none.

Remarks

Unlike AnyOnlineAsync(string, CancellationToken) this counts combat-logout bodies as well, because the caller needs to know a body exists in order to refuse switching away from it. An account may only ever have one character in the world, so at most one row matches.

FetchLockAsync(long, CancellationToken)

Reads a character's staff lock.

Task<DatabaseResult<CharacterLockState>> FetchLockAsync(long characterId, CancellationToken cancellationToken = default)

Parameters

characterId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<CharacterLockState>>

FetchNamesAsync(IReadOnlyList<long>, CancellationToken)

Fetches a character by name with an optional selected filter.

Task<DatabaseResult<IReadOnlyList<CharacterNameData>>> FetchNamesAsync(IReadOnlyList<long> characterIds, CancellationToken cancellationToken = default)

Parameters

characterIds IReadOnlyList<long>

Characters to resolve. Duplicates and non-positive IDs are ignored.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<IReadOnlyList<CharacterNameData>>>

A DatabaseResult<T> containing the character data, or null if not found.

Remarks

For labelling rows in lists shown to other players — the dungeon finder's instance list, principally. Projects to ID and name only, and is bounded internally as well as by its caller, because it answers a request a client controls the timing of.

IDs that do not resolve are simply absent from the result rather than being reported; a caller showing a list has to cope with a missing name anyway, since a character can be deleted between the list being built and the names being read.

FetchSelectedCharactersByAccountsAsync(List<string>, int, CancellationToken)

Retrieves the selected character for each of the specified accounts in batches.

Task<DatabaseResult<IReadOnlyList<CharacterData>>> FetchSelectedCharactersByAccountsAsync(List<string> accounts, int maxBatchSize = 1000, CancellationToken cancellationToken = default)

Parameters

accounts List<string>

List of account names to query.

maxBatchSize int

Maximum number of accounts per database round-trip (500–2500).

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<IReadOnlyList<CharacterData>>>

A list of selected CharacterData, one per account that has a selected character.

FetchSelectedWithLockAsync(string, CancellationToken)

Fetches an account's selected character together with its staff lock, from one read.

Task<DatabaseResult<(CharacterData Character, CharacterLockState Lock)?>> FetchSelectedWithLockAsync(string accountName, CancellationToken cancellationToken = default)

Parameters

accountName string

The account name.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<(CharacterData Character, CharacterLockState Lock)?>>

The character and its lock, or null when the account has no selected character.

Remarks

What FetchByAccountAsync(string, bool?, CancellationToken) followed by FetchLockAsync(long, CancellationToken) answers, without reading the same row twice.

FetchUnownedSessionsAsync(IReadOnlyList<CharacterSessionLeaseData>, CancellationToken)

Returns the subset of leases whose sessions the database no longer attributes to the supplied owner — that is, the claims the caller has lost.

Task<DatabaseResult<IReadOnlyList<long>>> FetchUnownedSessionsAsync(IReadOnlyList<CharacterSessionLeaseData> leases, CancellationToken cancellationToken = default)

Parameters

leases IReadOnlyList<CharacterSessionLeaseData>

Ownership triples the caller believes it holds.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<IReadOnlyList<long>>>

Character IDs no longer owned by the supplied server/token, including rows that have been deleted.

Remarks

RefreshSessionLeasesAsync(IReadOnlyList<CharacterSessionLeaseData>, CancellationToken) reports only how many rows it refreshed, so a short count says a claim was lost without saying which. This resolves that, and is meant to be called only on the short-count path: it is a diagnostic read, not part of the refresh hot path.

A character reported here is being simulated by a server that can no longer persist it. The caller must evict it locally; see PersistOwnedAsync(CharacterData, CharacterSessionLeaseData, CancellationToken).

LockAsync(long, DateTime, string, string, CancellationToken)

Places a staff lock that keeps the character out of the world until lockedUntilUtc.

Task<DatabaseResult> LockAsync(long characterId, DateTime lockedUntilUtc, string lockedBy, string reason, CancellationToken cancellationToken = default)

Parameters

characterId long
lockedUntilUtc DateTime
lockedBy string
reason string
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

Remarks

An end is required: a forgotten lock with none strands a player behind a refusal they cannot act on. A lock over an existing one replaces it. The lock is enforced where a character enters the world — character select refuses it, and a scene server holding it is told to kick — not by this write, which only records it.

PersistManyAsync(IReadOnlyList<CharacterPersistRequest>, CancellationToken)

Persists many character rows in one transaction, each with the checks PersistOwnedAsync(CharacterData, CharacterSessionLeaseData, CancellationToken) (or, for a request with no claim, the plain version-gated save) would make, and reports an outcome per row.

Task<DatabaseResult<IReadOnlyList<CharacterPersistResult>>> PersistManyAsync(IReadOnlyList<CharacterPersistRequest> requests, CancellationToken cancellationToken = default)

Parameters

requests IReadOnlyList<CharacterPersistRequest>

The rows to write, each with the claim that authorises it or none.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<IReadOnlyList<CharacterPersistResult>>>

One outcome per request, in no particular order. A failed result means the statement failed and nothing is known to have been written.

Remarks

One row's outcome never decides another's: a lost claim, a stale version or a deleted row is reported for that row and the rest are written. Callers keep a list to a few hundred rows, because the row locks are held until the commit.

PersistMuteAsync(long, DateTime?, string?, string?, CancellationToken)

Mutes one character in chat, leaving the account's other characters able to talk.

Task<DatabaseResult> PersistMuteAsync(long characterId, DateTime? mutedUntilUtc, string? mutedBy, string? reason, CancellationToken cancellationToken = default)

Parameters

characterId long

Character to mute.

mutedUntilUtc DateTime?

When the mute lifts, or null for no end.

mutedBy string

Operator account applying the mute.

reason string

The reason recorded with it.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

Success, or DB_NOT_FOUND when no such character exists.

Remarks

Replaces any mute already on the character. Not version-gated and not refused while a session lease is live: the save path's UPDATE never names the mute columns, so a mute written under a live session is not overwritten by the next save, and refusing it would leave operators unable to mute exactly the players who are online misbehaving.

PersistOwnedAsync(CharacterData, CharacterSessionLeaseData, CancellationToken)

Persists a character row, requiring that the caller still holds its session claim.

Task<DatabaseResult> PersistOwnedAsync(CharacterData characterData, CharacterSessionLeaseData ownership, CancellationToken cancellationToken = default)

Parameters

characterData CharacterData

Snapshot to persist. Its Version must exceed the stored version.

ownership CharacterSessionLeaseData

The claim this server holds, as returned by TryClaimAsync(long, long, CancellationToken).

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

Success when written; Forbidden when the claim is no longer held; StaleState when a newer version is already stored; NotFound when the row is gone.

Remarks

The claim taken by TryClaimAsync(long, long, CancellationToken) gates who may load a character. Without this method nothing gated who may write one: the plain PersistAsync is guarded only by the monotonic Version, so a server whose lease lapsed while it was still running kept saving a character another server had legitimately claimed — and reliably won, because its version counter had been climbing for the whole session while the new owner started again from the persisted row. The claim was advisory on the write path, which is what made a lease lapse corrupting rather than merely untidy.

Ownership is verified in the same statement as the write, so there is no window between checking and writing. A caller that no longer owns the row gets Forbidden and must stop simulating the character rather than retrying — the current owner's state is authoritative, and replaying a stale snapshot over it would destroy exactly the progress this refuses to overwrite.

When Buffs is not null, the character's stored buffs are replaced by that set in the same transaction, and only when the row itself is written. The same holds for PersistAsync and for each row of PersistManyAsync(IReadOnlyList<CharacterPersistRequest>, CancellationToken).

RefreshSessionLeaseAsync(long, long, Guid, CancellationToken)

Refreshes the session lease for an owned online character.

Task<DatabaseResult> RefreshSessionLeaseAsync(long characterId, long ownerServerId, Guid ownerToken, CancellationToken cancellationToken = default)

Parameters

characterId long
ownerServerId long
ownerToken Guid
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

RefreshSessionLeasesAsync(IReadOnlyList<CharacterSessionLeaseData>, CancellationToken)

Refreshes the session lease for many owned online characters in a single round trip.

Task<DatabaseResult<int>> RefreshSessionLeasesAsync(IReadOnlyList<CharacterSessionLeaseData> leases, CancellationToken cancellationToken = default)

Parameters

leases IReadOnlyList<CharacterSessionLeaseData>

Ownership triples to refresh. Invalid entries are skipped.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<int>>

The number of leases actually refreshed.

Remarks

Session liveness must not depend on save throughput. Refreshing one character per round trip inside the periodic save loop meant that on a busy shard with a slow database the characters at the tail of the loop could exceed the lease duration between refreshes and become claimable while still online. This performs the whole population in one statement, so the cost is independent of how many characters are resident.

Each entry is verified against the stored owner server and token, so a server that no longer owns a session silently refreshes nothing rather than extending the current owner's lease.

ReleaseAsync(long, long, Guid, CancellationToken)

Releases an online character back to offline and clears ownership in a single step.

Task<DatabaseResult> ReleaseAsync(long characterId, long ownerServerId, Guid ownerToken, CancellationToken cancellationToken = default)

Parameters

characterId long
ownerServerId long
ownerToken Guid
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

ReleaseManyAsync(IReadOnlyList<CharacterSessionLeaseData>, CancellationToken)

Releases many sessions (Online → Offline) in one transaction, each only while it is still held under the supplied server and token — ReleaseAsync(long, long, Guid, CancellationToken) for a batch.

Task<DatabaseResult<IReadOnlyList<long>>> ReleaseManyAsync(IReadOnlyList<CharacterSessionLeaseData> leases, CancellationToken cancellationToken = default)

Parameters

leases IReadOnlyList<CharacterSessionLeaseData>

The claims to hand back. Invalid entries are skipped.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<IReadOnlyList<long>>>

The ids actually released. A claim absent from the result was not this caller's to release (already released, or claimed away after a lease lapse), which is nothing to retry.

RenameAsync(long, string, CancellationToken)

Renames a character.

Task<DatabaseResult> RenameAsync(long characterId, string newName, CancellationToken cancellationToken = default)

Parameters

characterId long

The character to rename.

newName string

The new name. Validated against the shared character-name rules.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

Remarks

Only name is written: name_lowercase is a generated column (lower(name)) and carries the unique index, so the database enforces case-insensitive uniqueness without this method having to check for it first. A collision surfaces as a unique violation rather than a lost update.

RestoreAsync(long, CancellationToken)

Sets the selected character for an account atomically. Deselects all other characters for the account.

Task<DatabaseResult> RestoreAsync(long characterId, CancellationToken cancellationToken = default)

Parameters

characterId long

The character ID to select.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult>

A DatabaseResult indicating success or containing a DatabaseException on failure.

Remarks

Uses a single atomic UPDATE with conditional logic: SET selected = (id = characterId). This ensures all characters for the account are updated in one operation without race conditions. Execution strategy wrapping ensures transient database failures are automatically retried.

RollbackChannelSwitchAsync(long, DateTime, CancellationToken)

Restores a channel-switch cooldown claimed by TryBeginChannelSwitchAsync(long, TimeSpan, CancellationToken) for a switch that did not happen.

Task<DatabaseResult> RollbackChannelSwitchAsync(long characterId, DateTime previousUtc, CancellationToken cancellationToken = default)

Parameters

characterId long

Character whose claim is being released.

previousUtc DateTime

The value returned by the claim, restored as-is.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

Remarks

The claim has to be taken before the transfer, because it is the last thing that can refuse the request — but the transfer can still fail after it: the character enters combat during the validation, the connection goes away, or the scene server's main-thread queue rejects the hand-off. Leaving the claim in place then charged a player the full cooldown for a switch they were refused, and answered their retry with "you are travelling too often" on top of the refusal they had already been given.

Restores the exact previous value rather than clearing the column, so a player who genuinely switched moments ago still serves out the remainder of that cooldown. Nothing else writes this column, and a character has one session, so the guard below cannot discard a newer legitimate claim.

SearchAdminAsync(string, bool, bool?, int, int, CancellationToken)

Task<DatabaseResult<CharacterAdminPage>> SearchAdminAsync(string query, bool includeDeleted, bool? online, int page, int pageSize, CancellationToken cancellationToken = default)

Parameters

query string
includeDeleted bool
online bool?
page int
pageSize int
cancellationToken CancellationToken

Returns

Task<DatabaseResult<CharacterAdminPage>>

SetSelectedAsync(string, long, CancellationToken)

Task<DatabaseResult> SetSelectedAsync(string account, long characterId, CancellationToken cancellationToken = default)

Parameters

account string
characterId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

TryBeginChannelSwitchAsync(long, TimeSpan, CancellationToken)

Atomically claims a character's channel-switch cooldown window: succeeds and stamps the character only if it has not switched within cooldown.

Task<DatabaseResult<DateTime?>> TryBeginChannelSwitchAsync(long characterId, TimeSpan cooldown, CancellationToken cancellationToken = default)

Parameters

characterId long

Character attempting the switch.

cooldown TimeSpan

Minimum interval between switches.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<DateTime?>>

The timestamp the claim replaced when the switch may proceed, so a caller that then fails to perform the transfer can put it back with RollbackChannelSwitchAsync(long, DateTime, CancellationToken); null when the character is still on cooldown and nothing was stamped. NotFound when the character does not exist or is deleted.

Remarks

A channel switch releases the character and drops the connection, so the client comes back through the world server on a fresh connection id — very possibly to a different scene server. Any cooldown held in memory is therefore erased by the switch itself, which left the limit applying only to switches that were refused. The character row is the only state that survives the hop.

Check and stamp are one statement so two scene servers cannot both conclude the cooldown has elapsed. Deliberately not version-gated: this is a rate limit, not gameplay state, and it must not lose to — or interfere with — a concurrent save.

TryClaimAsync(long, long, CancellationToken)

Attempts to claim ownership of a character session (Offline → Online).

Task<DatabaseResult<Guid>> TryClaimAsync(long characterId, long ownerServerId, CancellationToken cancellationToken = default)

Parameters

characterId long
ownerServerId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<Guid>>

Remarks

A claim is permitted if the character is offline or the previous owner's lease has expired. On success, returns a new session owner token that must be presented for subsequent operations.

UnlockAsync(long, CancellationToken)

Releases a staff lock. True when there was one to release, lapsed or not.

Task<DatabaseResult<bool>> UnlockAsync(long characterId, CancellationToken cancellationToken = default)

Parameters

characterId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<bool>>

UpdateAdminAsync(long, CharacterAdminEdit, CancellationToken)

Searches characters for an operator, by character name or account name.

Task<DatabaseResult> UpdateAdminAsync(long characterId, CharacterAdminEdit edit, CancellationToken cancellationToken = default)

Parameters

characterId long

The character to edit.

edit CharacterAdminEdit

The fields to change. Nulls are left alone.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

Remarks

The match is a case-insensitive prefix on name_lowercase or on the account name. A prefix, not a contains: name_lowercase carries a unique index that a prefix can use and a leading wildcard cannot, so a shard with a million characters still answers from the index.

UpdatePositionAsync(long, float, float, float, float, float, float, float, CancellationToken)

Updates the position and rotation of a character atomically.

Task<DatabaseResult> UpdatePositionAsync(long characterId, float x, float y, float z, float rotX, float rotY, float rotZ, float rotW, CancellationToken cancellationToken = default)

Parameters

characterId long

The character ID.

x float

The X coordinate.

y float

The Y coordinate.

z float

The Z coordinate.

rotX float

The rotation X component.

rotY float

The rotation Y component.

rotZ float

The rotation Z component.

rotW float

The rotation W component.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult>

A DatabaseResult indicating success or containing a DatabaseException on failure.

Remarks

Uses atomic UPDATE to set all position and rotation components in one operation. Updates last_saved timestamp automatically. Execution strategy wrapping ensures transient database failures are automatically retried.

UpdateSceneAsync(long, long, string, long, CancellationToken)

Updates the routing information for a character atomically.

Task<DatabaseResult> UpdateSceneAsync(long characterId, long worldServerId, string sceneName, long sceneHandle, CancellationToken cancellationToken = default)

Parameters

characterId long

The character ID.

worldServerId long

The world server the character is being routed through.

sceneName string

The scene name.

sceneHandle long

The scene handle.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult>

A DatabaseResult indicating success or containing a DatabaseException on failure.

Remarks

Uses atomic UPDATE to set world_server_id, scene_name and scene_handle in one operation. All three are written together because the Scene Server matches an incoming character against its loaded scene instances on the full (world_server_id, scene_name, scene_handle) tuple — persisting the scene half while leaving world_server_id stale makes that lookup reject the character as mismatched. Updates last_saved timestamp automatically. Execution strategy wrapping ensures transient database failures are automatically retried.

UpdateSceneBatchAsync(long, IReadOnlyList<(long CharacterId, string SceneName, long SceneHandle)>, CancellationToken)

Writes the routing information of many characters at once: UpdateSceneAsync(long, long, string, long, CancellationToken) for a batch.

Task<DatabaseResult<IReadOnlyList<long>>> UpdateSceneBatchAsync(long worldServerId, IReadOnlyList<(long CharacterId, string SceneName, long SceneHandle)> binds, CancellationToken cancellationToken = default)

Parameters

worldServerId long

The world server every character in the batch is being routed through.

binds IReadOnlyList<(long CharacterId, string SceneName, long SceneHandle)>

Each character's scene name and scene handle. A character named twice takes its last entry.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<IReadOnlyList<long>>>

The ids of the characters whose rows were written. A character with no live row (missing or deleted) is absent, which is the per-row NotFound of UpdateSceneAsync(long, long, string, long, CancellationToken). A failed result wrote nothing the caller may rely on.

Remarks

For the world server's routing pass, which binds every character it places before telling the client where to go. After a world server restart every character's world_server_id is stale, so every one of them needs the write, and one round trip each held the whole routing cycle for seconds.