feat(server): staff tools, player-made items, picture safety, chat, multiplayer games

Staff and moderation
- Invisible staff (!invisible, "xiv"): hidden from players, half see-through
  to other staff, cannot chat while hidden. New permission staff.invisible.
- Summon and goto land on the player's exact spot ("xgt" before the move).
- Custom warnings (!warn PLAYER custom TEXT), shown in the warning popup.
- Mod notes (!note, !notes; lib/modnotes.js), on the player page and the
  dashboard.
- Granular permissions: per-role overrides (setting rolePermissions) and
  per-account grants and denies, applied live to staff who are playing
  (refreshStaff re-sends "xsp").
- Item control (lib/itemcontrol.js): lock items out of the item finder
  (!lock, !unlock, !locked), take an item from a player (!take), delete a
  custom item from the game and every inventory.
- GET items/find: search any item by name or id, marked locked, for the
  dashboards' quick lock.

Player-made items (lib/playeritems.js, "xcm")
- The Item Maker: make, rename, set the worn look, delete. 5 a day, 20 in all;
  names go through the name filter.
- Admin switches: Item Maker on/off, new items wait for approval, and a
  separate switch (on by default) that holds every player-uploaded picture
  for a moderator. Review queue for items.approve (moderator and up).
- Pictures (lib/itemart.js): PNG, JPEG and GIF cleaned of metadata, BMP
  converted to PNG; 512px and 300KB at most once cleaned.
