Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

FEP 002: Lobby/Leaderboard Specification

FieldValue
FEP ID002
TitleGame Events and Leaderboard in Lobby
AuthorAndrew Diller
StatusDraft
TypeInformational
Created2025-05-09
Version1.0
InputEricC, RogerS

Abstract

This document defines a standard approach for enhancing the existing FujiNet lobby server service by introducing a persistent leaderboard system based on multiplayer game outcomes. The enhancement involves creating a new gameResult table within the service’s SQLite database to store detailed player performance data, including game identifiers, server information, player names, win status, and player type. A new HTML leaderboard page presents aggregated player statistics in two formats: a global ranking of players by total wins, and per-server listings of the top 10 winning players.

Architecture Overview

graph LR
    GS[Game Server] -->|POST gameResult| LS[Lobby Server]
    LS --> DB[(SQLite Database)]
    DB --> LB[Leaderboard HTML Page]
    LS -->|bounce payload| EVT[Event Address Hosts]

Lobby Logic

As Game Server (GS) events flow into the Lobby Server (LS), the server processes them with the following logic:

If gameResult exists in POST body:
    - Create a new UUID for this game
    - Loop over the array of players in the gameResult:
        - For each player, create a new row in the gameResult table:
            gameID, gameName, gameServer, playerName,
            playerWinner, playerType, datetime

Else:
    - Continue with normal processing
    - Bounce the entire payload to any evtaddr hosts specified
      when the server was instantiated

Database Schema

gameResult Table

ColumnTypeDescription
idINTEGERPrimary key, auto-increment
timedateDATETIMETimestamp of the game result
gameIDINTEGERUnique identifier for the game session
gameNameVARCHAR(80)Name of the game
gameServerVARCHAR(80)Name/identifier of the game server
playerNameVARCHAR(80)Name of the player
playerWinnerBOOLEANWhether this player won
playerTypeENUMhuman or bot

Queries

Top Players by Wins (All Games)

Returns a global ranking of all human players ordered by total wins:

SELECT playerName, COUNT(*) AS wins
FROM gameResult
WHERE playerWinner = 1 AND playerType = 'human'
GROUP BY playerName
ORDER BY wins DESC;

Top 10 Players Per Server

Returns the top winning human players grouped by game server:

SELECT gameServer, playerName, COUNT(*) AS wins
FROM gameResult
WHERE playerWinner = 1 AND playerType = 'human'
GROUP BY gameServer, playerName
HAVING wins > 0
ORDER BY gameServer, wins DESC;

SQLite Compatibility Note

For SQLite versions prior to 3.25 (which lack ROW_NUMBER() support), a correlated subquery can be used to limit results to the top 10 per server:

SELECT *
FROM (
  SELECT gameServer, playerName, COUNT(*) AS wins
  FROM gameResult
  WHERE playerWinner = 1 AND playerType = 'human'
  GROUP BY gameServer, playerName
)
WHERE (
  SELECT COUNT(*) FROM gameResult AS gr
  WHERE gr.playerWinner = 1 AND gr.playerType = 'human'
    AND gr.gameServer = gameResult.gameServer
    AND (
      SELECT COUNT(*) FROM gameResult
      WHERE playerWinner = 1 AND playerType = 'human'
        AND gameServer = gr.gameServer
        AND playerName = gr.playerName
    ) <= 10
);

Leaderboard Page

The leaderboard HTML page presents two views:

Global Rankings

A table of all human players ranked by total wins across all games and servers.

RankPlayer NameWins
1andyXEL42
2frank31

Per-Server Rankings

A table showing the top 10 human winners for each individual game server.

ServerPlayer NameWins
AI Room - 2 botsandyXEL25
AI Room - 2 botsfrank18

Data Flow

sequenceDiagram
    participant GS as Game Server
    participant LS as Lobby Server
    participant DB as SQLite DB
    participant Web as Leaderboard Page

    GS->>LS: POST with gameResult array
    LS->>LS: Generate UUID for game session
    loop For each player
        LS->>DB: INSERT into gameResult
    end
    Web->>DB: Query top players (global)
    DB->>Web: Ranked player list
    Web->>DB: Query top 10 per server
    DB->>Web: Per-server rankings

See Also