Skip to content
Docs pages

Developers · Guides

Scores and leaderboards

The score submission flow, leaderboard periods, player XP, the anti-cheat rules in order, tips for choosing limits, and player authentication with JWT.

On this page

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

Sequence
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? }
JavaScript
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

PeriodScopeResets
dailyThe current day, as YYYY-MM-DDEvery day at 00:00 Vietnam time
weeklyThe current ISO week, starting Monday, as YYYY-WwwMondays at 00:00 Vietnam time
allAll timeNever
  • 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" in game.json flips the comparison: lower scores are better.
  • In your game, read the boards with top(), around(), me(), or open the portal's board with show() (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:

EventXP
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):

#Checkreason
1The play session exists, hasn't ended and belongs to the submitting playerinvalid_session
—The game's leaderboard is enabled on the portaldisabled
—The play session has been flagged as suspiciousblocked
2The score is an integer from 0 to 2^53invalid_score
3At most 1 submission per second per session and 30 per minute per playerrate_limited
4Gameplay is running, or gameplayStop() happened no more than 10 seconds agono_gameplay
5Score ≤ limits.maxScoreover_max
6Play time ≥ limits.minDurationMs; with scoreOrder: "asc", also the declared time check (see below)too_fast
7Score ÷ 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() to gameplayStop() added up, including the one still running, with a minimum of 1 second. Pauses between a gameplayStop() and the next gameplayStart() 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_rejected event with the reason and 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 gets blocked, 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

reasonCommon causeFix
invalid_sessionThe session has ended: the player left or reloaded, or the game kept running after the old session closedSubmit as soon as the round ends; nothing else to do in the game
invalid_scoreThe score has a fractional part, is negative, or is too largeMath.floor() and clamp the score before submitting
rate_limitedSeveral submissions within a second, or more than 30 per minuteSubmit only once per round
no_gameplaygameplayStart() 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_maxThe score is above maxScoreClamp the score in-game, or raise maxScore if the design allows it
too_fastThe round ended faster than minDurationMs; with asc, the declared time is shorter than the time the server measuredSet minDurationMs to the fastest possible run; with asc, submit the milliseconds measured in the game (see below)
rate_too_highScore divided by play time is above maxScorePerSecondRecompute using how to choose limits
blockedThe session was rejected 5 times within 10 minutesFix the root cause; the player needs a new session
disabledThe operations team turned off the leaderboard for this game in the admin pageNo 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:

  1. The player reaches 40 points after 30 seconds and dies. The game submits 40: 40 ÷ 30 = 1.3 points per second, accepted.
  2. 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 calls gameplayStart() again when play resumes.
  3. 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 blocked threshold (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() to gameplayStop() (or to the submission if gameplay is still running), by more than a max(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 maxScore so you never submit above it.
  • A minDurationMs below 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.
  • limits live in each version's game.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:

Bash
# 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.

  1. In the game, get the token with WSG.player.getToken(). In standalone mode the token is null.
  2. Send the token to your server in an Authorization: Bearer <token> header.
  3. 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 the kid in the header), then checks the claims.
ClaimMeaning
issThe public origin of the API that issued the token
subThe player ID (a UUID), equal to WSG.player.id on the portal
gidThe game ID (a UUID), not the slug
sidThe play session ID (a UUID)
guesttrue for guest accounts
iatIssued at (Unix seconds)
expExpires at = iat + 3600

The token header has alg: "RS256", typ: "JWT" and a kid. There is no aud claim.

  • Always check gid against your game's ID so you never accept a token issued for another game. Get the ID with curl https://api.leonogames.com/api/v1/games/<slug> (the id field) once the game is released.
  • iss is 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 from https://api.leonogames.com; read iss from a real token or ask the operations team before enabling an issuer check.
  • 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.
JavaScriptverify-token.mjs
// 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 };
}
JavaScriptserver.mjs
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);
JavaScriptIn the game
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());
}