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
|
|
@ -18,7 +18,7 @@ const TYPES = ['scan', 'raid', 'attack', 'takeover', 'reinforce', 'settle'];
|
|||
const HOSTILE = ['raid', 'attack', 'takeover'];
|
||||
|
||||
// The target of a movement: a POP (by id or by tile) or a bare tile. -> { town: row|null, x, y, tile }
|
||||
function resolveTarget(db, world, args) {
|
||||
function resolveTarget(db, world, args, now) {
|
||||
let town = null, x, y;
|
||||
if (args.toTownId !== undefined && args.toTownId !== null) {
|
||||
town = db.get('SELECT * FROM towns WHERE id = ? AND world_id = ?', args.toTownId, world.id);
|
||||
|
|
@ -30,7 +30,7 @@ function resolveTarget(db, world, args) {
|
|||
} else {
|
||||
throw new GameError('validation_failed', { errors: [{ path: 'toTownId', message: 'give toTownId or x and y' }] });
|
||||
}
|
||||
const tile = R.tileAt(world.seed, world.map_radius, x, y);
|
||||
const tile = R.tileAt(world.seed, world.map_radius, x, y, R.worldAgeDays(world.start_at, now, world.speed));
|
||||
if (tile.type === 'void') throw new GameError('invalid_target', { reason: 'outside_map' });
|
||||
return { town, x, y, tile };
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ module.exports = function sendMovement(ctx0, args) {
|
|||
for (const k of Object.keys(units)) if ((home[k] || 0) < units[k]) throw new GameError('not_enough_units', { unit: k, have: home[k] || 0, want: units[k] });
|
||||
if (!P.online(from, now)) throw new GameError('units_offline', { townId: from.id });
|
||||
|
||||
const tgt = resolveTarget(db, world, args);
|
||||
const tgt = resolveTarget(db, world, args, now);
|
||||
if (tgt.town && tgt.town.id === from.id) throw new GameError('invalid_target', { reason: 'same_town' });
|
||||
const dist = R.distance(from.x, from.y, tgt.x, tgt.y);
|
||||
const arriveAt = now + R.movementMs(dist, units, world.speed);
|
||||
|
|
@ -81,6 +81,10 @@ module.exports = function sendMovement(ctx0, args) {
|
|||
}
|
||||
} else if (tgt.tile.type === 'incumbent') {
|
||||
if (type !== 'scan' && type !== 'attack') throw new GameError('invalid_target', { reason: 'incumbent_scan_or_attack_only' });
|
||||
} else if (tgt.tile.type === 'backbone') {
|
||||
require('../endgame').checkLandingTarget(db, world, op, tgt, type, now, ctx); // scan or attack only, alliance members, no pact partners
|
||||
} else if (R.isBackboneSite(world.seed, world.map_radius, tgt.x, tgt.y)) {
|
||||
throw new GameError('backbone_closed', { opensAtDay: D.ENDGAME.openDay }); // the landing site is not there yet
|
||||
} else {
|
||||
throw new GameError('invalid_target', { reason: 'nothing_there' });
|
||||
}
|
||||
|
|
@ -98,7 +102,7 @@ module.exports = function sendMovement(ctx0, args) {
|
|||
const own = U.operatorTowns(db, op.id);
|
||||
let nearest = Infinity;
|
||||
for (const t of own) nearest = Math.min(nearest, R.distance(t.x, t.y, tgt.x, tgt.y));
|
||||
const chk2 = R.settleCheck({ tileType: tgt.tile.type, occupied: !!tgt.town, nearestOwnDist: nearest, ownedCount: own.length, footprint: U.operatorFootprint(db, op.id, now) });
|
||||
const chk2 = R.settleCheck({ tileType: tgt.tile.type, backbone: R.isBackboneSite(world.seed, world.map_radius, tgt.x, tgt.y), occupied: !!tgt.town, nearestOwnDist: nearest, ownedCount: own.length, footprint: U.operatorFootprint(db, op.id, now) });
|
||||
if (!chk2.ok) throw new GameError(chk2.code, chk2);
|
||||
extra.wild = R.cleanWild(args.wild);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue