feat(net)!: client on server-run fights, websocket lobby, server economy (P1-5, P1-6, P1-7, P2-3, P2-4)

- net.js: REST + one WebSocket with reconnect; single-flight refresh shared across tabs; ?slot=N
- lobby.js / netfight.js: server owns presence, challenges and the fight; client shows snapshots
- game.js: every workshop change goes through RC.Eco via act() (server-checked online);
  results, rewards and achievements come from the server (match.end)
- ranking/live/cloudsave on the new REST endpoints; online tournament removed until P2-6

BREAKING CHANGE: needs the new server (protocol v1); old online saves are not migrated.
This commit is contained in:
Benjamin Oezcan
2026-11-19 02:09:07 +01:00
parent 4bd85f68bf
commit 85a19ba242
13 changed files with 494 additions and 798 deletions

View File

@@ -1,4 +1,4 @@
/* Robot Clash - live settings from the backend (Firebase node /live).
/* Robot Clash - live settings from the own server (GET /api/live, admin writes PUT /api/admin/live).
The pure part has no DOM and no network, so the tests can run it in Node.
RC.Live.parse(data, now, build) -> {
@@ -8,7 +8,7 @@
needsReload, // this copy is older than build.min
locked(kind, id), // true when the admin has not released this part/arena/class yet
}
RC.Live.load(net, onChange) reads /live once, then keeps listening, and remembers the last
RC.Live.load(net, onChange) reads /api/live, polls it every minute, and remembers the last
answer in localStorage so the game still works offline.
Everything is best effort: no config, broken JSON or no network simply means "nothing special
@@ -74,10 +74,11 @@
const fire = data => { if (data) remember(data); onChange(parse(data, Date.now(), build)); };
fire(cached()); // show something immediately
if (!net || !net.enabled) return { close() {} };
net.db.get('live').then(d => { if (d) fire(d); }, () => {});
let sub = null;
try { sub = net.db.stream('live', d => { if (d) fire(d); }); } catch (e) { sub = null; }
return { close() { if (sub) sub.close(); } };
// the admin changes these rarely: read now, then poll every minute
const pull = () => net.api('GET', '/api/live').then(d => { if (d) fire(d); }, () => {});
pull();
const timer = setInterval(pull, 60000);
return { close() { clearInterval(timer); } };
}
RC.Live = { parse, load, KEY };