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
20 lines
879 B
JavaScript
20 lines
879 B
JavaScript
'use strict';
|
|
const { GameError } = require('../errors');
|
|
const { ownedTown } = require('./build');
|
|
|
|
const STRIP = new RegExp('[\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2066-\\u2069\\ufeff]', 'g');
|
|
|
|
// Display-name hygiene: no control or bidi characters, collapsed whitespace, 2..24 characters.
|
|
function cleanName(v) {
|
|
const s = Array.from(String(v).replace(STRIP, '').replace(/\s+/g, ' ').trim()).slice(0, 24).join('').trim();
|
|
return s;
|
|
}
|
|
|
|
module.exports = function renameTown(ctx, { userId, townId, name }) {
|
|
const town = ownedTown(ctx.db, userId, townId);
|
|
const clean = cleanName(name);
|
|
if (clean.length < 2) throw new GameError('validation_failed', { errors: [{ path: 'name', message: 'too short' }] });
|
|
ctx.db.run('UPDATE towns SET name = ? WHERE id = ?', clean, town.id);
|
|
return { name: clean };
|
|
};
|
|
module.exports.cleanName = cleanName;
|