- Worn as the maker chooses: a sticker (the picture) or a texture (the
  item's shape painted with the picture).

Picture safety
- A picture waiting for approval is never served publicly: /itemart/ 404s it,
  and it is only shown through /account|/mod|/admin/api/itemart to its maker
  and to staff who review or make items.
- A picture turned away or taken off is remembered by SHA-256 and cannot be
  uploaded again.
- Three strikes: three pictures turned away stops a player's uploads until a
  moderator lets them again. Staff can stop or allow uploads by hand.
- Accounts under 24 hours old cannot upload pictures (AJ_ITEM_ART_MIN_HOURS);
  uploads capped at 10 a day.
- Optional Google Cloud Vision SafeSearch (lib/image-moderation.js) for item
  pictures and Art Studio paintings when AJ_GOOGLE_VISION_API_KEY is set;
  fails closed when the scanner is unreachable.

Chat
- Emoji: Twemoji pictures served at /emoji/<codepoints>.png and cached in
  data/emoji (lib/emoji.js).
- Smart spam filtering before the word filter (lib/chatspam.js): long runs of
  one character, repeated words and lines, huge words and emoji floods are
  tidied, and repeats within 20 seconds are dropped.
- Typing indicator: "xty" is passed on to everyone in the room who can see
  the player, at most every 2 seconds.

Games (lib/minigames.js)
- Room games can be played together: a MULTIPLAYER table gives a game a
  waiting list (Single Player / Multiplayer). Players in the same room are
  matched, taken into the game together, and each one's moves are relayed to
  the others. Gem Breaker is the first: two players, "pos", "shoot" and
  "playerLost" relayed.
- Gem Breaker's start message now lists each player's id. Without it no
  player counted as local, so even single player could not aim.

Other
- Players stay connected through the client's new 75-minute AFK limit
  (idleTimeoutMs 80 minutes).
- Jam-a-Grams carry custom items and colours; Jammer Wall avatar photos are
  validated (walls.js photoParam).
- Weak passwords refused (common words, or containing the username).
- Code-scanning fixes: every logged value goes through logText
  (lib/logtext.js) against log injection, HSTS, path-only error logs, a
  single file read in lib/names.js.

Tests: items (pictures, approval, strikes, re-upload refusal, the hidden
waiting picture, the dashboard search), staff (invisibility, goto and summon
spots, custom warnings, notes), buddygames (two-player Gem Breaker, the
typing relay), and updates for main's verified badge and spawn rooms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
SnipzilandClaude Opus 5.5 committed 2026-10-17 21:44:10 -04:00
1 parent da7eb9af58
commit e05565787f
50 files changed
+2904 -277

No files matched your search

+87 -16
View File
@@ -1,5 +1,6 @@
"use strict";
const {logText} = require("./logtext.js");
const crypto = require("crypto");
const fs = require("fs");
const path = require("path");
@@ -18,6 +19,7 @@ const log = require("./log.js");
const masterpieces = require("./masterpieces.js");
const modlog = require("./modlog.js");
const modpanel = require("./modpanel.js");
const playerItems = require("./playeritems.js");
const erase = require("./erase.js");
const reports = require("./reports.js");
const roles = require("./roles.js");
@@ -89,7 +91,7 @@ const passwordAcceptable = password =>
const load = () => {
if (!hasPassword()) {
setupCode = crypto.randomBytes(5).toString("hex");
console.log(`[admin] no admin password yet: open ${config.baseUrl}admin to choose one`
console.log(`[admin] no admin password yet: open ${logText(config.baseUrl)}admin to choose one`
+ ` (from another machine it will ask for this setup code: ${setupCode})`);
}
};
@@ -154,6 +156,10 @@ const accountRow = (account, playing) => {
banReason: ban === 0 ? "" : account.banReason || bans.NO_REASON,
moderator: Boolean(roles.roleOf(account)),
role: roles.roleOf(account),
// what they may do (their role's, with their own grants and denies)
permissions: roles.permissionsOf(account),
permGrants: account.permGrants || [],
permDenies: account.permDenies || [],
nameRejected: Boolean(account.nameRejected),
silenced: world.moderation.isSilenced(account),
animals: account.avatars.length,
@@ -378,8 +384,10 @@ const act = (account, body) => {
const name = account.username;
switch (body.action) {
case "password": {
if (accounts.setPassword(account, body.password)) {
return {error: "Passwords need 10 characters or more, with a capital letter, a small letter and a digit."};
const passwordProblem = accounts.setPassword(account, body.password);
if (passwordProblem) {
return {error: passwordProblem === "weak_password" ? "That password is too easy to guess: it is a common one, or has your username in it."
: "Passwords need 10 characters or more, with a capital letter, a small letter and a digit."};
}
actions.kick(account);
manage.forget(account); // their account page too, whoever has it open
@@ -523,12 +531,26 @@ const act = (account, body) => {
modpanel.forget(account);
}
accounts.save();
world.refreshStaff(account);
if (role === null) {
return {ok: `${name} has no staff role.`};
}
const label = roles.ROLES[role].label.toLowerCase();
return {ok: `${name} is now ${/^[aeiou]/.test(label) ? "an" : "a"} ${label}.${totp.isOn(account) ? "" : " They have no 2FA yet, so their role does nothing until they turn it on."}`};
}
// one staff member's own permissions, beyond their role's or taken from
// it ({grants: [...], denies: [...]}).
case "permissions": {
if (!roles.roleOf(account)) {
return {error: `${name} has no staff role: give them one first.`};
}
roles.setAccountPermissions(account, body.grants, body.denies);
accounts.save();
world.refreshStaff(account);
modlog.record("admin", "permissions changed", account.username,
`+${(account.permGrants || []).join(",") || "none"} -${(account.permDenies || []).join(",") || "none"}`);
return {ok: `${name}'s permissions are saved.`};
}
case "rejectName":
actions.rejectName(account, BY);
manage.forget(account);
@@ -633,7 +655,7 @@ const handle = async (req, res, url, from, web) => {
}
storePassword(body.password);
setupCode = null;
console.log(`[admin] admin password chosen from ${from.address}`);
console.log(`[admin] admin password chosen from ${logText(from.address)}`);
signIn(res);
reply(200, {ok: true});
return;
@@ -646,11 +668,11 @@ const handle = async (req, res, url, from, web) => {
}
if (!hasPassword() || !passwordMatches(body.password)) {
recordFailure(from.key);
console.log(`[admin] failed sign-in from ${from.address}`);
console.log(`[admin] failed sign-in from ${logText(from.address)}`);
reply(401, {error: "Wrong password."});
return;
}
console.log(`[admin] signed in from ${from.address}`);
console.log(`[admin] signed in from ${logText(from.address)}`);
signIn(res);
reply(200, {ok: true});
return;
@@ -667,6 +689,39 @@ const handle = async (req, res, url, from, web) => {
return;
}
// what players made that waits (the moderator panel's Review), and the
// admin's switches for the Item Maker: {enabled, approval}.
if (url.pathname === "/admin/api/review" || url.pathname === "/admin/api/item-switches") {
const done = (result, action, target = "", detail = "") => {
if (result.ok) {
modlog.record("admin", action, target, result.detail || detail);
}
reply(result.ok ? 200 : 400, result.ok ? {ok: result.ok} : {error: result.error});
};
if (route === "POST /admin/api/item-switches") {
const flag = value => (value === undefined ? undefined : value === true);
playerItems.setSwitches({enabled: flag(body.enabled), approval: flag(body.approval), artApproval: flag(body.artApproval)});
const pictures = playerItems.pictureWaits() ? "pictures wait for a moderator" : "pictures are shown at once";
done({ok: `The Item Maker is ${playerItems.enabled() ? "on" : "off"}; new items ${playerItems.approvalOn() ? "wait for a moderator first" : "are in the game at once"}; ${pictures}.`},
"item maker settings", "", `${playerItems.enabled() ? "on" : "off"}, approval ${playerItems.approvalOn() ? "on" : "off"}, pictures ${playerItems.pictureWaits() ? "wait" : "at once"}`);
return;
}
modpanel.reviewRoutes(route.replace(" /admin/api/", " "), body, reply, done, "admin", "/admin/api/itemart");
return;
}
// custom items (lib/customitems.js): the moderator panel's pages, the
// admin written down as "admin", and free to take from anyone.
if (url.pathname.startsWith("/admin/api/items")) {
const done = (result, action, target = "", detail = "") => {
if (result.ok) {
modlog.record("admin", action, target, result.detail || detail);
}
reply(result.ok ? 200 : 400, result.ok ? {ok: result.ok} : {error: result.error});
};
modpanel.itemRoutes(route.replace(" /admin/api/", " "), url, body, reply, done, {username: "admin", artBase: "/admin/api/itemart", mayTake: () => true});
return;
}
switch (route) {
case "GET /admin/api/overview":
reply(200, overview());
@@ -741,7 +796,7 @@ const handle = async (req, res, url, from, web) => {
}
const result = act(account, body);
if (result.ok) {
console.log(`[admin] ${body.action} on "${account.username}"`);
console.log(`[admin] ${logText(body.action)} on "${logText(account.username)}"`);
// in the record beside the moderators', for the player's timeline.
if (!["password", "lastSeen", "level"].includes(body.action)) {
modlog.record(BY, body.action, account.username, result.detail || "");
@@ -765,7 +820,7 @@ const handle = async (req, res, url, from, web) => {
case "POST /admin/api/device": {
const result = staff.unbanDevices(body.id, BY);
if (result.ok) {
console.log(`[admin] device ban ${Number(body.id)} lifted`);
console.log(`[admin] device ban ${logText(Number(body.id))} lifted`);
modlog.record(BY, "hardware ban lifted", result.username || "");
}
reply(result.ok ? 200 : 400, result);
@@ -796,9 +851,25 @@ const handle = async (req, res, url, from, web) => {
// who may use the moderator panel, and what each did there.
// the staff roles and what each may do.
case "GET /admin/api/roles":
reply(200, {roles: Object.entries(roles.ROLES).map(([id, role]) => ({id, label: role.label, rank: role.rank, permissions: role.permissions})),
permissions: roles.PERMISSIONS});
reply(200, {roles: Object.entries(roles.ROLES).map(([id, role]) => ({id, label: role.label, rank: role.rank, permissions: roles.rolePermissions(id),
defaults: role.permissions, changed: roles.roleChanged(id)})), permissions: roles.PERMISSIONS});
return;
// a role's permissions changed ({role, permissions: [...]}), or back to
// its defaults ({role, reset: true}). its staff who are playing are told.
case "POST /admin/api/roles": {
const role = String(body.role || "");
if (!roles.setRolePermissions(role, body.reset === true ? null : Array.isArray(body.permissions) ? body.permissions : [])) {
reply(400, {error: "No such role."});
return;
}
for (const player of accounts.all().filter(account => roles.roleOf(account) === role)) {
world.refreshStaff(player);
}
console.log(`[admin] permissions of the ${logText(role)} role ${logText(body.reset === true ? "reset" : "changed")}`);
modlog.record("admin", body.reset === true ? "role permissions reset" : "role permissions changed", "", `${role}: ${roles.rolePermissions(role).join(", ")}`);
reply(200, {ok: `${roles.ROLES[role].label}: ${body.reset === true ? "back to its defaults" : "saved"}.`});
return;
}
case "GET /admin/api/moderators":
reply(200, {moderators: modpanel.moderators(), log: modlog.recent()});
return;
@@ -812,7 +883,7 @@ const handle = async (req, res, url, from, web) => {
case "POST /admin/api/address": {
const result = addressAct(body);
if (result.ok) {
console.log(`[admin] address ${body.action}: ${limits.key(body.address)}`);
console.log(`[admin] address ${logText(body.action)}: ${logText(limits.key(body.address))}`);
}
reply(result.ok ? 200 : 400, result);
return;
@@ -829,7 +900,7 @@ const handle = async (req, res, url, from, web) => {
case "POST /admin/api/debug": {
const result = debugAct(body);
if (result.ok) {
console.log(`[admin] debug: ${body.action} ${body.action === "teleport" ? `${body.username} -> ${body.room}` : body.on === true}`);
console.log(`[admin] debug: ${logText(body.action)} ${logText(body.action === "teleport" ? `${body.username} -> ${body.room}` : body.on === true)}`);
}
reply(result.ok ? 200 : 400, result);
return;
@@ -850,7 +921,7 @@ const handle = async (req, res, url, from, web) => {
return;
}
const reached = world.announce(text, body.room ? String(body.room) : null);
console.log(`[admin] announcement to ${body.room ? `room ${body.room}` : "everyone"} (${reached} players)`);
console.log(`[admin] announcement to ${logText(body.room ? `room ${body.room}` : "everyone")} (${logText(reached)} players)`);
reply(200, {ok: reached === 1 ? "Shown to 1 player." : `Shown to ${reached} players.`});
return;
}
@@ -895,7 +966,7 @@ const handle = async (req, res, url, from, web) => {
result = {error: "Unknown action."};
}
if (result.ok) {
console.log(`[admin] masterpiece ${body.action} ${id || body.on === true}`);
console.log(`[admin] masterpiece ${logText(body.action)} ${logText(id || body.on === true)}`);
}
reply(result.ok ? 200 : 400, result);
return;
@@ -937,7 +1008,7 @@ const handle = async (req, res, url, from, web) => {
result = {error: "Unknown action."};
}
if (result.ok) {
console.log(`[admin] support: ${body.action} ${Number(body.id)}`);
console.log(`[admin] support: ${logText(body.action)} ${logText(Number(body.id))}`);
}
reply(result.ok ? 200 : 400, result);
return;
@@ -965,4 +1036,4 @@ const handle = async (req, res, url, from, web) => {
}
};
module.exports = {load, handle, PASSWORD_SETTING};
module.exports = {load, handle, signedIn, PASSWORD_SETTING};