Table of Contents

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

query LeaderboardQuery

Which board.

offset int

Zero-based position of the first row.

limit int

Rows to return, clamped to 1-200.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<LeaderboardPageData>>

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

query LeaderboardQuery

Which board.

characterId long

The character.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<LeaderboardStandingData>>

Remarks

Succeeds with Ranked false when the character is not on the board, which is an ordinary answer and not a failure.