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
35
server/sharedReports.js
Normal file
35
server/sharedReports.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
'use strict';
|
||||
/* Read model of the alliance's shared report folder. Newest first, `after` = id of the last report you have (older ones
|
||||
* follow), like GET /reports. Members with `viewSharedReports` only. */
|
||||
const { GameError } = require('./errors');
|
||||
const A = require('./alliances');
|
||||
|
||||
const j = (s) => JSON.parse(s || '{}');
|
||||
|
||||
function createSharedReportQueries({ db, clock, scheduler }) {
|
||||
const fresh = () => { scheduler.runDue(); return clock.now(); };
|
||||
|
||||
function list(userId, allianceId, { after, limit }) {
|
||||
const now = fresh();
|
||||
A.requireRole(db, userId, allianceId, 'viewSharedReports');
|
||||
const n = limit || 25;
|
||||
const rows = db.all(`SELECT r.id, r.type, r.created_at, r.summary, s.created_at AS shared_at, s.shared_by, o.name AS shared_name
|
||||
FROM report_shares s JOIN reports r ON r.id = s.report_id JOIN operators o ON o.id = s.shared_by
|
||||
WHERE s.alliance_id = ? ${after ? 'AND r.id < ?' : ''} ORDER BY r.id DESC LIMIT ?`, ...(after ? [allianceId, after, n + 1] : [allianceId, n + 1]));
|
||||
const items = rows.slice(0, n).map((r) => ({ id: r.id, type: r.type, createdAt: r.created_at, sharedAt: r.shared_at, sharedBy: { operatorId: r.shared_by, name: r.shared_name }, summary: j(r.summary) }));
|
||||
return { serverTime: now, items, next: rows.length > n ? items[items.length - 1].id : null };
|
||||
}
|
||||
|
||||
function get(userId, allianceId, reportId) {
|
||||
const now = fresh();
|
||||
A.requireRole(db, userId, allianceId, 'viewSharedReports');
|
||||
const r = db.get(`SELECT r.*, s.created_at AS shared_at, s.shared_by, o.name AS shared_name FROM report_shares s JOIN reports r ON r.id = s.report_id JOIN operators o ON o.id = s.shared_by
|
||||
WHERE s.alliance_id = ? AND r.id = ?`, allianceId, reportId);
|
||||
if (!r) throw new GameError('not_found', { what: 'shared report' });
|
||||
return { serverTime: now, report: { id: r.id, type: r.type, createdAt: r.created_at, expiresAt: r.expires_at, sharedAt: r.shared_at, sharedBy: { operatorId: r.shared_by, name: r.shared_name }, summary: j(r.summary), data: j(r.data) } };
|
||||
}
|
||||
|
||||
return { list, get };
|
||||
}
|
||||
|
||||
module.exports = { createSharedReportQueries };
|
||||
Loading…
Add table
Add a link
Reference in a new issue