Phase 2: client military/social screens, WebSocket push, trade + endgame, review findings pending

Built: units/movements/reports/send/expansion screens, alliance/messages/rankings screens, ws client + server /ws push
(docs/PROTOCOL.md), Internet exchange trade, backbone endgame + world end, shared reports, buildDone relative levels.
Tested: npm test 175/175. Two adversarial reviews found issues (trade-leg recall exploit, __proto__ via validate.js,
rankings DoS, static headers, ...): fixes follow in the next commit.
NOT done: bots/balance, e2e suite, real-device checks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
jvanvik 2026-10-11 19:05:03 +02:00
parent 249818a7aa
commit b18645dca1
87 changed files with 10201 additions and 71 deletions

View file

@ -40,19 +40,35 @@ const handlers = {
messageDelete: require('./messageDelete'),
messageBlock: require('./messageBlock').messageBlock,
messageUnblock: require('./messageBlock').messageUnblock,
// trade, end game, shared reports
reportShare: require('./reportShare').reportShare,
reportUnshare: require('./reportShare').reportUnshare,
tradeOffer: require('./tradeOffer'),
tradeCancel: require('./tradeCancel'),
tradeAccept: require('./tradeAccept'),
backboneBuild: require('./backboneBuild'),
backboneShip: require('./backboneShip'),
};
function createCommands({ db, clock, scheduler }) {
// hooks.onCommand(name, args, out): optional, called after a command committed (stage 6 push). Never throws into the caller.
const hooks = { onCommand: null };
function run(name, args) {
const fn = handlers[name];
if (!fn) throw new Error('unknown command ' + name);
scheduler.runDue();
require('../endgame').guard(db, name, args); // an ended world refuses every command except reading state and chatting
const now = clock.now();
const out = db.tx(() => fn({ db, clock, now, scheduler }, args));
const mark = scheduler.outboxMark();
let out;
try { out = db.tx(() => fn({ db, clock, now, scheduler }, args)); }
catch (err) { scheduler.outboxRollback(mark); throw err; }
scheduler.flushOutbox(); // notifications written by the command go out now that it is committed
if (hooks.onCommand) { try { hooks.onCommand(name, args, out); } catch (e) { if (scheduler.log) scheduler.log('onCommand hook failed: ' + e.message); } }
scheduler.arm();
return out;
}
return { run, handlers };
return { run, handlers, hooks };
}
module.exports = { createCommands };