Files
wikideck/server/game/config.ts
claudeanderic dbb89ce9c5 Night 2: 40-card Magic-style duel, PvP with owned decks, polite Wikimedia client, Android mining (#23)
Night 2 (2026-11-17), from the `claude/wikideck` fork's `night/2026-11-17` branch. It follows Night 1 (#22).

## What's in it
- **Duel engine** (fork #72, #80): 40-card decks of cards you own, Notability/Citations, keywords, effects T1–T12, Connected, a hidden-information-safe `viewFor`/`logFor`, and replay. Balance v1 tuning (#84) gives the first player about 51%.
- **Card profiles** (#70, #82): Figure, Location, Event, Institution or Doctrine, plus stats, keywords and rules text, all derived from real article data. Templates only.
- **Design and story** (#66, #69, #83): DUEL_DESIGN.md, plus the match log and the encyclopedic "Battle of X (2026)" recap.
- **PvP** (#74, #77, #81, #76, #85):
  - The server checks ownership, and 40-card eligibility is enforced.
  - Modes: Classic (ranked), Draft and Trending.
  - Invites, quick match, Elo, a ladder and recap pages. Online matches render on the duel board.
- **Duel board UI** (#79): MTG-style card faces and combat declaration, built for 360 px first.
- **Polite Wikimedia client** (#73, #75): throttled, cached and identified requests, the mint-path fix, and a prefetch pool.
- **Android mining** (#78): native RandomX, as a sideload build. The emulator mined a testnet block.
- **Testnet ops** (#67, #68).

PR numbers refer to `claude/wikideck`.

## Status
- **Tests:** 423, of which 422 pass, 0 fail and 1 is skipped. The build is OK (`node:24-alpine`, `--network none`).
- **Testnet:** running this commit (036489c) on r350.
- **Untouched:** no changes to `server/testnet/consensus.ts`, `randomx.ts`, `native/` or the mainnet compose.
- **Review:** night-review reviewed fork #66–#79. #80–#85 came from the agents' unfinished branches and were not reviewed.
- **Known gaps:**
  - The PvP end-to-end test hasn't been run (it needs two eom.dev accounts).
  - Bot matches aren't reachable from Play.
  - Card identity pre-bake hasn't been done.
  - The RandomX verifier latch (`server/testnet/randomx.ts:140`) is still open.

This PR is for Eric to merge.

🤖 Generated with [Claude Code](https://claude.com/claude-code)Reviewed-on: WikiDeck/wikideck#23

Co-authored-by: Claude <claude@eom.dev>
2026-11-18 18:12:24 +00:00

58 lines
3.3 KiB
TypeScript

/**
* Operator configuration for hosted modes. Everything comes from the operator's own
* environment and files; nothing here is learned from peers.
*
* WIKIDECK_MODES comma list of built-in mode ids and/or JSON file paths
* (default DEFAULT_MODES; "none" hosts nothing but still discovers)
* WIKIDECK_MODES_DIR optional directory: every *.json in it is a mode
* WIKIDECK_GAME_OPERATOR name shown as "Hosted by ..." (default: the origin's host name)
* WIKIDECK_GAME_NOTE optional short note shown with the host
* WIKIDECK_GAME_PEERS peer origins whose modes to list (default: WIKIDECK_PEERS)
* PUBLIC_ORIGIN this node's public origin (the host identity)
*/
import { readFileSync, readdirSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { HostIdentitySchema, MAX_MODES_PER_NODE, parseModeJson, type HostIdentity, type ModeDocument } from '../../shared/game/modes.ts';
import { parsePeerOrigins } from './discovery.ts';
export const BUILTIN_MODES_DIR = fileURLToPath(new URL('./modes/', import.meta.url));
/** Duel (Night 2): classic, draft, trending. Edit War (Night 1): edit-war, edit-war-draft, edit-war-trending. */
export const BUILTIN_MODE_IDS = ['classic', 'trending', 'draft', 'edit-war', 'edit-war-trending', 'edit-war-draft'] as const;
export const DEFAULT_MODES = 'classic,draft,trending,edit-war';
export function loadModes(env: NodeJS.ProcessEnv = process.env): ModeDocument[] {
const modes: ModeDocument[] = [];
const spec = (env.WIKIDECK_MODES ?? DEFAULT_MODES).trim();
if (spec !== 'none') for (const item of spec.split(',').map(s => s.trim()).filter(Boolean)) {
if ((BUILTIN_MODE_IDS as readonly string[]).includes(item)) modes.push(readMode(join(BUILTIN_MODES_DIR, `${item}.json`)));
else if (item.endsWith('.json')) modes.push(readMode(resolve(item)));
else throw new Error(`WIKIDECK_MODES: unknown built-in mode "${item.slice(0, 40)}" (use ${BUILTIN_MODE_IDS.join(', ')} or a .json path)`);
}
if (env.WIKIDECK_MODES_DIR) {
const dir = resolve(env.WIKIDECK_MODES_DIR);
for (const f of readdirSync(dir).filter(f => f.endsWith('.json')).sort()) modes.push(readMode(join(dir, f)));
}
if (modes.length > MAX_MODES_PER_NODE) throw new Error(`At most ${MAX_MODES_PER_NODE} modes per node`);
const ids = new Set<string>();
for (const m of modes) { if (ids.has(m.id)) throw new Error(`Duplicate mode id ${m.id}`); ids.add(m.id); }
return modes;
}
function readMode(path: string): ModeDocument {
try { return parseModeJson(readFileSync(path, 'utf8')); }
catch (e) { throw new Error(`Invalid mode file ${path}: ${(e as Error).message.slice(0, 300)}`); }
}
export function hostIdentity(env: NodeJS.ProcessEnv = process.env): HostIdentity {
const origin = new URL(env.PUBLIC_ORIGIN ?? `http://127.0.0.1:${env.PORT ?? 3001}`).origin;
return HostIdentitySchema.parse({ origin, operator: (env.WIKIDECK_GAME_OPERATOR ?? new URL(origin).host).slice(0, 48),
...(env.WIKIDECK_GAME_NOTE ? { note: env.WIKIDECK_GAME_NOTE.slice(0, 120) } : {}) });
}
export function gamePeers(env: NodeJS.ProcessEnv = process.env): string[] {
const self = hostIdentity(env).origin;
return parsePeerOrigins(env.WIKIDECK_GAME_PEERS ?? env.WIKIDECK_PEERS, env.WIKIDECK_ALLOW_PRIVATE_PEERS === '1')
.filter(o => o !== self);
}