Interface ICharacterMailService
- Namespace
- FishMMO.Database.Npgsql.Services.Interfaces
- Assembly
- FishMMO-DB.dll
Service interface for managing character mail in the database.
public interface ICharacterMailService : ICountByKeyAction<long>, IDeleteByKeyVersionedAction<long>, IFetchCollectionByKeyAction<long, CharacterMailData>
- Inherited Members
Remarks
Mail deletion is expected to be version-gated via the logical Version
so stale updates are rejected and newer authoritative updates win.
Methods
ClaimAttachmentAsync(long, long, long, CancellationToken)
Takes the attachment off one mail, returning what was on it.
Task<DatabaseResult<CharacterMailAttachmentData?>> ClaimAttachmentAsync(long mailId, long characterId, long incomingVersion, CancellationToken cancellationToken = default)
Parameters
mailIdlongThe mail to claim from.
characterIdlongThe owning character ID, for authorization.
incomingVersionlongThe authoritative, monotonic version for this write.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult<CharacterMailAttachmentData?>>
The attachment as it stood before the clear, or no data when the mail had nothing attached, does not exist or is deleted, does not belong to this character, has already been claimed, or already holds a version at or past
incomingVersion.
Remarks
One answer for all of those, on purpose. The caller claims with the version it has just read plus one, so a stale version means another write reached the mail first — in practice another claim — and "there is nothing left to claim" is the true thing to tell the player. A separate stale-state failure would read as a server error for what was a lost race.
Read and clear are one statement. The attachment columns are zeroed and their
previous values returned by the same UPDATE, whose WHERE additionally
requires that something is still attached. Two claims racing on one mail therefore
serialise on the row lock and only the first affects a row — the second matches nothing
and returns no data. Fetching the mail and then clearing it would leave a window in
which both reads see the same item and both callers grant it.
The caller grants what comes back. That ordering means a crash between the clear and the grant loses the attachment rather than duplicating it, which is the correct direction for an authoritative server — the same reasoning the merchant and corpse loot paths use.
DeleteAsync(long, long, long, CancellationToken)
Deletes a specific mail message by its ID if incomingVersion is newer.
Task<DatabaseResult> DeleteAsync(long mailId, long characterId, long incomingVersion, CancellationToken cancellationToken = default)
Parameters
mailIdlongThe mail ID to delete.
characterIdlongThe owning character ID (for authorization).
incomingVersionlongThe authoritative, monotonic version for this delete operation.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult>
A DatabaseResult indicating success or failure.
SendAsync(long, string, long, string, string, int, int, uint, int, long, CancellationToken)
Sends a new mail message from one character to another.
Task<DatabaseResult> SendAsync(long senderCharacterId, string senderName, long recipientCharacterId, string subject, string body, int itemAttachmentTemplateID, int itemAttachmentSeed, uint itemAttachmentAmount, int currencyAttachment, long incomingVersion, CancellationToken cancellationToken = default)
Parameters
senderCharacterIdlongThe sending character ID.
senderNamestringThe display name of the sender.
recipientCharacterIdlongThe recipient character ID.
subjectstringThe mail subject.
bodystringThe mail body text.
itemAttachmentTemplateIDintThe attached item template ID (0 for none).
itemAttachmentSeedintThe attached item seed (0 for none).
itemAttachmentAmountuintThe attached item amount (0 for none).
currencyAttachmentintThe attached currency amount (0 for none).
incomingVersionlongThe authoritative, monotonic version for this persist operation.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult>
A DatabaseResult indicating success or failure.
Remarks
Safe to retry: a retry after a lost reply finds the mail the first attempt wrote and writes no second one, so an attachment is delivered once. What it cannot settle is a failure returned after every retry also failed — the first attempt may still have landed, and a caller that refunds the attachment on any failure can then both refund it and deliver it. That needs the database unreachable from the moment of the commit for the whole retry window.