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]>
201 lines
8.0 KiB
JavaScript
201 lines
8.0 KiB
JavaScript
"use strict";
|
|
|
|
const {logText} = require("./logtext.js");
|
|
const accounts = require("./accounts.js");
|
|
const limits = require("./limits.js");
|
|
const net = require("net");
|
|
|
|
// what bans keep beside the account's own `bannedUntil`: banned addresses,
|
|
// each account's one appeal, and a record of every ban given and lifted.
|
|
//
|
|
// an address ban is for good, and is of the address alone: the accounts
|
|
// that were used from it are not banned with it (a VPN's address is many
|
|
// people's). it keeps that address out of the game and out of signing up;
|
|
// the account page still opens there, where a player can ask about it or
|
|
// delete their account. this machine's own address cannot be banned, which
|
|
// is also the address of everyone when a proxy or a tunnel stands in front
|
|
// and the server has not been told (AJ_TRUSTED_PROXY).
|
|
|
|
const SCHEMA = `
|
|
CREATE TABLE IF NOT EXISTS ban_log (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
at INTEGER NOT NULL,
|
|
account_id INTEGER,
|
|
username TEXT NOT NULL DEFAULT '',
|
|
address TEXT NOT NULL DEFAULT '',
|
|
action TEXT NOT NULL,
|
|
seconds INTEGER NOT NULL DEFAULT 0,
|
|
reason TEXT NOT NULL DEFAULT '',
|
|
by TEXT NOT NULL DEFAULT ''
|
|
);
|
|
CREATE TABLE IF NOT EXISTS address_bans (
|
|
address_key TEXT PRIMARY KEY,
|
|
address TEXT NOT NULL,
|
|
reason TEXT NOT NULL,
|
|
by TEXT NOT NULL,
|
|
created_at INTEGER NOT NULL
|
|
);
|
|
CREATE TABLE IF NOT EXISTS appeals (
|
|
account_id INTEGER PRIMARY KEY,
|
|
created_at INTEGER NOT NULL,
|
|
username TEXT NOT NULL,
|
|
text TEXT NOT NULL,
|
|
address_key TEXT NOT NULL DEFAULT '',
|
|
status TEXT NOT NULL DEFAULT 'waiting',
|
|
reply TEXT NOT NULL DEFAULT '',
|
|
handled_at INTEGER
|
|
);
|
|
`;
|
|
|
|
const WAITING = "waiting";
|
|
const APPROVED = "approved";
|
|
const DENIED = "denied";
|
|
const MAX_REASON = 300;
|
|
const MAX_APPEAL = 1000;
|
|
const MAX_REPLY = 500;
|
|
const MAX_ADDRESS_BANS = 10000;
|
|
const HISTORY_SHOWN = 50;
|
|
|
|
const now = () => Math.floor(Date.now() / 1000);
|
|
const db = () => accounts.database();
|
|
// A line break is kept; the other control characters are not.
|
|
const clean = (text, max) => String(text === undefined || text === null ? "" : text).replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g, " ").trim().slice(0, max);
|
|
|
|
// A ban's reason as it is kept and shown: something is always said.
|
|
const NO_REASON = "Not provided";
|
|
const reasonText = text => clean(text, MAX_REASON) || NO_REASON;
|
|
|
|
const banned = new Map(); // address as limits count it -> {key, address, reason, by, createdAt}
|
|
|
|
const addressRow = row => ({key: row.address_key, address: row.address, reason: row.reason, by: row.by, createdAt: row.created_at});
|
|
|
|
const load = () => {
|
|
db().exec(SCHEMA);
|
|
for (const row of db().prepare("SELECT * FROM address_bans").all()) {
|
|
banned.set(row.address_key, addressRow(row));
|
|
}
|
|
};
|
|
|
|
// `entry`: {account, address, action, seconds, reason, by}. actions: "ban",
|
|
// "unban", "reason", "address_ban", "address_unban", "appeal",
|
|
// "appeal_approved", "appeal_denied". A ban that runs out leaves no line.
|
|
const record = entry => {
|
|
db().prepare("INSERT INTO ban_log (at, account_id, username, address, action, seconds, reason, by) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
|
|
.run(now(), entry.account ? entry.account.id : null, entry.account ? entry.account.username : "", entry.address || "",
|
|
entry.action, entry.seconds || 0, entry.reason || "", entry.by || "");
|
|
};
|
|
|
|
const logRow = row => ({at: row.at, username: row.username, address: row.address, action: row.action, seconds: row.seconds, reason: row.reason, by: row.by});
|
|
|
|
const historyOf = account =>
|
|
db().prepare("SELECT * FROM ban_log WHERE account_id = ? ORDER BY id DESC LIMIT ?").all(account.id, HISTORY_SHOWN).map(logRow);
|
|
|
|
const addressBan = address => banned.get(limits.key(address)) || null;
|
|
|
|
// returns {ban} or {error: "not_an_address" | "own_address" | "already" | "too_many"}.
|
|
const banAddress = (address, reason, by) => {
|
|
const text = String(address || "").trim().replace(/^::ffff:(?=\d+\.\d+\.\d+\.\d+$)/i, "");
|
|
if (!net.isIP(text)) {
|
|
return {error: "not_an_address"};
|
|
}
|
|
// this machine: the owner at home, and with a proxy or a tunnel in front
|
|
// everybody else as well.
|
|
if (limits.isLoopback(text) || /^(0\.0\.0\.0|::|0:0:0:0:0:0:0:[01])$/.test(text)) {
|
|
return {error: "own_address"};
|
|
}
|
|
const key = limits.key(text);
|
|
if (banned.has(key)) {
|
|
return {error: "already"};
|
|
}
|
|
if (banned.size >= MAX_ADDRESS_BANS) {
|
|
return {error: "too_many"};
|
|
}
|
|
const ban = {key, address: text, reason: reasonText(reason), by, createdAt: now()};
|
|
db().prepare("INSERT INTO address_bans (address_key, address, reason, by, created_at) VALUES (?, ?, ?, ?, ?)").run(key, ban.address, ban.reason, by, ban.createdAt);
|
|
banned.set(key, ban);
|
|
record({address: key, action: "address_ban", seconds: -1, reason: ban.reason, by});
|
|
return {ban};
|
|
};
|
|
|
|
// `key` as a listing gave it, or any address the ban covers.
|
|
const unbanAddress = (key, by) => {
|
|
const ban = banned.get(String(key)) || addressBan(key);
|
|
if (!ban) {
|
|
return false;
|
|
}
|
|
db().prepare("DELETE FROM address_bans WHERE address_key = ?").run(ban.key);
|
|
banned.delete(ban.key);
|
|
record({address: ban.key, action: "address_unban", by});
|
|
return true;
|
|
};
|
|
|
|
const addressBans = () => [...banned.values()].sort((one, other) => other.createdAt - one.createdAt);
|
|
|
|
const appealRow = row => ({
|
|
accountId: row.account_id,
|
|
createdAt: row.created_at,
|
|
username: row.username,
|
|
text: row.text,
|
|
addressKey: row.address_key,
|
|
status: row.status,
|
|
reply: row.reply,
|
|
handledAt: row.handled_at,
|
|
});
|
|
|
|
const appealOf = account => {
|
|
const row = db().prepare("SELECT * FROM appeals WHERE account_id = ?").get(account.id);
|
|
return row ? appealRow(row) : null;
|
|
};
|
|
|
|
// `addressKey` when it is (also) about the address they wrote from.
|
|
// returns {appeal} or {error: "empty" | "already"}.
|
|
const appeal = (account, text, addressKey = "") => {
|
|
const body = clean(text, MAX_APPEAL);
|
|
if (!body) {
|
|
return {error: "empty"};
|
|
}
|
|
if (appealOf(account)) {
|
|
return {error: "already"};
|
|
}
|
|
db().prepare("INSERT INTO appeals (account_id, created_at, username, text, address_key) VALUES (?, ?, ?, ?, ?)").run(account.id, now(), account.username, body, addressKey);
|
|
record({account, address: addressKey, action: "appeal"});
|
|
console.log(`[bans] "${logText(account.username)}" appealed`);
|
|
return {appeal: appealOf(account)};
|
|
};
|
|
|
|
// appeals waiting, oldest first; or with `handled`, the latest answered.
|
|
const appeals = (handled = false) => db()
|
|
.prepare(handled
|
|
? "SELECT * FROM appeals WHERE status <> ? ORDER BY handled_at DESC LIMIT 200"
|
|
: "SELECT * FROM appeals WHERE status = ? ORDER BY created_at LIMIT 500")
|
|
.all(WAITING).map(appealRow);
|
|
|
|
const waitingAppeal = accountId => {
|
|
const row = db().prepare("SELECT * FROM appeals WHERE account_id = ? AND status = ?").get(Number(accountId), WAITING);
|
|
return row ? appealRow(row) : null;
|
|
};
|
|
|
|
// the caller lifts the bans when it approves.
|
|
const answerAppeal = (accountId, approved, reply, by) => {
|
|
const answered = db().prepare("UPDATE appeals SET status = ?, reply = ?, handled_at = ? WHERE account_id = ? AND status = ?")
|
|
.run(approved ? APPROVED : DENIED, clean(reply, MAX_REPLY), now(), Number(accountId), WAITING).changes > 0;
|
|
if (answered) {
|
|
const account = accounts.byId(Number(accountId));
|
|
record({account, action: approved ? "appeal_approved" : "appeal_denied", reason: clean(reply, MAX_REPLY), by});
|
|
}
|
|
return answered;
|
|
};
|
|
|
|
const openAppeals = () => db().prepare("SELECT COUNT(*) AS count FROM appeals WHERE status = ?").get(WAITING).count;
|
|
|
|
// an account being deleted: what it wrote goes with it. the record of what
|
|
// was done about it stays, under the name it had.
|
|
const forget = account => {
|
|
db().prepare("DELETE FROM appeals WHERE account_id = ?").run(account.id);
|
|
};
|
|
|
|
module.exports = {
|
|
load, record, historyOf, addressBan, banAddress, unbanAddress, addressBans, appealOf, appeal, appeals, waitingAppeal, answerAppeal,
|
|
openAppeals, forget, clean, reasonText, NO_REASON, MAX_REASON, MAX_APPEAL, MAX_REPLY,
|
|
};
|