Local and online scoreboards for browser games. A tested local board (top N, higher or lower is better, one entry per name, daily and weekly boards, blocked-storage safe), daily challenge seeds, score and time formatting, an online client, and a dependency-free Node leaderboard server with signed run tokens, plausibility checks, one best per player, rate limits, name cleaning and file storage; ...
Download skill (.zip) Files on GitHubLeaderboard system
Which board
| Need | Use |
|---|---|
| Best scores on this device | createLocalBoard (no server) |
| A board for the people in a Bash space | The sharing-results guide (a route writes it, with Bash names) |
| A global board for an itch.io or web game | leaderboard-server.mjs on a Node host, or Supabase (docs/services/supabase.md) |
| On a portal (Newgrounds, Game Jolt) | Their scoreboard API: bash-portal-achievements |
assets/leaderboard.js (browser)
import { createLocalBoard, periodKey, dailySeed, formatScore, formatTime, ordinal, createOnlineBoard } from "./leaderboard.js";
const board = createLocalBoard("my-game:scores", { size: 10, order: "desc" }); // "asc" for times and move counts
const { rank, isBest, madeBoard } = board.submit(name, score, { level });
const today = createLocalBoard(`my-game:day:${periodKey("day")}`); // new board each UTC day
const seed = dailySeed("my-game"); // same level for everyone today
assets/leaderboard-server.mjs (Node)
import { createLeaderboard } from "./leaderboard-server.mjs";
const lb = createLeaderboard({ file: "data/scores.json", secret: process.env.RUN_SECRET, maxPerSecond: 50, minSeconds: 5 });
http.createServer((req, res) => lb.handle(req, res, "/api/scores") || serveFiles(req, res));
Browser flow: const run = await online.start() when the run begins → play → online.submit({ ...run, name, score }).
| Check | Stops |
|---|---|
| Signed run token (HMAC, server secret) | Scores for runs that never started; edited tokens |
| One score per token | Replaying a good submission |
Run length ≥ minSeconds, score ≤ seconds × maxPerSecond |
Instant or impossible scores |
| Rate limit per IP | Spamming |
cleanName |
HTML, invisible characters, empty names |
That stops casual cheating. A determined cheater can still play a real run with a modified game; for prizes, verify replays
on the server (game-replay-system’s verifyReplay).
RUN_SECRET: a long random value set on the server host, never in the repo or the page.
UI
- Game over: score, “New best!”, rank (“4th today”), board with the player’s row highlighted, and their row shown below the top 10 when they’re further down.
- Name: ask once, remember it, allow changing. In Bash, use the viewer’s Bash name (bash-js-sdk) when signed in.
- Tabs: Today / This week / All time. Daily boards keep new players motivated.
- Offline or server down: keep the local board, say “Couldn’t reach the online board”, retry later.
Tested
Node: local ranks, board size, ascending boards, one-per-name, UTC day and ISO week keys, daily seed, formatting, blocked storage. Server with real HTTP (11 checks): too-short runs refused, valid score ranked, token reuse refused, impossible score refused, forged token refused, one best per player, names cleaned, daily board, rate limiting, saving and reloading.
Run it: node assets/tests/server-test.mjs.
Pitfalls
Writing the board from the browser (anyone can rewrite it), local time for daily boards (use UTC), no ties rule (earlier wins here), and showing a global board with nobody on it (show the local board until there are entries).