56 lines
2.1 KiB
JavaScript
56 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
|
// Local patch: make the minimum length for newly created character names
|
|
// configurable.
|
|
//
|
|
// Upstream's is_name_allowed() rejects names shorter than 4 characters, while
|
|
// is_name_xallowed() already accepts 1-12 for rename, chat and login. Three
|
|
// character names are therefore fully supported; the 4-character gate only
|
|
// applies to character creation and makes them a paid rename target (24,000
|
|
// shells). This patch reads options.character_name_min_length (default 4) so a
|
|
// local server can allow 3-character names at creation without changing the
|
|
// rename rules or prices.
|
|
//
|
|
// The patch is idempotent and fails loudly if the anchor is gone.
|
|
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
|
|
const app = path.resolve(process.argv[2] || "/app");
|
|
const file = path.join(app, "api.js");
|
|
let source = fs.readFileSync(file, "utf8");
|
|
|
|
const oldLine = "\tif (name.length < 4) return false;";
|
|
const newLines = [
|
|
"\tvar min_length =",
|
|
'\t\ttypeof options === "undefined" || !options || options.character_name_min_length === undefined',
|
|
"\t\t\t? 4",
|
|
"\t\t\t: Number(options.character_name_min_length);",
|
|
"\tif (!Number.isSafeInteger(min_length) || min_length < 1 || min_length > 12) min_length = 4;",
|
|
"\tif (name.length < min_length) return false;",
|
|
].join("\n");
|
|
|
|
function fail(message) {
|
|
console.error("patch-character-name-length: " + message);
|
|
process.exit(1);
|
|
}
|
|
|
|
const marker = "options.character_name_min_length";
|
|
const oldCount = source.split(oldLine).length - 1;
|
|
const patchedCount = source.split("if (name.length < min_length) return false;").length - 1;
|
|
|
|
if (oldCount === 1 && patchedCount === 0) {
|
|
source = source.replace(oldLine, newLines);
|
|
fs.writeFileSync(file, source);
|
|
console.log("patch-character-name-length: patched " + file);
|
|
} else if (oldCount === 0 && patchedCount === 1 && source.includes(marker)) {
|
|
console.log("patch-character-name-length: already patched");
|
|
} else {
|
|
fail(
|
|
"expected 1 unpatched creation length check, found " +
|
|
oldCount +
|
|
" unpatched and " +
|
|
patchedCount +
|
|
" patched; refusing partial patch",
|
|
);
|
|
}
|