Every game has its own leaderboard over three periods: today, this week and all time. Players see it right below the game frame on the portal, together with their own position. A score only reaches the board after passing the server's anti-cheat checks.
Submission flow
game gameplayStart() the portal sends gameplay_start to the server right away
game ... the player plays ...
game gameplayStop() the portal sends gameplay_stop right away
game leaderboard.submit(42) (within 10 seconds after gameplayStop)
portal flushes pending events, then submits the score to the server
server runs the 7 rules in order → SubmitResult
game receives { accepted, best, rank, improved, reason? }async function onGameOver(score) {
WSG.gameplayStop();
const result = await WSG.leaderboard.submit(Math.floor(score));
if (result.accepted) {
showResult({ best: result.best, rank: result.rank, newRecord: result.improved });
} else {
showResult({ best: result.best, rank: result.rank, note: result.reason });
}
}A rejected score doesn't reject the Promise. best and rank are always present (on rejection they reflect the player's current state), so your game-over screen can render in every case.
Leaderboard periods
| Period | Scope | Resets |
|---|---|---|
daily | The current day, as YYYY-MM-DD | Every day at 00:00 Vietnam time |
weekly | The current ISO week, starting Monday, as YYYY-Www | Mondays at 00:00 Vietnam time |
all | All time | Never |
- The time zone is
Asia/Ho_Chi_Minh(UTC+7) for every player. - Each player has a single row per period: their best score in that period.
- An accepted submission updates all three periods, wherever the new score beats the old one.
scoreOrder: "asc"ingame.jsonflips the comparison: lower scores are better.- In your game, read the boards with
top(),around(),me(), or open the portal's board withshow()(your game is paused while it is open).
Player XP
Besides per-game boards, the portal has a player leaderboard ranked by XP at https://leonogames.com/leaderboard. The server computes XP from the signals your game sends and adds it to the daily, weekly and all-time periods at once:
| Event | XP |
|---|---|
The first gameplayStart() of a play session | +10 |
| Every 10 seconds of gameplay (counted when gameplay stops or the session ends), at most 60 XP per session | +1 |
| An accepted score that beats the player's all-time best in that game | +20 |
| After a submission, an all-time rank ≤ 100 / ≤ 10 / = 1 | +20 / +50 / +100 |
The rank bonus takes the highest tier reached by that submission, and each tier is awarded only once per player per game. So call gameplayStart() and gameplayStop() at the right moments: getting them wrong costs players XP or hands it out unfairly.
Anti-cheat rules
The server checks these in order and stops at the first one that fails, answering HTTP 200 with { accepted: false, reason } (thresholds are not revealed):
| # | Check | reason |
|---|---|---|
| 1 | The play session exists, hasn't ended and belongs to the submitting player | invalid_session |
| — | The game's leaderboard is enabled on the portal | disabled |
| — | The play session has been flagged as suspicious | blocked |
| 2 | The score is an integer from 0 to 2^53 | invalid_score |
| 3 | At most 1 submission per second per session and 30 per minute per player | rate_limited |
| 4 | Gameplay is running, or gameplayStop() happened no more than 10 seconds ago | no_gameplay |
| 5 | Score ≤ limits.maxScore | over_max |
| 6 | Play time ≥ limits.minDurationMs; with scoreOrder: "asc", also the declared time check (see below) | too_fast |
| 7 | Score ÷ seconds played ≤ limits.maxScorePerSecond (not applied to asc) | rate_too_high |
- Play time (elapsed) is the session's total gameplay time up to the moment the server receives the score: every stretch from
gameplayStart()togameplayStop()added up, including the one still running, with a minimum of 1 second. Pauses between agameplayStop()and the nextgameplayStart()don't count. Each call is timestamped when the portal page receives it; that time is used if it reaches the server within 15 seconds, otherwise the server uses its own receipt time. - Every rejection is logged (a
score_rejectedevent with thereasonand the score) and counts toward a per-player counter. After 5 rejections within the same 10-minute window, the current play session is flagged and every later submission in that session getsblocked, until the player opens a new session (presses Play again on the portal or reloads the page). - A submission rejected by rules 4–7 still counts toward the limit of rule 3.
- An accepted score is stored, updates the three periods and awards XP.
Rejection reasons and fixes
reason | Common cause | Fix |
|---|---|---|
invalid_session | The session has ended: the player left or reloaded, or the game kept running after the old session closed | Submit as soon as the round ends; nothing else to do in the game |
invalid_score | The score has a fractional part, is negative, or is too large | Math.floor() and clamp the score before submitting |
rate_limited | Several submissions within a second, or more than 30 per minute | Submit only once per round |
no_gameplay | gameplayStart() was never called; it was called before init() finished; the score came more than 10 seconds after gameplayStop() | Call gameplayStart() after await WSG.init(), submit right after gameplayStop() |
over_max | The score is above maxScore | Clamp the score in-game, or raise maxScore if the design allows it |
too_fast | The round ended faster than minDurationMs; with asc, the declared time is shorter than the time the server measured | Set minDurationMs to the fastest possible run; with asc, submit the milliseconds measured in the game (see below) |
rate_too_high | Score divided by play time is above maxScorePerSecond | Recompute using how to choose limits |
blocked | The session was rejected 5 times within 10 minutes | Fix the root cause; the player needs a new session |
disabled | The operations team turned off the leaderboard for this game in the admin page | No game change needed; check WSG.isAvailable('leaderboard') to hide leaderboard buttons. This rejection does not count toward the blocked threshold |
Play time across pauses and revives
Play time adds up every gameplay stretch of the session, so pausing or reviving in the middle of a run doesn't get scores rejected. For example, with maxScorePerSecond: 3:
- The player reaches 40 points after 30 seconds and dies. The game submits 40: 40 ÷ 30 = 1.3 points per second, accepted.
- The player watches a rewarded ad to revive. The SDK already called
gameplayStop()before the ad, so the ad time doesn't count; the game callsgameplayStart()again when play resumes. - Four seconds later the player dies with 42 points. The game submits 42: 42 ÷ 34 = 1.2 points per second, accepted.
Keep in mind:
- The time is added up over the whole session, including earlier rounds in the same session (restarting inside the game doesn't open a new session). Don't rely on it instead of clamping the score in-game.
- Still submit at every death, before offering a revive, so the best score is recorded even if the player leaves midway. The Phaser template does exactly this.
- Every rejection counts toward the
blockedthreshold (5 within 10 minutes).
Time scores (scoreOrder: "asc")
With scoreOrder: "asc", the score must be the finishing time in milliseconds (lower is better). Instead of rule 7, the server checks that:
- the score is ≥
limits.minDurationMs(no faster than the fastest possible run); - the score is not shorter than the latest gameplay stretch the server measured, from the last
gameplayStart()togameplayStop()(or to the submission if gameplay is still running), by more than amax(2 seconds, 10 %)tolerance for delays.
So call gameplayStart() exactly when the clock starts and gameplayStop() at the finish line, then submit the milliseconds measured in the game. Around pauses, call gameplayStop()/gameplayStart() as usual: the measured stretch only gets shorter, so it can't cause a false rejection. maxScorePerSecond is not used for asc, but it must still be a positive number in game.json.
Tips for choosing limits
- Derive the maximum scoring rate from the design, then multiply by 1.5; don't guess from human speed.
- Clamp the in-game score at
maxScoreso you never submit above it. - A
minDurationMsbelow 1000 has no effect, since play time is always at least 1 second. - Try the fastest valid runs and the highest scores on the staging portal before releasing.
limitslive in each version'sgame.json. To change them, release a new version; play sessions created after the release use the new values.- With
scoreOrder: "asc", the score is in milliseconds and checked as described in Time scores.
Reading leaderboards from your server
The leaderboard read API is public, so your website or server can use it:
# Get the game's id (a UUID) from its slug
curl -s https://api.leonogames.com/api/v1/games/tap-rush
# This week's top 10 of the game
curl -s "https://api.leonogames.com/api/v1/leaderboards/games/<game-id>?period=weekly&limit=10"The response looks like { period, bucket, entries, me }, where entries holds rows of { rank, playerId, name, avatarUrl, score, isMe } and me is null when called without a player cookie. period defaults to all, limit ranges from 1 to 100 (default 50). The public read APIs share a limit of 300 requests per minute per IP, so cache the results. Only released games are available through the API.
Authenticating players on your game server
When your game talks to your own server (after agreeing on it with the operations team, see Game requirements), use the token issued by the portal to know for sure who the player is.
- In the game, get the token with
WSG.player.getToken(). In standalone mode the token isnull. - Send the token to your server in an
Authorization: Bearer <token>header. - The server verifies the RS256 signature with the public keys at
https://api.leonogames.com/.well-known/jwks.json(a JWKS, cached for 1 hour, picking the key by thekidin the header), then checks the claims.
| Claim | Meaning |
|---|---|
iss | The public origin of the API that issued the token |
sub | The player ID (a UUID), equal to WSG.player.id on the portal |
gid | The game ID (a UUID), not the slug |
sid | The play session ID (a UUID) |
guest | true for guest accounts |
iat | Issued at (Unix seconds) |
exp | Expires at = iat + 3600 |
The token header has alg: "RS256", typ: "JWT" and a kid. There is no aud claim.
- Always check
gidagainst your game's ID so you never accept a token issued for another game. Get the ID withcurl https://api.leonogames.com/api/v1/games/<slug>(theidfield) once the game is released. issis the public origin of the API. When the portal serves the API through the website's own origin (as the current staging environment does), it can differ fromhttps://api.leonogames.com; readissfrom a real token or ask the operations team before enabling anissuercheck.- Tokens live 1 hour from the start of the play session and are not reissued within the same session. When your server reports an expired token, ask the player to press Play again to get a new session and token.
// Node 20+, npm install jose
import { createRemoteJWKSet, jwtVerify } from 'jose';
const JWKS = createRemoteJWKSet(new URL('https://api.leonogames.com/.well-known/jwks.json'));
const GAME_ID = process.env.WSG_GAME_ID; // your game's id (UUID) on the portal
export async function verifyPlayer(token) {
// Checks the RS256 signature, exp and iat; throws if the token is invalid or expired
const { payload } = await jwtVerify(token, JWKS, { algorithms: ['RS256'] });
if (payload.gid !== GAME_ID) throw new Error('Token belongs to another game');
return { playerId: payload.sub, sessionId: payload.sid, guest: payload.guest === true };
}import { createServer } from 'node:http';
import { verifyPlayer } from './verify-token.mjs';
createServer(async (req, res) => {
// The game runs on the games origin, so the server must allow CORS from that origin
res.setHeader('Access-Control-Allow-Origin', 'https://games.leonogames.com');
res.setHeader('Access-Control-Allow-Headers', 'authorization, content-type');
if (req.method === 'OPTIONS') return res.writeHead(204).end();
try {
const token = (req.headers.authorization ?? '').replace(/^Bearer /, '');
const player = await verifyPlayer(token);
res.writeHead(200, { 'content-type': 'application/json' });
res.end(JSON.stringify({ playerId: player.playerId, guest: player.guest }));
} catch {
res.writeHead(401).end();
}
}).listen(8080);const token = await WSG.player.getToken();
if (token) {
const res = await fetch('https://api.your-studio.example/me', {
headers: { Authorization: `Bearer ${token}` },
});
console.log(await res.json());
}