Upstream/server/commands/tradeCancel.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

15 lines
732 B
JavaScript

'use strict';
/* DELETE /trade/offers/:id: take your open offer back; the escrow returns to the POP. */
const { GameError } = require('../errors');
const ctxOf = require('../military/ctx');
const T = require('../trade');
module.exports = function tradeCancel(ctx0, { userId, offerId }) {
const ctx = ctxOf(ctx0);
const { db, now } = ctx;
const o = T.getOffer(db, offerId);
if (!o || T.userOfOperator(db, o.operator_id) !== userId) throw new GameError('not_found', { what: 'offer' });
if (o.status !== 'open') throw new GameError('offer_closed', { status: o.status });
T.closeOffer(ctx, o, 'cancelled', now);
return { offerId: o.id, status: 'cancelled', returned: { resource: o.give_res, amount: o.give_amount } };
};