Interface IArenaMatchService
- Namespace
- FishMMO.Database.Npgsql.Services.Interfaces
- Assembly
- FishMMO-DB.dll
Service interface for arena matches: reading the match a hosting scene server has just loaded, recording its progress and its result.
public interface IArenaMatchService
Remarks
Matches are created by TryFormArenaMatchAsync(long, string, int, int, int, int, TimeSpan, int, ArenaRatingSource, ArenaComposeOptions, CancellationToken), inside the transaction that takes the players out of the queue; nothing here creates one. The hosting scene server is not necessarily the one that formed the match, so everything it needs to run it is read back from these rows.
Methods
CancelAbandonedAsync(TimeSpan, int, CancellationToken)
Cancels matches older than olderThan that have not ended and whose
instance no longer exists.
Task<DatabaseResult<int>> CancelAbandonedAsync(TimeSpan olderThan, int maxRows = 64, CancellationToken cancellationToken = default)
Parameters
olderThanTimeSpanHow long a match must have existed before it can be judged abandoned.
maxRowsintUpper bound on matches cancelled in one call.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<int>>
Matches cancelled.
Remarks
A match whose instance failed to load, or whose hosting server died at any point, would otherwise hold every seat's character out of both finders forever. Called from every scene server's stale sweep, so it does not depend on the server that lost the match.
Aged by the database's clock, which also stamped the match's creation: the sweeping server is rarely the one that formed the match. Served by the partial index on unfinished matches, so a sweep reads the handful of matches still open, not the whole history.
FetchAsync(long, CancellationToken)
Reads one match by id.
Task<DatabaseResult<ArenaMatchData?>> FetchAsync(long matchId, CancellationToken cancellationToken = default)
Parameters
matchIdlongcancellationTokenCancellationToken
Returns
FetchByInstanceAsync(long, CancellationToken)
Reads the match that runs in one instance.
Task<DatabaseResult<ArenaMatchData?>> FetchByInstanceAsync(long instanceId, CancellationToken cancellationToken = default)
Parameters
instanceIdlongThe
scenesrow of the instance.cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<ArenaMatchData?>>
The match, or null when the instance is not an arena match.
FetchCharactersInLiveMatchesAsync(IReadOnlyList<long>, CancellationToken)
Which of the given characters hold a seat in a match that has not ended.
Task<DatabaseResult<IReadOnlyList<long>>> FetchCharactersInLiveMatchesAsync(IReadOnlyList<long> characterIds, CancellationToken cancellationToken = default)
Parameters
characterIdsIReadOnlyList<long>cancellationTokenCancellationToken
Returns
Remarks
The arena half of the one-instance-per-party rule, asked at queue time about a whole party so that a party with a member in a live arena cannot open a dungeon, and one with a dungeon open cannot enter an arena. The forming transaction re-asserts it per seat.
FetchMembersAsync(long, CancellationToken)
Reads every seat of a match.
Task<DatabaseResult<IReadOnlyList<ArenaMatchMemberData>>> FetchMembersAsync(long matchId, CancellationToken cancellationToken = default)
Parameters
matchIdlongcancellationTokenCancellationToken
Returns
FetchRecentForCharacterAsync(long, int, CancellationToken)
A character's most recent matches, newest first, each with their own seat.
Task<DatabaseResult<IReadOnlyList<ArenaHistoryData>>> FetchRecentForCharacterAsync(long characterId, int limit, CancellationToken cancellationToken = default)
Parameters
characterIdlonglimitintcancellationTokenCancellationToken
Returns
MarkSeatVacatedAsync(long, long, CancellationToken)
Marks a seat vacated so the backfill may fill it, keeping the leaver's row for history.
Task<DatabaseResult<bool>> MarkSeatVacatedAsync(long matchId, long characterId, CancellationToken cancellationToken = default)
Parameters
matchIdlongcharacterIdlongcancellationTokenCancellationToken
Returns
- Task<DatabaseResult<bool>>
True when the seat was seated and is now vacated.
ReseatAsync(long, long, CancellationToken)
Re-seats a vacated character who came back inside the reconnect grace, if their seat was not filled meanwhile.
Task<DatabaseResult<bool>> ReseatAsync(long matchId, long characterId, CancellationToken cancellationToken = default)
Parameters
matchIdlongcharacterIdlongcancellationTokenCancellationToken
Returns
- Task<DatabaseResult<bool>>
True when the seat was vacated, the team had room, and the seat is theirs again.
Remarks
"Not filled" is counted: the team must have fewer seated players than the match's team size, under the match row's lock, which the backfill takes too — so a backfill and a reconnect racing for the last seat cannot both have it.
SetBackfillWindowAsync(long, TimeSpan?, CancellationToken)
Opens, for window from now, the window during which vacated seats may
be backfilled; or closes it, with null.
Task<DatabaseResult<bool>> SetBackfillWindowAsync(long matchId, TimeSpan? window, CancellationToken cancellationToken = default)
Parameters
matchIdlongwindowTimeSpan?cancellationTokenCancellationToken
Returns
Remarks
The end is stamped by the database's clock because it is read by the backfill transactions of every other scene server, which compare it with the database's clock; a moment computed by the hosting server would shift the window by the difference between the two machines' clocks.
SetRankedAsync(long, long, CancellationToken)
Stamps a match as ranked in a season. Called once, right after it forms, before it goes live.
Task<DatabaseResult<bool>> SetRankedAsync(long matchId, long seasonId, CancellationToken cancellationToken = default)
Parameters
matchIdlongseasonIdlongcancellationTokenCancellationToken
Returns
UpdateMemberRatingDeltasAsync(long, IReadOnlyList<(long characterId, int ratingDelta)>, CancellationToken)
Writes the rating change each seat earned in a ranked match.
Task<DatabaseResult<int>> UpdateMemberRatingDeltasAsync(long matchId, IReadOnlyList<(long characterId, int ratingDelta)> deltas, CancellationToken cancellationToken = default)
Parameters
matchIdlongdeltasIReadOnlyList<(long characterId, int ratingDelta)>cancellationTokenCancellationToken
Returns
UpdateMemberTalliesAsync(long, IReadOnlyList<(long characterId, int kills, int deaths, int score)>, CancellationToken)
Writes the final tallies for a match's seats in one statement.
Task<DatabaseResult<int>> UpdateMemberTalliesAsync(long matchId, IReadOnlyList<(long characterId, int kills, int deaths, int score)> tallies, CancellationToken cancellationToken = default)
Parameters
matchIdlongMatch the seats belong to.
talliesIReadOnlyList<(long characterId, int kills, int deaths, int score)>Per character: kills, deaths and score.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<int>>
Rows updated.
UpdateStatusAsync(long, ArenaMatchStatus, int, CancellationToken)
Advances a match's status, stamping the start or end time as appropriate.
Task<DatabaseResult<bool>> UpdateStatusAsync(long matchId, ArenaMatchStatus status, int winnerTeam = -1, CancellationToken cancellationToken = default)
Parameters
matchIdlongMatch to update.
statusArenaMatchStatusNew status.
winnerTeamintWinning team for Ended, or -1.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<bool>>
True when the row moved.
Remarks
Only ever moves forward: the WHERE refuses a status lower than the current one,
so a late write from a server that lost the instance cannot reopen an ended match.