Upstream/server/routes/world.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

41 lines
2.7 KiB
JavaScript

'use strict';
/* End game: the race (world status), the final results, landing sites (read, feed the stockpile, build the node). Taking a site is
* POST /movements (scan / attack at its x,y). */
const { reply } = require('../http');
const { createEndgameQueries } = require('../endgameQueries');
const D = require('../../public/js/data.js');
function register(router, services) {
const { commands } = services;
const eg = createEndgameQueries(services);
const errs = ['unauthorized', 'not_found', 'validation_failed'];
router.get('/worlds/:id/status', {
summary: 'The state of the world: phase (running, backbone_open, ended), world age, the landing sites with holder, node level, stockpile and build progress, the winner', tag: 'world',
response: { $ref: 'WorldStatus' }, errors: errs,
}, ({ user, params }) => eg.status(user.id, params.id));
router.get('/worlds/:id/results', {
summary: 'The final ranking snapshot (operators, alliances, attackers, defenders, winner); available once the world has ended', tag: 'world',
response: { $ref: 'WorldResults' }, errors: errs,
}, ({ user, params }) => eg.results(user.id, params.id));
router.get('/backbone/:id', {
summary: 'One landing site; members of the holding alliance also see the contribution ledger and what they may do', tag: 'world',
response: { $ref: 'LandingSiteResponse' }, errors: errs,
}, ({ user, params }) => eg.site(user.id, params.id));
router.post('/backbone/:id/ship', {
summary: 'Send resources from one of your POPs to a landing site your alliance holds (a transport: Internet exchange links, 500 each)', tag: 'world', status: 201,
body: { type: 'object', required: ['fromTownId', 'cargo'], properties: { fromTownId: { type: 'integer', minimum: 1 }, cargo: { type: 'object', additionalProperties: true, description: 'fiber/hardware/capital -> amount' } } },
response: { $ref: 'MovementSent' },
errors: errs.concat(['forbidden', 'backbone_closed', 'capacity_exceeded', 'no_transport_link', 'not_enough_resources', 'world_ended']),
}, ({ user, params, body }) => reply(201, commands.run('backboneShip', { userId: user.id, siteId: params.id, fromTownId: body.fromTownId, cargo: body.cargo })));
router.post('/backbone/:id/build', {
summary: 'Start the next Backbone node level on a landing site your alliance holds (paid from the site\'s stockpile; one level at a time, up to level ' + D.ENDGAME.maxLevel + ')', tag: 'world', status: 201,
response: { $ref: 'BackboneBuildStarted' },
errors: errs.concat(['forbidden', 'backbone_closed', 'max_level', 'already_queued', 'not_enough_resources', 'world_ended']),
}, ({ user, params }) => reply(201, commands.run('backboneBuild', { userId: user.id, siteId: params.id })));
}
module.exports = { register };