Leaderboards
Ranked scores with automatic resets, archives of past periods and server-side anti-cheat.
Create a leaderboard#
Create leaderboards on the Leaderboards page of your project and use the slug in code.
| Setting | Options |
|---|---|
| Slug | Lowercase identifier used in code, e.g. coins. |
| Sort order | DESC (highest first) or ASC (lowest first, e.g. race times). |
| Score mode | BEST keeps each player's best score; LATEST always replaces it. |
| Reset | NONE, DAILY, WEEKLY or MONTHLY. |
| Minimum / maximum score | Minimum and maximum accepted score (optional). |
| Submit cooldown | Minimum seconds between two submissions by one player (optional). |
Submit a score#
The player name comes from the account, so a client cannot submit for someone else.
var submit = await Majacloud.Leaderboards.SubmitScoreAsync("coins", 340);
if (submit.Ok && submit.Value.Accepted)
Debug.Log("New rank #" + submit.Value.Entry.Rank);var submit := await Majacloud.leaderboards.submit_score("coins", 340)
if submit.ok and submit.value.accepted:
print("New rank #", submit.value.entry.rank)const submit = await mc.leaderboards.submitScore('coins', 340);
if (submit.ok && submit.value.accepted) console.log('New rank #' + submit.value.entry.rank);curl -X POST https://majacloud.majanite.com/v1/leaderboards/coins/scores -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"score": 340}'Read rankings#
Top entries need no sign-in; the player's own rank and the entries around it need a signed-in player.
var top = await Majacloud.Leaderboards.GetTopAsync("coins", limit: 10);
var me = await Majacloud.Leaderboards.GetMyRankAsync("coins");
var around = await Majacloud.Leaderboards.GetAroundMeAsync("coins", radius: 3);
if (me.Ok && me.Value.Entry != null) Debug.Log("You are #" + me.Value.Entry.Rank + " of " + me.Value.Total);var top := await Majacloud.leaderboards.get_top("coins", 10)
var me := await Majacloud.leaderboards.get_my_rank("coins")
var around := await Majacloud.leaderboards.get_around_me("coins", 3)
if me.ok and me.value.entry != null:
print("You are #%d of %d" % [me.value.entry.rank, me.value.total])const top = await mc.leaderboards.getTop('coins', { limit: 10 });
const me = await mc.leaderboards.getMyRank('coins');
const around = await mc.leaderboards.getAroundMe('coins', { radius: 3 });
if (me.ok && me.value.entry) console.log(`You are #${me.value.entry.rank} of ${me.value.total}`);curl "https://majacloud.majanite.com/v1/leaderboards/coins/entries?limit=10" -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY"
curl https://majacloud.majanite.com/v1/leaderboards/coins/me -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"
curl "https://majacloud.majanite.com/v1/leaderboards/coins/around-me?radius=3" -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"Resets and previous periods#
Daily, weekly (Monday) and monthly leaderboards reset at 00:00 UTC. The finished period is archived; read it with the previous period:
var yesterday = await Majacloud.Leaderboards.GetTopAsync("coins", 10, 0, MajacloudLeaderboardPeriod.Previous);var yesterday := await Majacloud.leaderboards.get_top("coins", 10, 0, "previous")const yesterday = await mc.leaderboards.getTop('coins', { limit: 10, period: 'previous' });curl "https://majacloud.majanite.com/v1/leaderboards/coins/entries?period=previous" -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY"How many past periods are kept, and how many entries a leaderboard returns, depends on the plan (see Limits).
Anti-cheat#
- Scores outside the minimum or maximum are rejected with
validation. - Submitting faster than the cooldown returns
rate_limited. - Clients can only submit for the signed-in player.
- For competitive games, let your server decide the score and submit it with the secret key.
Submit from your server#
With the secret key, send the player_id and the score. The player must exist.
// Node.js with secretKey: submit after your server validated the match
await admin.server.submitScore('coins', 'player_3f9c…', 980);curl -X POST https://majacloud.majanite.com/v1/leaderboards/coins/scores \
-H "X-Project-ID: $PROJECT_ID" -H "X-Secret-Key: $SECRET_KEY" \
-H "Content-Type: application/json" -d '{"player_id": "player_3f9c…", "score": 980}'