Stage 0-2 server spine: db, scheduler, REST, auth, economy, map
Built: SQLite (node:sqlite) via server/db.js with checksummed migrations, injectable clock, persistent event scheduler with catch-up, tiny REST router (error envelope, idempotency keys, rate limits, bearer tokens with scrypt passwords), lazy-resource economy in public/js/rules.js + data.js, build/cancel/rename commands, seeded map + spawn ring, generated docs/openapi.json. NETWALL net.js/static.js reused. Tested: manual smoke run only (signup, town view, build, map). No unit tests or e2e yet. NOT done: military, expansion, social, client, push, deploy docs, bots/admin. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
9fa76d53a8
commit
b56b13880e
39 changed files with 4450 additions and 0 deletions
22
server/commands/cancelBuild.js
Normal file
22
server/commands/cancelBuild.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
'use strict';
|
||||
/* DELETE /towns/:id/queue/:eventId. Cancels a running build and refunds 80% (rounded down). */
|
||||
const D = require('../../public/js/data.js');
|
||||
const { GameError } = require('../errors');
|
||||
const { settle } = require('../state');
|
||||
const { ownedTown } = require('./build');
|
||||
|
||||
const REFUND = 0.8;
|
||||
|
||||
module.exports = function cancelBuild(ctx, { userId, townId, eventId }) {
|
||||
const { db, now } = ctx;
|
||||
const town = ownedTown(db, userId, townId);
|
||||
const ev = db.get("SELECT id, payload FROM events WHERE id = ? AND town_id = ? AND type = 'buildDone' AND status = 'pending'", eventId, town.id);
|
||||
if (!ev) throw new GameError('not_found', { what: 'queue entry' });
|
||||
settle(db, town, now);
|
||||
const cost = JSON.parse(ev.payload).cost || {};
|
||||
const cap = require('../../public/js/rules.js').storageCap(town);
|
||||
for (const r of D.RESOURCES) town.res[r] = Math.min(Math.max(cap, town.res[r]), town.res[r] + Math.floor((cost[r] || 0) * REFUND));
|
||||
db.run('UPDATE towns SET fiber = ?, hardware = ?, capital = ? WHERE id = ?', town.res.fiber, town.res.hardware, town.res.capital, town.id);
|
||||
db.run("UPDATE events SET status = 'cancelled', done_at = ? WHERE id = ?", now, ev.id);
|
||||
return { cancelled: ev.id };
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue