Built: - Economy: raid loot capped to the room the raiders have at home (rest stays with the victim, "lootLeft" in the report); trade escrow reserves its room so refunds always fit; trade accept refuses with no_room_for_goods when the goods would not fit. Loot destroyed per 30-day run 31-61k -> ~1k, refunds clipped ~27k -> 0 (docs/BALANCE.md, 3 seeds). - End game: members of the holding alliance garrison landing sites (migration 005_site_garrison.sql), garrison counts in site defence, 72 h capture shield, withdraw route, POP view lists garrisoned units. Shipping capacity scales with world speed (3x world: winner 76-98 -> ~30-36 days after sites open). Bot runs show real contests (84-194 attacks on held sites at 1x). - Ops: deploy/update.sh (backup, stop, ff-merge, npm ci --ignore-scripts, health check, rollback), deploy/upstream-offsite (rsync only), admin end-world snapshots results, EPIPE fix, docs/workflows/ filled in. - e2e 62 -> 163 checks: units, raids/reports, alliance+messages, trade, end game, nb, PWA, reconnect, slow polling fallback (opt-in). Two app bugs found: message push ignored, "New" button stayed English. Tested: npm test 274/274, openapi check, npm run e2e 163/163 (137 s), bot runs 50x30d seeds 1-3 and 140-day/60-day speed-3 end-game runs INVARIANTS OK, adversarial review pass (findings fixed or documented). NOT tested: update.sh on a real box (systemd, real npm, runuser; stubs only, shellcheck not installed), garrison card/loot text on a phone, Node 22.13, humans. Known leaks left open and documented (BALANCE S6): loot/shipments can still overflow when stock arrives in flight, bounced backbone shipments lose overflow (reported to the sender). Garrison numbers (heldDefenceMult 2, shield 72 h) are first guesses from 2 seeds. Not claimed: balanced. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
53 lines
3.6 KiB
JavaScript
53 lines
3.6 KiB
JavaScript
'use strict';
|
|
/* Internet exchange: open offers, your offers, create / cancel / accept. Direct transports (to your own POPs or any player)
|
|
* are POST /movements with type "transport". */
|
|
const { reply } = require('../http');
|
|
const { createTradeQueries } = require('../tradeQueries');
|
|
const D = require('../../public/js/data.js');
|
|
|
|
const int1 = { type: 'integer', minimum: 1 };
|
|
const res = { type: 'string', enum: D.RESOURCES };
|
|
const page = { after: { type: 'integer', minimum: 0 }, limit: { type: 'integer', minimum: 1, maximum: 100 } };
|
|
|
|
function register(router, services) {
|
|
const { commands } = services;
|
|
const trade = createTradeQueries(services);
|
|
const errs = ['unauthorized', 'not_found', 'validation_failed'];
|
|
|
|
router.get('/trade/offers', {
|
|
summary: 'Open offers you can take: within the offer\'s max distance and the reach of one of your Internet exchanges (newest first, cursor: after = last id seen)', tag: 'trade',
|
|
query: { type: 'object', properties: Object.assign({ worldId: int1, townId: int1, give: res, want: res }, page) }, response: { $ref: 'TradeOfferList' }, errors: errs,
|
|
}, ({ user, query }) => trade.offers(user.id, query));
|
|
|
|
router.get('/trade/offers/mine', {
|
|
summary: 'Offers you posted or accepted, any status (newest first)', tag: 'trade',
|
|
query: { type: 'object', properties: Object.assign({ worldId: int1, status: { type: 'string', enum: ['open', 'accepted', 'completed', 'cancelled', 'expired', 'void'] } }, page) },
|
|
response: { $ref: 'TradeOfferList' }, errors: errs,
|
|
}, ({ user, query }) => trade.mineOffers(user.id, query));
|
|
|
|
router.get('/trade/offers/:id', {
|
|
summary: 'One offer (open ones to every operator of the world, closed ones to the two parties)', tag: 'trade', response: { $ref: 'TradeOfferResponse' }, errors: errs,
|
|
}, ({ user, params }) => trade.offer(user.id, params.id));
|
|
|
|
router.post('/trade/offers', {
|
|
summary: 'Post an offer from one of your POPs: give X of A for Y of B within a max distance. The offered amount is escrowed and a transport link reserved',
|
|
tag: 'trade', status: 201,
|
|
body: {
|
|
type: 'object', required: ['townId', 'giveRes', 'giveAmount', 'wantRes', 'wantAmount', 'maxDistance'],
|
|
properties: { townId: int1, giveRes: res, giveAmount: int1, wantRes: res, wantAmount: int1, maxDistance: { type: 'integer', minimum: 1, maximum: D.TRADE.maxDistance } },
|
|
},
|
|
response: { $ref: 'TradeOfferResponse' }, errors: errs.concat(['trade_ratio', 'capacity_exceeded', 'no_transport_link', 'not_enough_resources', 'world_ended']),
|
|
}, ({ user, body }) => reply(201, commands.run('tradeOffer', Object.assign({ userId: user.id }, body))));
|
|
|
|
router.del('/trade/offers/:id', {
|
|
summary: 'Cancel your open offer; the escrow returns to the POP', tag: 'trade', response: { $ref: 'TradeCancelled' }, errors: errs.concat(['offer_closed', 'world_ended']),
|
|
}, ({ user, params }) => commands.run('tradeCancel', { userId: user.id, offerId: params.id }));
|
|
|
|
router.post('/trade/offers/:id/accept', {
|
|
summary: 'Take an open offer with one of your POPs: two transports leave at once (your payment, their goods) and the offer is settled when both arrive', tag: 'trade', status: 201,
|
|
body: { type: 'object', required: ['townId'], properties: { townId: int1 } },
|
|
response: { $ref: 'TradeAccepted' },
|
|
errors: errs.concat(['offer_closed', 'own_offer', 'trade_out_of_range', 'no_room_for_goods', 'no_transport_link', 'capacity_exceeded', 'not_enough_resources', 'world_ended']),
|
|
}, ({ user, params, body }) => reply(201, commands.run('tradeAccept', { userId: user.id, offerId: params.id, townId: body.townId })));
|
|
}
|
|
module.exports = { register };
|