Table of Contents

Class ArenaMatchService

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

Service for arena matches. See IArenaMatchService.

public sealed class ArenaMatchService : BaseService<ArenaMatchEntity>, IArenaMatchService
Inheritance
ArenaMatchService
Implements
Inherited Members

Constructors

ArenaMatchService(INpgsqlDbContextFactory)

Initializes a new instance of ArenaMatchService.

public ArenaMatchService(INpgsqlDbContextFactory dbContextFactory)

Parameters

dbContextFactory INpgsqlDbContextFactory

Methods

CancelAbandonedAsync(DateTime, int, CancellationToken)

Cancels matches that had not ended by createdBeforeUtc and whose instance no longer exists.

public Task<DatabaseResult<int>> CancelAbandonedAsync(DateTime createdBeforeUtc, int maxRows = 64, CancellationToken cancellationToken = default)

Parameters

createdBeforeUtc DateTime
maxRows int
cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

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.

FetchAsync(long, CancellationToken)

Reads one match by id.

public Task<DatabaseResult<ArenaMatchData?>> FetchAsync(long matchId, CancellationToken cancellationToken = default)

Parameters

matchId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<ArenaMatchData?>>

FetchByInstanceAsync(long, CancellationToken)

Reads the match that runs in one instance.

public Task<DatabaseResult<ArenaMatchData?>> FetchByInstanceAsync(long instanceId, CancellationToken cancellationToken = default)

Parameters

instanceId long

The scenes row of the instance.

cancellationToken CancellationToken

Cancellation 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.

public Task<DatabaseResult<IReadOnlyList<long>>> FetchCharactersInLiveMatchesAsync(IReadOnlyList<long> characterIds, CancellationToken cancellationToken = default)

Parameters

characterIds IReadOnlyList<long>
cancellationToken CancellationToken

Returns

Task<DatabaseResult<IReadOnlyList<long>>>

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.

public Task<DatabaseResult<IReadOnlyList<ArenaMatchMemberData>>> FetchMembersAsync(long matchId, CancellationToken cancellationToken = default)

Parameters

matchId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<IReadOnlyList<ArenaMatchMemberData>>>

FetchRecentForCharacterAsync(long, int, CancellationToken)

A character's most recent matches, newest first, each with their own seat.

public Task<DatabaseResult<IReadOnlyList<ArenaHistoryData>>> FetchRecentForCharacterAsync(long characterId, int limit, CancellationToken cancellationToken = default)

Parameters

characterId long
limit int
cancellationToken CancellationToken

Returns

Task<DatabaseResult<IReadOnlyList<ArenaHistoryData>>>

MarkSeatVacatedAsync(long, long, CancellationToken)

Marks a seat vacated so the backfill may fill it, keeping the leaver's row for history.

public Task<DatabaseResult<bool>> MarkSeatVacatedAsync(long matchId, long characterId, CancellationToken cancellationToken = default)

Parameters

matchId long
characterId long
cancellationToken CancellationToken

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.

public Task<DatabaseResult<bool>> ReseatAsync(long matchId, long characterId, CancellationToken cancellationToken = default)

Parameters

matchId long
characterId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<bool>>

True when the seat was vacated and is theirs again.

SetBackfillWindowAsync(long, DateTime?, CancellationToken)

Opens (or closes, with null) the window during which vacated seats may be backfilled.

public Task<DatabaseResult<bool>> SetBackfillWindowAsync(long matchId, DateTime? untilUtc, CancellationToken cancellationToken = default)

Parameters

matchId long
untilUtc DateTime?
cancellationToken CancellationToken

Returns

Task<DatabaseResult<bool>>

SetRankedAsync(long, long, CancellationToken)

Stamps a match as ranked in a season. Called once, right after it forms, before it goes live.

public Task<DatabaseResult<bool>> SetRankedAsync(long matchId, long seasonId, CancellationToken cancellationToken = default)

Parameters

matchId long
seasonId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<bool>>

UpdateMemberRatingDeltasAsync(long, IReadOnlyList<(long characterId, int ratingDelta)>, CancellationToken)

Writes the rating change each seat earned in a ranked match.

public Task<DatabaseResult<int>> UpdateMemberRatingDeltasAsync(long matchId, IReadOnlyList<(long characterId, int ratingDelta)> deltas, CancellationToken cancellationToken = default)

Parameters

matchId long
deltas IReadOnlyList<(long characterId, int ratingDelta)>
cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

UpdateMemberTalliesAsync(long, IReadOnlyList<(long characterId, int kills, int deaths, int score)>, CancellationToken)

Writes the final tallies for a match's seats in one statement.

public Task<DatabaseResult<int>> UpdateMemberTalliesAsync(long matchId, IReadOnlyList<(long characterId, int kills, int deaths, int score)> tallies, CancellationToken cancellationToken = default)

Parameters

matchId long

Match the seats belong to.

tallies IReadOnlyList<(long characterId, int kills, int deaths, int score)>

Per character: kills, deaths and score.

cancellationToken CancellationToken

Cancellation 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.

public Task<DatabaseResult<bool>> UpdateStatusAsync(long matchId, ArenaMatchStatus status, int winnerTeam = -1, CancellationToken cancellationToken = default)

Parameters

matchId long

Match to update.

status ArenaMatchStatus

New status.

winnerTeam int

Winning team for Ended, or -1.

cancellationToken CancellationToken

Cancellation 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.