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

18
server/ratelimit.js Normal file
View File

@@ -0,0 +1,18 @@
/* Tiny in-memory rate limiter (per IP + route group). Enough for one server; resets on restart. */
'use strict';
function rateLimit({ windowMs = 60000, max = 10, name = 'rl' } = {}) {
const hits = new Map(); // key -> { n, reset }
const sweep = setInterval(() => { const now = Date.now(); for (const [k, v] of hits) if (v.reset < now) hits.delete(k); }, windowMs);
if (sweep.unref) sweep.unref();
return (req, res, next) => {
const key = name + ':' + (req.ip || req.socket.remoteAddress);
const now = Date.now();
let h = hits.get(key);
if (!h || h.reset < now) { h = { n: 0, reset: now + windowMs }; hits.set(key, h); }
if (++h.n > max) { res.set('Retry-After', String(Math.ceil((h.reset - now) / 1000))); return res.status(429).json({ error: 'RATE_LIMIT' }); }
next();
};
}
module.exports = { rateLimit };