mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
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]>
304 lines
12 KiB
JavaScript
304 lines
12 KiB
JavaScript
"use strict";
|
|
|
|
const accounts = require("./accounts.js");
|
|
const config = require("../config.js");
|
|
const customItems = require("./customitems.js");
|
|
const dens = require("./dens.js");
|
|
const itemControl = require("./itemcontrol.js");
|
|
const modlog = require("./modlog.js");
|
|
const names = require("./names.js");
|
|
const {addClothing, sendClothingAdded} = require("./player.js");
|
|
|
|
// items players make for themselves (the patched client's Item Maker, in the
|
|
// settings menu): one of the game's clothing pieces or den items under a
|
|
// name of their own, as staff make them (lib/customitems.js), but free, never
|
|
// in a shop, and in the item finder for its maker only. the maker is given
|
|
// one at once; it can be worn, placed and traded like any other. a maker
|
|
// may delete their own; staff may delete anyone's (the moderator panel).
|
|
//
|
|
// "xcm" from the client: ["info"], ["make", kind, baseId, name],
|
|
// ["rename", kind, id, name], ["look", kind, id, "sticker" | "texture"]
|
|
// (how one with a picture is worn) or ["delete", kind, id]. its picture is
|
|
// uploaded over HTTP (lib/itemart.js, POST /api/itemart). the answer is always "xcm" [ok 1 | 0, what to say,
|
|
// left today, left in all, the maker's items as JSON]
|
|
|
|
// the admin's two switches (the admin panel's Items page): whether players
|
|
// may make items at all, and whether what they make (an item, or a new
|
|
// picture for one) waits for a moderator first (items.approve: the
|
|
// moderator panel's Review page), out of the game till then.
|
|
const ENABLED_SETTING = "playerItems";
|
|
const APPROVAL_SETTING = "playerItemApproval";
|
|
const enabled = () => accounts.setting(ENABLED_SETTING) !== "off";
|
|
const approvalOn = () => accounts.setting(APPROVAL_SETTING) === "on";
|
|
// pictures are seen by everyone who meets the item, so a player's waits for
|
|
// a moderator even when items do not: unless the admin turns this off too.
|
|
const ART_APPROVAL_SETTING = "playerArtApproval";
|
|
const artApprovalOn = () => accounts.setting(ART_APPROVAL_SETTING) !== "off";
|
|
const pictureWaits = () => approvalOn() || artApprovalOn();
|
|
const setSwitches = ({enabled: on, approval, artApproval}) => {
|
|
if (on !== undefined) {
|
|
accounts.setSetting(ENABLED_SETTING, on ? "on" : "off");
|
|
}
|
|
if (approval !== undefined) {
|
|
accounts.setSetting(APPROVAL_SETTING, approval ? "on" : "off");
|
|
}
|
|
if (artApproval !== undefined) {
|
|
accounts.setSetting(ART_APPROVAL_SETTING, artApproval ? "on" : "off");
|
|
}
|
|
};
|
|
|
|
// ---- what keeps pictures players upload decent
|
|
//
|
|
// - a picture turned away (or taken off by a moderator) is remembered by
|
|
// its SHA-256, and the same picture cannot be sent again;
|
|
// - each counts against its maker: at ART_STRIKES their uploads stop,
|
|
// till a moderator lets them again (account.artBlocked);
|
|
// - an account younger than config.itemArtMinAccountHours may not upload.
|
|
const ART_STRIKES = 3;
|
|
const REFUSED_SETTING = "refusedArt";
|
|
const MAX_REFUSED = 5000;
|
|
let refused = null; // Set of SHA-256 hex
|
|
|
|
const refusedSet = () => {
|
|
if (!refused) {
|
|
let saved = [];
|
|
try {
|
|
saved = JSON.parse(accounts.setting(REFUSED_SETTING) || "[]");
|
|
}
|
|
catch {
|
|
saved = [];
|
|
}
|
|
refused = new Set(Array.isArray(saved) ? saved.map(String) : []);
|
|
}
|
|
return refused;
|
|
};
|
|
const pictureRefused = hash => refusedSet().has(hash);
|
|
|
|
// {error} when `account` may not upload a picture now, else null. `local`:
|
|
// the request is from this machine (no wait for a new account).
|
|
const uploadRefusal = (account, local = false) => {
|
|
if (account.artBlocked) {
|
|
return {error: "A moderator has turned off picture uploads for your account."};
|
|
}
|
|
const hours = config.itemArtMinAccountHours;
|
|
if (!local && hours > 0 && Math.floor(Date.now() / 1000) - (account.createdAt || 0) < hours * 3600) {
|
|
return {error: `New accounts can add pictures after ${hours} hours. Try again later.`};
|
|
}
|
|
return null;
|
|
};
|
|
|
|
// stops or lets again one player's uploads; letting them again clears the
|
|
// pictures counted against them.
|
|
const setUploadsBlocked = (account, blocked) => {
|
|
account.artBlocked = Boolean(blocked);
|
|
if (!blocked) {
|
|
account.artRefusals = 0;
|
|
}
|
|
accounts.save(account);
|
|
return {ok: blocked ? `${account.username} can no longer upload pictures.` : `${account.username} can upload pictures again.`};
|
|
};
|
|
|
|
// a picture turned away or taken off: never again, and counted against its
|
|
// maker (not against staff, whose items have no maker). before it is removed.
|
|
// returns what to add to what the moderator is told.
|
|
const strike = entry => {
|
|
const hash = require("./itemart.js").digestOf(entry.kind, entry.id);
|
|
if (hash) {
|
|
const set = refusedSet();
|
|
set.add(hash);
|
|
const kept = [...set].slice(-MAX_REFUSED);
|
|
refused = new Set(kept);
|
|
accounts.setSetting(REFUSED_SETTING, JSON.stringify(kept));
|
|
}
|
|
const maker = entry.ownerId === null ? null : accounts.byId(entry.ownerId);
|
|
if (!maker) {
|
|
return "";
|
|
}
|
|
maker.artRefusals = (maker.artRefusals || 0) + 1;
|
|
if (maker.artRefusals >= ART_STRIKES && !maker.artBlocked) {
|
|
maker.artBlocked = true;
|
|
accounts.save(maker);
|
|
modlog.record("system", "picture uploads stopped", maker.username, `${maker.artRefusals} pictures turned away`);
|
|
return ` That is ${maker.artRefusals} for ${maker.username}: their picture uploads are stopped.`;
|
|
}
|
|
accounts.save(maker);
|
|
return ` ${maker.username} has had ${maker.artRefusals} of ${ART_STRIKES} pictures turned away.`;
|
|
};
|
|
|
|
// a moderator takes an item's picture off, shown or waiting (after a report).
|
|
const takePicture = (kind, id) => {
|
|
const entry = customItems.get(kind, id);
|
|
if (!entry || !entry.art) {
|
|
return {error: "That item has no picture of its own."};
|
|
}
|
|
const said = strike(entry);
|
|
const result = require("./itemart.js").remove(kind, entry.id);
|
|
return result.error ? result : {ok: `${result.ok}${said}`};
|
|
};
|
|
|
|
const PER_DAY = 5;
|
|
const IN_ALL = 20;
|
|
const DAY = 86400;
|
|
|
|
const RENAMES_PER_HOUR = 10;
|
|
|
|
const now = () => Math.floor(Date.now() / 1000);
|
|
const renames = require("./limits.js").limiter(RENAMES_PER_HOUR, 3600000); // per account: each is sent to every game
|
|
|
|
const madeBy = account => customItems.list().filter(entry => entry.ownerId === account.id);
|
|
|
|
const left = account => {
|
|
const mine = madeBy(account);
|
|
const today = mine.filter(entry => entry.createdAt > now() - DAY).length;
|
|
return {today: Math.max(0, Math.min(PER_DAY - today, IN_ALL - mine.length)), inAll: Math.max(0, IN_ALL - mine.length)};
|
|
};
|
|
|
|
// returns {ok} or {error}.
|
|
const make = (session, kind, baseId, name) => {
|
|
const {account} = session;
|
|
if (!enabled()) {
|
|
return {error: "The Item Maker is turned off on this server for now."};
|
|
}
|
|
if (!customItems.KINDS.includes(kind) || !/^\d+$/.test(String(baseId))) {
|
|
return {error: "Choose an item to make yours from."};
|
|
}
|
|
if (!customItems.copyable(kind, Number(baseId))) {
|
|
return {error: "That item cannot be made into one of your own. Choose another."};
|
|
}
|
|
const room = left(account);
|
|
if (room.inAll === 0) {
|
|
return {error: `You have made ${IN_ALL} items, as many as there can be. Delete one to make another.`};
|
|
}
|
|
if (room.today === 0) {
|
|
return {error: `You have made ${PER_DAY} items today. Try again tomorrow.`};
|
|
}
|
|
const clean = String(name || "").trim().replace(/\s+/g, " ");
|
|
if (clean && names.refused(clean)) {
|
|
return {error: "That name is not allowed."};
|
|
}
|
|
const waits = approvalOn();
|
|
const result = customItems.create(kind, {base: Number(baseId), name: clean, cost: 0, members: false, inShop: false}, account.username, account.id, waits);
|
|
if (result.error) {
|
|
return result;
|
|
}
|
|
const {item} = result;
|
|
if (waits) {
|
|
modlog.record(account.username, "item made by a player, waiting for approval", "", `${kind} ${item.id} ${item.name}`);
|
|
return {ok: `${item.name} is waiting for a moderator to approve it. It is yours as soon as they do.`};
|
|
}
|
|
giveTo(account, item, session);
|
|
modlog.record(account.username, "item made by a player", "", `${kind} ${item.id} ${item.name}`);
|
|
return {ok: `Made ${item.name}. It is in your ${kind === "den" ? "den items" : "clothing"} now.`};
|
|
};
|
|
|
|
// one of the item, to its maker: now in their game if `session` is it
|
|
const giveTo = (account, item, session) => {
|
|
if (item.kind === "den") {
|
|
if (dens.giveDenItem(account, item.id) && session) {
|
|
dens.sendDenItems(session);
|
|
}
|
|
}
|
|
else {
|
|
const given = addClothing(account, item.id, item.colors[0]);
|
|
accounts.save(account);
|
|
if (session) {
|
|
sendClothingAdded(session, given);
|
|
}
|
|
}
|
|
};
|
|
|
|
// a moderator's answer about what waits (lib/modpanel.js, lib/panel.js): an
|
|
// item let in is given to its maker; one turned away is deleted, or only
|
|
// its picture taken away. `world` finds whether its maker is playing, and
|
|
// tells games about items taken. returns {ok} or {error}.
|
|
const review = (kind, id, approve, by, world) => {
|
|
const entry = customItems.get(kind, id);
|
|
if (!entry || (!entry.pending && !entry.artPending)) {
|
|
return {error: "That is not waiting for approval."};
|
|
}
|
|
const maker = entry.ownerId === null ? null : accounts.byId(entry.ownerId);
|
|
const wasNew = entry.pending;
|
|
if (approve) {
|
|
customItems.approve(kind, entry.id);
|
|
if (wasNew && maker) {
|
|
giveTo(maker, entry, world.findOnline(maker.username));
|
|
}
|
|
return {ok: wasNew ? `${entry.name} is in the game, and ${maker ? maker.username : "its maker"} has one.` : `${entry.name}'s picture is shown now.`};
|
|
}
|
|
if (wasNew) {
|
|
itemControl.deleteCustom(kind, entry.id, world);
|
|
return {ok: `${entry.name} was turned away and deleted.`};
|
|
}
|
|
const said = strike(entry);
|
|
require("./itemart.js").remove(kind, entry.id);
|
|
return {ok: `${entry.name}'s new picture was turned away.${said}`};
|
|
};
|
|
|
|
// a new name for one of their own (every game is told: customItems.update).
|
|
const rename = (account, kind, id, name) => {
|
|
const entry = customItems.get(kind, id);
|
|
if (!entry || entry.ownerId !== account.id) {
|
|
return {error: "That is not one of your items."};
|
|
}
|
|
if (!renames.allow(account.id)) {
|
|
return {error: "Too many renames. Try again in an hour."};
|
|
}
|
|
const clean = String(name || "").trim().replace(/\s+/g, " ");
|
|
if (clean && names.refused(clean)) {
|
|
return {error: "That name is not allowed."};
|
|
}
|
|
const result = customItems.update(kind, entry.id, {name: clean});
|
|
return result.error ? result : {ok: `Renamed it ${result.item.name}.`};
|
|
};
|
|
|
|
// how one of their own is worn ("sticker" or "texture")
|
|
const setLook = (account, kind, id, mode) => {
|
|
const entry = customItems.get(kind, id);
|
|
if (!entry || entry.ownerId !== account.id) {
|
|
return {error: "That is not one of your items."};
|
|
}
|
|
const result = customItems.setArtMode(kind, entry.id, String(mode));
|
|
return result.error ? result : {ok: `${entry.name} is worn as ${mode === "texture" ? "its shape, with your picture in it" : "your picture"}.`};
|
|
};
|
|
|
|
const remove = (session, kind, id, world) => {
|
|
const entry = customItems.get(kind, id);
|
|
if (!entry || entry.ownerId !== session.account.id) {
|
|
return {error: "That is not one of your items."};
|
|
}
|
|
const result = itemControl.deleteCustom(kind, entry.id, world);
|
|
return result.error ? result : {ok: `Deleted ${entry.name}.`};
|
|
};
|
|
|
|
const reply = (session, result) => {
|
|
const room = left(session.account);
|
|
const mine = madeBy(session.account).map(entry => ({kind: entry.kind, id: entry.id, name: entry.name, base: entry.base, art: entry.artPending ? "" : entry.art || "",
|
|
artMode: entry.artMode || "sticker", waiting: entry.pending ? "item" : entry.artPending ? "picture" : ""}));
|
|
session.sendXt("xcm", -1, result.error ? 0 : 1, String(result.error || result.ok || "").replace(/%/g, " percent"), room.today, room.inAll,
|
|
JSON.stringify(mine).replace(/%/g, "\\u0025"));
|
|
};
|
|
|
|
// `world` tells games about items taken (lib/world.js itemsTaken).
|
|
const handlers = world => ({
|
|
xcm(session, roomId, [action, kind, id, ...words]) {
|
|
if (action === "make") {
|
|
reply(session, make(session, kind, id, words.join(" ")));
|
|
}
|
|
else if (action === "look") {
|
|
reply(session, setLook(session.account, kind, id, words[0]));
|
|
}
|
|
else if (action === "rename") {
|
|
reply(session, rename(session.account, kind, id, words.join(" ")));
|
|
}
|
|
else if (action === "delete") {
|
|
reply(session, remove(session, kind, id, world));
|
|
}
|
|
else {
|
|
reply(session, enabled() ? {ok: ""} : {error: "The Item Maker is turned off on this server for now."});
|
|
}
|
|
},
|
|
});
|
|
|
|
module.exports = {handlers, madeBy, rename, setLook, review, enabled, approvalOn, artApprovalOn, pictureWaits, setSwitches,
|
|
pictureRefused, uploadRefusal, setUploadsBlocked, takePicture, ART_STRIKES, PER_DAY, IN_ALL};
|