feat(server)!: websocket lobby, server-run matches, server economy, new schema (P1-2, P1-4, P2-1, P2-1b, P2-5)

Replaces the Firebase-style /db facade (rtdb, rules, nodes tree) with explicit REST endpoints and a
WebSocket hub. Login by name or optional e-mail, seed accounts via npm run db:reset.

BREAKING CHANGE: old clients (lobby/netfight over /db) no longer work against this server; database is new.
This commit is contained in:
Benjamin Oezcan
2026-11-19 01:52:30 +01:00
parent 46499e354b
commit dca1032ac4
20 changed files with 908 additions and 322 deletions

View File

@@ -0,0 +1,33 @@
/* Reset the database to a clean state: backup copy, fresh schema, seed accounts.
Test system only (see CLAUDE.md). Stop the server first (systemctl stop robotclash), then:
npm run db:reset (in server/)
DB_FILE from the environment, default server/data.sqlite. */
'use strict';
const fs = require('fs');
const path = require('path');
// Dev phase: fixed test accounts (plan T-1: move to .env before there is ever a production system).
const DEV_SEED_USERS = [
{ name: 'michi', pass: 'Michi2000!', role: 'admin' },
{ name: 'benni', pass: 'Benni2000!', role: 'admin' },
];
const file = process.env.DB_FILE || path.join(__dirname, '..', 'data.sqlite');
if (file !== ':memory:' && fs.existsSync(file)) {
const bak = `${file}.bak-${new Date().toISOString().replace(/[:.]/g, '-')}`;
fs.copyFileSync(file, bak);
for (const ext of ['', '-wal', '-shm']) if (fs.existsSync(file + ext)) fs.rmSync(file + ext);
console.log('backup:', bak);
}
process.env.DB_FILE = file;
process.env.JWT_SECRET = process.env.JWT_SECRET || 'reset-script-signs-nothing';
const { createUser } = require('../auth'); // opens + migrates the fresh database
const economy = require('../economy');
for (const u of DEV_SEED_USERS) {
const row = createUser({ name: u.name, pass: u.pass, role: u.role });
economy.load(row.uid); // creates the starter online save
console.log(`seeded ${u.name} (${u.role})`);
}
console.log('database reset:', file);