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
15
server/events/buildDone.js
Normal file
15
server/events/buildDone.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
/* A building level finished. Payload: { key, type, toLevel, userId }. Idempotent: a level never goes down. */
|
||||
const { loadTown, settle } = require('../state');
|
||||
|
||||
module.exports = function buildDone(ctx, ev) {
|
||||
const { db } = ctx;
|
||||
const { key, type, toLevel, userId } = ev.payload;
|
||||
const town = loadTown(db, ev.townId);
|
||||
if (!town) return;
|
||||
settle(db, town, ev.dueAt); // values up to the moment of completion, at the OLD rates
|
||||
const cur = town.buildings[key];
|
||||
if (!cur) db.run('INSERT INTO buildings (town_id, key, type, level) VALUES (?, ?, ?, ?)', town.id, key, type, toLevel);
|
||||
else if (cur.level < toLevel) db.run('UPDATE buildings SET level = ? WHERE town_id = ? AND key = ?', toLevel, town.id, key);
|
||||
if (userId) ctx.notify(userId, ev.worldId, 'build_done', { townId: town.id, key, type, level: toLevel });
|
||||
};
|
||||
5
server/events/index.js
Normal file
5
server/events/index.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
/* Event type -> handler. One file per event type. */
|
||||
module.exports = {
|
||||
buildDone: require('./buildDone'),
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue