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
18
server/commands/signup.js
Normal file
18
server/commands/signup.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
/* Create account + operator + capital POP + first token in one transaction. The password hash and token hash are
|
||||
* computed by the route before the transaction (scrypt is async, a transaction never spans an await). */
|
||||
const { GameError } = require('../errors');
|
||||
const joinWorld = require('./joinWorld');
|
||||
|
||||
module.exports = function signup(ctx, { username, passHash, tokenHash, device, worldId }) {
|
||||
const { db, now } = ctx;
|
||||
if (db.get('SELECT 1 AS x FROM users WHERE username = ?', username)) throw new GameError('username_taken');
|
||||
const w = worldId !== undefined ? db.get("SELECT id FROM worlds WHERE id = ? AND status = 'running'", worldId)
|
||||
: db.get("SELECT id FROM worlds WHERE status = 'running' ORDER BY id LIMIT 1");
|
||||
if (!w) throw new GameError('not_found', { what: 'world' });
|
||||
const u = db.run('INSERT INTO users (username, pass_hash, created_at) VALUES (?, ?, ?)', username, passHash, now);
|
||||
const userId = Number(u.lastInsertRowid);
|
||||
const joined = joinWorld(ctx, { userId, worldId: w.id });
|
||||
const t = db.run('INSERT INTO tokens (user_id, token_hash, device, created_at, last_used_at) VALUES (?, ?, ?, ?, ?)', userId, tokenHash, device || '', now, now);
|
||||
return Object.assign({ userId, tokenId: Number(t.lastInsertRowid) }, joined);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue