feat: free-play choice + per-game dual leaderboard (backend)

Free-to-play alongside paid, with scores split per game between a Pleb board
(free) and the Hall of Champions (paid). Keys on the existing per-game
game_mode, so no new game columns.

- Leaderboard API: GET /api/leaderboard?board=pleb|champions|all. champions =
  game_mode IN (PAID_SINGLE,PAID_CREDITS), pleb = FREE. board is whitelisted.
  Migration 019 adds a supporting partial index.
- FREE_PLAY_ENABLED config: offer free play as an explicit choice even when the
  instance also sells credits/entry (always on when payments are off).
- play_free socket event -> handleAutoStart(socket, {free:true}); skips all
  payment/credits/payout-address gating and records the game as game_mode=FREE
  via processGameStart(..., {forceFree:true}) -> _processGameStartFree (no
  payment, no payout, counted).
- getPaymentOptionsForUser exposes a play_free option; /api/game-modes exposes
  freePlayEnabled.

Adds freePlay.test.js. Full backend suite: 22 suites / 158 tests.
This commit is contained in:
jwinterm
2026-05-31 15:01:01 -04:00
parent 7581ba79cb
commit 0a1766ee2a
5 changed files with 154 additions and 13 deletions
@@ -0,0 +1,8 @@
-- Migration 019: Index for the per-game leaderboard split (Pleb vs Hall of Champions)
--
-- The leaderboard is split by game_mode: free games -> Pleb board, paid (credits/entry)
-- games -> Hall of Champions. This composite index supports both filtered queries
-- (score-ranked, restricted to ranked games).
CREATE INDEX IF NOT EXISTS idx_games_leaderboard
ON games (game_mode, score DESC)
WHERE status IN ('won', 'lost') AND score > 0;