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
22 lines
1.2 KiB
JavaScript
22 lines
1.2 KiB
JavaScript
'use strict';
|
|
/* A Backbone node level finished. Payload { siteId, toLevel, by }. Idempotent: only acts while the site's build points at THIS
|
|
* event. The level lands on the SITE (a capture during the build does not stop it); level maxLevel makes the holder alliance the
|
|
* winner (once per world) and schedules the end of the world. */
|
|
const D = require('../../public/js/data.js');
|
|
const { loadWorld } = require('../state');
|
|
const E = require('../endgame');
|
|
|
|
module.exports = function backboneDone(ctx, ev) {
|
|
const { db } = ctx;
|
|
const site = E.siteRow(db, ev.payload.siteId);
|
|
if (!site || site.build_event_id !== ev.id) return;
|
|
const world = loadWorld(db, site.world_id);
|
|
if (!world || world.status === 'ended') return;
|
|
const level = site.build_to;
|
|
db.run('UPDATE landing_sites SET level = ?, build_to = NULL, build_event_id = NULL, build_started_at = NULL, build_due_at = NULL, build_cost = NULL WHERE id = ?', level, site.id);
|
|
const fresh = E.siteRow(db, site.id);
|
|
if (fresh.holder_alliance_id && (level % D.ENDGAME.notifyEvery === 0 || level >= D.ENDGAME.maxLevel)) {
|
|
E.notifyAlliance(ctx, fresh.holder_alliance_id, 'backbone_level', { siteId: site.id, index: site.idx, level });
|
|
}
|
|
E.maybeWin(ctx, fresh, ev.dueAt);
|
|
};
|