/** * What a relay will accept. Policy, not contract. * * The submission *shape* is `@ludus/schema`'s and is the same everywhere. These * limits are this relay's opinion, and a self-hoster is entitled to a different * one — which is the point of the service being ~400 lines and self-hostable. * * Every value here is a CHEAP defence. Read `SIGNATURE_PROVES` in * `@ludus/schema` before adding an expensive one: a local-first client computes * its own score, so it can lie, and a defence that implies otherwise is worse * than no defence at all (CLAUDE.md §6.3). */ export interface RelayConfig { /** * Hard ceiling on the XP one participant may hold in one week. * * Submissions above it are CLAMPED, not rejected. Rejecting would punish an * honest heavy user with a lost week; clamping bounds what a dishonest one * gains, which is all a ceiling can do. * * The number is derived from the session contract rather than picked: six to * eight items a day (`SESSION_MIN_ITEMS`/`SESSION_MAX_ITEMS`) at roughly 20 XP * an item is ~160 XP on a full day, ~1 120 in a week. 5 000 leaves room for * bonuses, catch-up days and a scoring change, and still makes "I earned * 400 000 XP this week" impossible to submit. */ readonly xpCeiling: number; /** * Longest display name stored, in UTF-16 code units. * * A relay serves this string back to every other participant in the league. * It is untrusted text from an anonymous device, so it is bounded here and * refused — not truncated — above the bound: truncating changes the bytes that * were signed, and the row would then disagree with its own signature. */ readonly displayNameMaxChars: number; /** Longest league id accepted. Ids are chosen by whoever runs the league. */ readonly leagueIdMaxChars: number; /** * Largest request body read, in bytes. * * A submission is a few hundred bytes. The cap exists so an unauthenticated * POST cannot make the process buffer a gigabyte; the connection is closed as * soon as the limit is passed rather than after the body finishes arriving. */ readonly maxBodyBytes: number; /** * Most rows one board read returns. * * A league is a cohort of ~30 by design — an empty-looking global board with * eleven people on it is worse than no board (CLAUDE.md §8). The cap is * generous rather than exact so that a self-hoster running larger cohorts is * not silently truncated at a number they never chose. */ readonly boardMaxRows: number; /** * Where the source of THIS running relay can be read, served by `GET /about`. * * The relay is published under CPAL-1.0 as LudusPublic, and CPAL §15 counts running it for other people as * distributing it: whoever runs it must make its source available to the people who use it. A relay is an * API with no screen, so the place its users can find that source is a response. The default is LudusPublic * itself; a self-hoster running a MODIFIED relay must point this at their own copy, because the obligation is * to publish the code that runs, not the code it was forked from. */ readonly sourceUrl: string; } export const DEFAULT_RELAY_CONFIG: RelayConfig = { xpCeiling: 5_000, displayNameMaxChars: 32, leagueIdMaxChars: 64, maxBodyBytes: 8 * 1024, boardMaxRows: 200, sourceUrl: 'https://gitea.marek-novak.cz/mnovak/LudusPublic' }; /** * The CPAL-1.0 Exhibit B credit, exactly as LudusPublic's LICENSE states it. * * Not configurable: the attribution belongs to the Original Developer and a relay may not drop it (CPAL §14). * Copied from the licence rather than paraphrased; `server.test.ts` checks the words. */ export const ATTRIBUTION = { phrase: 'Built on Domi', url: 'https://aula.marek-novak.cz', copyright: 'Copyright (c) 2026 Marek Novák', licence: 'CPAL-1.0' } as const; export function relayConfig(overrides: Partial = {}): RelayConfig { return { ...DEFAULT_RELAY_CONFIG, ...overrides }; }