Interface ILeaderboardService
- Namespace
- FishMMO.Database.Npgsql.Services.Interfaces
- Assembly
- FishMMO-DB.dll
Read-only ranking of characters by a number the game already stores.
public interface ILeaderboardService
Remarks
Nothing here writes. Every source is owned by the system that writes it — the arena match coordinator for ratings, the character save for attributes and achievements — and a leaderboard is only a way of reading it across characters.
Eligibility is decided in the SQL, not by the caller. A deleted character (a soft delete: the row stays with a renamed name) and a character on a banned account are never ranked, and neither is anyone on a staff account unless the query asks for them. Ranks are computed over the eligible rows only, so removing somebody closes the gap they leave rather than leaving a hole in the numbering.
One rank definition, used twice. A page ranks its rows with RANK() ordered by
score, and a standing is one plus the eligible characters with a strictly higher score —
the same number by construction, so a character looked up on its own is given the rank it
would carry on the page. Rows with equal scores share a rank; the order among them is fixed
(fewer games first on the arena board, then character id) so pages never overlap or skip.
Callers are expected to cache: these are ordered reads over whole tables' worth of rows, served cheaply by an index but not free. The scene server holds the results for a short time and shares one read between every player who asks in that window.
Methods
FetchPageAsync(LeaderboardQuery, int, int, CancellationToken)
A slice of a board, best first, with the board's size.
Task<DatabaseResult<LeaderboardPageData>> FetchPageAsync(LeaderboardQuery query, int offset, int limit, CancellationToken cancellationToken = default)
Parameters
queryLeaderboardQueryWhich board.
offsetintZero-based position of the first row.
limitintRows to return, clamped to 1-200.
cancellationTokenCancellationTokenCancellation token.
Returns
FetchStandingAsync(LeaderboardQuery, long, CancellationToken)
One character's rank and score on a board, wherever it falls.
Task<DatabaseResult<LeaderboardStandingData>> FetchStandingAsync(LeaderboardQuery query, long characterId, CancellationToken cancellationToken = default)
Parameters
queryLeaderboardQueryWhich board.
characterIdlongThe character.
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
Succeeds with Ranked false when the character is not on the board, which is an ordinary answer and not a failure.