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
28 lines
925 B
JavaScript
28 lines
925 B
JavaScript
'use strict';
|
|
/*
|
|
* Player commands: one file each, validate + apply in one transaction. `run` first catches the event queue up to now
|
|
* (so a town is never touched with an overdue event pending), then runs the command in a transaction, then re-arms the
|
|
* scheduler timer because the command may have enqueued events.
|
|
*/
|
|
const handlers = {
|
|
signup: require('./signup'),
|
|
joinWorld: require('./joinWorld'),
|
|
build: require('./build'),
|
|
cancelBuild: require('./cancelBuild'),
|
|
renameTown: require('./renameTown'),
|
|
};
|
|
|
|
function createCommands({ db, clock, scheduler }) {
|
|
function run(name, args) {
|
|
const fn = handlers[name];
|
|
if (!fn) throw new Error('unknown command ' + name);
|
|
scheduler.runDue();
|
|
const now = clock.now();
|
|
const out = db.tx(() => fn({ db, clock, now, scheduler }, args));
|
|
scheduler.arm();
|
|
return out;
|
|
}
|
|
return { run, handlers };
|
|
}
|
|
|
|
module.exports = { createCommands };
|