Custom items made while the server runs, and a Developer role

Staff with the new items.create permission (admins, and the new Developer
role) make clothing and den items from the game's own art: an existing
item under a new id (50000 on), name, price, members-only flag and choice
of its colours. No restart of the server or of anyone's game:

- lib/customitems.js keeps them (custom_items table) and puts them into
  the server's tables and the packs new games fetch (defpacks.setCustomItem)
- games already playing get the def rows in "xdi"; so does every game at
  login. The client adds them (ItemXtCommManager.addItemDefs,
  DenXtCommManager.addDenItemDefs, both now in swf-src; rebuild with
  tools/build-client.sh)
- they are sold first in the two shops of oddities and found by the item
  finder; an item can be renamed, repriced, recoloured and taken off sale,
  never deleted (players may own it)
- the moderator panel has an Items page; in game, "!item clothing|den ID
  NAME" and "!item list"
- the Developer role holds only staff.list and items.create. The panel's
  pages that show players (players, chat, reports, requests, bans,
  paintings) now need player.view, which helpers and up have

test/items.js covers it end to end, including a restart (withServer can
keep its database for that).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
SnipzilandClaude Opus 5.5 committed 2026-10-16 22:43:27 -04:00
1 parent 2fba9f1612
commit 6563d5de99
18 files changed
+3853 -23

No files matched your search

+62
View File
@@ -8,6 +8,8 @@ const bans = require("./bans.js");
const captcha = require("./captcha.js");
const chatlog = require("./chatlog.js");
const config = require("../config.js");
const customItems = require("./customitems.js");
const defpacks = require("./defpacks.js");
const limits = require("./limits.js");
const manage = require("./manage.js");
const masterpieces = require("./masterpieces.js");
@@ -376,7 +378,25 @@ const handle = async (req, res, url, from, web) => {
case "GET /mod/api/me":
reply(200, {username: mod.username, role: roles.roleOf(mod), permissions: roles.permissionsOf(mod)});
return;
}
// custom items (lib/customitems.js), for whoever may make them.
if (url.pathname.startsWith("/mod/api/items")) {
if (!roles.can(mod, "items.create")) {
reply(403, {error: "Your role does not allow that."});
return;
}
itemRoutes(route, url, body, reply, done, mod);
return;
}
// everything else shows players and what they did: not for a role that
// only makes things.
if (!roles.can(mod, "player.view")) {
reply(403, {error: "Your role does not allow that."});
return;
}
switch (route) {
case "GET /mod/api/overview":
reply(200, {online: world.players().length, reports: reports.openCount(), requests: support.nameRequests(false).length + bans.openAppeals(),
paintings: masterpieces.list(masterpieces.PENDING).length});
@@ -511,6 +531,48 @@ const handle = async (req, res, url, from, web) => {
}
};
// GET /mod/api/items: the custom items, the newest first.
// GET /mod/api/items/base?kind=clothing|den&id=N: an item of the game's to
// make one from (its name and colours), to check before making it.
// POST /mod/api/items {action: "create", kind, base, name, cost, members, colors}
// or {action: "update", kind, id, and any of name, cost, members, colors, inShop}.
const itemRoutes = (route, url, body, reply, done, mod) => {
switch (route) {
case "GET /mod/api/items":
reply(200, {items: customItems.list().map(entry => ({...entry, baseName: customItems.baseName(entry)})), firstId: customItems.FIRST_ID});
return;
case "GET /mod/api/items/base": {
const kind = url.searchParams.get("kind") === "den" ? "den" : "clothing";
const id = Number(url.searchParams.get("id"));
const def = kind === "den" ? defpacks.denItemDef(id) : defpacks.itemDef(id);
if (!def || id >= customItems.FIRST_ID || (kind === "clothing" && def.type !== "1")) {
reply(404, {error: `No ${kind === "den" ? "den item" : "clothing"} with that id.`});
return;
}
reply(200, kind === "den"
? {kind, id, name: defpacks.string(def.nameStrId) || def.abbrName, art: def.abbrName, cost: Number(def.cost)}
: {kind, id, name: defpacks.string(def.titleStrId), art: Number(def.layerDefId), cost: Number(def.value), colors: String(def.colors).split(",").map(Number)});
return;
}
case "POST /mod/api/items": {
const kind = String(body.kind || "");
const result = body.action === "update"
? customItems.update(kind, body.id, body)
: body.action === "create" ? customItems.create(kind, body, mod.username) : {error: "Unknown action."};
if (result.error) {
done(result);
return;
}
const {item} = result;
done({ok: `${item.name} (${item.kind === "den" ? "den item" : "clothing"} ${item.id}) ${body.action === "update" ? "changed" : "made"}.`},
body.action === "update" ? "item changed" : "item made", "", `${item.kind} ${item.id} ${item.name}`);
return;
}
default:
reply(404, {error: "not_found"});
}
};
const moderators = () => accounts.all().filter(account => roles.roleOf(account))
.map(account => ({username: account.username, role: roles.roleOf(account), twoStep: totp.isOn(account), lastSeen: account.lastSeen || null}))
.sort((a, b) => a.username.localeCompare(b.username));