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:
parent
249818a7aa
commit
b18645dca1
87 changed files with 10201 additions and 71 deletions
|
|
@ -1,5 +1,8 @@
|
|||
'use strict';
|
||||
/* A building level finished. Payload: { key, type, toLevel, userId }. Idempotent: a level never goes down. */
|
||||
/* A building level finished. Payload: { key, type, toLevel, userId }. Each build event adds exactly ONE level to what the
|
||||
* building is at the moment it finishes (relative, not absolute): exploit kits may have knocked the building down while the
|
||||
* upgrade was in flight, and the finished level must not undo that. Never lowers a level; `toLevel` is the level the
|
||||
* upgrade was queued for and is only an upper bound. Events run once (status), so +1 is safe. */
|
||||
const { loadTown, settle } = require('../state');
|
||||
|
||||
module.exports = function buildDone(ctx, ev) {
|
||||
|
|
@ -9,8 +12,12 @@ module.exports = function buildDone(ctx, ev) {
|
|||
if (!town) return;
|
||||
settle(db, town, ev.dueAt); // values up to the moment of completion, at the OLD rates
|
||||
const cur = town.buildings[key];
|
||||
if (!cur) db.run('INSERT INTO buildings (town_id, key, type, level) VALUES (?, ?, ?, ?)', town.id, key, type, toLevel);
|
||||
else if (cur.level < toLevel) db.run('UPDATE buildings SET level = ? WHERE town_id = ? AND key = ?', toLevel, town.id, key);
|
||||
let level;
|
||||
if (!cur) { level = 1; db.run('INSERT INTO buildings (town_id, key, type, level) VALUES (?, ?, ?, ?)', town.id, key, type, level); }
|
||||
else {
|
||||
level = cur.level < toLevel ? cur.level + 1 : cur.level;
|
||||
if (level !== cur.level) db.run('UPDATE buildings SET level = ? WHERE town_id = ? AND key = ?', level, town.id, key);
|
||||
}
|
||||
require('../military/power').reschedule(ctx, town.id, ev.dueAt); // building draw / battery cap changed: units' power check
|
||||
if (userId) ctx.notify(userId, ev.worldId, 'build_done', { townId: town.id, key, type, level: toLevel });
|
||||
if (userId) ctx.notify(userId, ev.worldId, 'build_done', { townId: town.id, key, type, level });
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue