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

@ -77,7 +77,7 @@
}
// ------------------------------------------------------------------ screen
let box, canvas, view, coordsEl, legendEl, ready = false, visible = false, pendingFocus = 'own';
let box, canvas, view, coordsEl, legendEl, ready = false, visible = false, pendingFocus = 'own', offMoveTick = null;
const store = new Store();
let infoSheet = null;
@ -113,6 +113,8 @@
forEachSpecial: (a, b, c, d, fn) => store.forEachSpecial(a, b, c, d, fn),
townsInRect: (a, b, c, d) => store.townsInRect(a, b, c, d),
isOwn: (t) => t.owner.id === ownOperatorId(),
movements: () => moveLines(),
threatened: (t) => App.mil.moves.incoming.some((m) => m.to && m.to.townId === t.id),
};
view = new MapRender.MapView(canvas, source, {
onTap: onTap,
@ -128,6 +130,21 @@
drawLegend();
}
// Lines for the movements of the shared cache (App.mil.moves): yours, incoming and allied ones, with progress at draw time.
function moveLines() {
const mv = App.mil && App.mil.moves;
if (!mv) return [];
const now = App.now(), out = [];
const add = (m, kind) => {
if (!m.from || !m.to || m.from.x === undefined || m.to.x === undefined) return;
out.push({ from: m.from, to: m.to, kind, p: (now - m.departAt) / Math.max(1, m.arriveAt - m.departAt) });
};
for (const m of mv.outgoing) add(m, m.type === 'return' ? 'ret' : 'out');
for (const m of mv.incoming) add(m, 'in');
for (const m of mv.alliedIncoming || []) add(m, 'ally');
return out;
}
function drawLegend() {
UI.clear(legendEl);
const item = (cls, text) => h('li', null, h('span', { class: 'lg ' + cls }), text);
@ -135,6 +152,8 @@
legendEl.appendChild(item('rival', App.t('map.legend.rival')));
legendEl.appendChild(item('rural', App.t('map.legend.rural')));
legendEl.appendChild(item('incumbent', App.t('map.legend.incumbent')));
legendEl.appendChild(item('mv-out', App.t('map.legend.out')));
legendEl.appendChild(item('mv-in', App.t('map.legend.in')));
}
// ------------------------------------------------------------------ tile info
@ -174,6 +193,9 @@
body.push(h('p', { class: 'detail-desc', text: App.t('map.info.land') }));
}
body.push(row('', App.t('map.info.coords', { x, y })));
if (App.openSend && App.state.towns.length && (town || (special && special.type === 'incumbent') || (!special && known))) {
body.push(h('button', { class: 'btn wide' + (town && town.owner.id === ownOperatorId() ? '' : ' primary'), type: 'button', onclick: () => App.openSend({ x, y }) }, icon('target'), App.t('send.open')));
}
if (cap && !(town && town.id === cap.id)) body.push(row('', App.t('map.info.distance', { d: App.fmt.dec(R.distance(cap.x, cap.y, x, y)) })));
if (town && town.owner.id === ownOperatorId() && App.state.towns.some((t) => t.id === town.id)) {
body.push(h('button', { class: 'btn primary wide', type: 'button', onclick: () => { closeSheet(); App.setTown(town.id); App.go('pop'); } }, icon('pop'), App.t('map.info.open')));
@ -192,10 +214,19 @@
render(container) {
box = container;
App.on('session', () => { store.reset(); pendingFocus = 'own'; });
App.on('movements', () => { if (visible && view) view.invalidate(); });
App.on('towns', () => { if (view) view.invalidate(); });
App.on('town', () => { const t = App.state.townData; if (t) store.patchTown(t.id, { name: t.name }); });
},
onShow(params) {
visible = true;
// marker positions move with the clock: redraw about once a second while any movement is on the wire
if (offMoveTick) offMoveTick();
let lastSec = 0;
offMoveTick = App.onTick((now) => {
const sec = Math.floor(now / 1000), mv = App.mil.moves;
if (sec !== lastSec && view && (mv.outgoing.length || mv.incoming.length || (mv.alliedIncoming || []).length)) { lastSec = sec; view.invalidate(); }
});
if (!App.state.world) { UI.clear(box); box.appendChild(h('p', { class: 'empty pad', text: App.t('map.noWorld') })); ready = false; return; }
setup();
view.setWorld(App.state.world.mapRadius);
@ -208,7 +239,7 @@
// the container was display:none until now: measure after layout
requestAnimationFrame(() => { if (view.resize()) apply(); else setTimeout(() => { view.resize(); apply(); }, 60); });
},
onHide() { visible = false; closeSheet(); },
onHide() { visible = false; if (offMoveTick) offMoveTick(); offMoveTick = null; closeSheet(); },
onLang() {
if (!ready) return;
canvas.setAttribute('aria-label', App.t('map.label'));