Upstream/server/routes/schemasMilitary.js
jvanvik b18645dca1 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
2026-10-11 19:05:03 +02:00

42 lines
3.6 KiB
JavaScript

'use strict';
/* Response schemas of the military stage (merged into routes/schemas.js). Documentation only, like the others. */
module.exports = function addMilitarySchemas(schemas, { int, num, str, bool, obj, arr }) {
const nint = { type: ['integer', 'null'] };
const free = { type: 'object', additionalProperties: true };
const Units = { type: 'object', additionalProperties: true, description: 'unit id -> count' };
const Cost = { $ref: 'Cost' };
Object.assign(schemas, {
Units,
TrainResult: obj({ serverTime: int, eventId: int, unit: str, count: int, building: str, startAt: int, dueAt: int, cost: Cost }),
ResearchResult: obj({ serverTime: int, eventId: int, unit: str, stat: str, toLevel: int, startedAt: int, dueAt: int, cost: Cost }),
MovementSent: obj({ serverTime: int, movementId: int, type: str, fromTownId: int, toTownId: nint, to: obj({ x: int, y: int }), units: Units, cargo: free, departAt: int, arriveAt: int, protectionEnded: bool }, ['serverTime', 'movementId', 'type', 'fromTownId', 'toTownId', 'departAt', 'arriveAt']),
RecallResult: obj({ serverTime: int, recalled: int, returnMovementId: int, arriveAt: int }),
WithdrawResult: obj({ serverTime: int, movementId: int, units: Units, arriveAt: int }),
MovementEnd: obj({ townId: nint, x: int, y: int, name: { type: ['string', 'null'] }, owner: { type: ['object', 'null'], additionalProperties: true } }, ['townId', 'x', 'y']),
Movement: obj({
id: int, type: str, status: str, ownerId: int, from: { $ref: 'MovementEnd' }, to: { $ref: 'MovementEnd' }, units: Units, cargo: free,
departAt: int, arriveAt: int, recallableUntil: nint, target: { type: ['string', 'null'] }, parentId: nint, incoming: bool,
}, ['id', 'type', 'status', 'from', 'to', 'departAt', 'arriveAt']),
MovementList: obj({ serverTime: int, outgoing: arr({ $ref: 'Movement' }), incoming: arr({ $ref: 'Movement' }), alliedIncoming: arr({ $ref: 'Movement' }) }, ['serverTime', 'outgoing', 'incoming']),
Marked: obj({ serverTime: int, marked: int }),
ReportItem: obj({ id: int, type: str, createdAt: int, role: str, read: bool, summary: free }),
ReportList: obj({ serverTime: int, items: arr({ $ref: 'ReportItem' }), next: nint, unread: int }),
Report: obj({ id: int, type: str, createdAt: int, expiresAt: int, role: str, read: bool, summary: free, data: free }),
ReportResponse: obj({ serverTime: int, report: { $ref: 'Report' } }),
TileInfo: obj({
serverTime: int, x: int, y: int, type: str, bonus: { type: ['string', 'null'] },
distances: arr(obj({ townId: int, distance: num })), town: free, incumbent: free,
settle: obj({ possible: bool, code: { type: ['string', 'null'] }, footprint: num, footprintNeeded: num, maxDistance: int }),
}, ['serverTime', 'x', 'y', 'type', 'distances', 'settle']),
TownMilitary: obj({
units: obj({ home: Units, online: bool, offlineSince: nint, stationedHere: arr(free), stationedAway: arr(free) }),
training: arr(obj({ id: int, unit: str, count: int, building: str, startAt: int, dueAt: int })),
trainable: arr(obj({ unit: str, building: str, role: str, cost: Cost, timeMs: int, missing: arr(free), locked: bool })),
research: obj({ levels: free, queue: { type: ['object', 'null'], additionalProperties: true }, speedBonus: num, maxLevel: int }),
transport: obj({ links: int, active: int, capacityPerLink: int }),
movements: obj({ outgoing: arr({ $ref: 'Movement' }), incoming: arr({ $ref: 'Movement' }) }),
protectionUntil: int,
}),
});
if (schemas.Town && schemas.Town.properties) schemas.Town.properties.military = { $ref: 'TownMilitary' }; // optional: not in `required`
};