Leaderboard

portex.leaderboard provides leaderboard capabilities for games or applications.

API Documentation

  • Submit user score

updateUserLeaderboardScore(options:LeaderboardUpdateUserScoreOptions):Promise<void>
  • Get topN leaderboard data

getLeaderboardTopN(options: LeaderboardTopNOptions): Promise<LeaderboardTopNResult>
  • Get user's leaderboard rank information

 getLeaderboardRank(options: LeaderboardRankOptions): Promise<LeaderboardRankResult>

Interface

interface LeaderboardUpdateUserScoreOptions {
	/** Sort direction, asc=0 desc=1, only effective for first data upload */
	direction: number
	/** Extra data */
	extra?: string
	/** Leaderboard name */
	leaderboard_name: string
	/** User ID */
	user_id: string
	/** User score, the key field for sorting */
	score: number
}

interface LeaderboardTopNOptions {
	/** Leaderboard name */
	leaderboard_name: string
	/** Get leaderboard length, maximum support 1000 */
	top_n: number
}

interface LeaderboardTopNUser {
	/** User ID */
	user_id: string
	/** User score, the key field for sorting */
	score: number
	/** Extra data submitted by updateUserLeaderboardScore function */
	extra: string
}

interface LeaderboardTopNResult {
	/** Information of users on the leaderboard */
	leaderboard_users: Array<LeaderboardTopNUser>
}

interface LeaderboardRankOptions {
	/** Leaderboard name */
	leaderboard_name: string
	/** User ID */
	user_id: string
}

interface LeaderboardRankResult {
	/** User rank */
	rank: number
	/** Extra data submitted by updateUserLeaderboardScore function */
	extra: string
}

Example

Notes

  • top_n has a maximum limit of 1000, exceeding this will throw an exception

  • The userLeaderboardRank function will return an exception if the rank exceeds 10000

Last updated