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]>
234 lines
15 KiB
JavaScript
234 lines
15 KiB
JavaScript
"use strict";
|
|
|
|
// end-to-end check of the sign-up page's rules and the account page
|
|
// (/account, lib/manage.js): signing in, password, username requests,
|
|
// feedback, the lock, the switches for parts of the game, login history,
|
|
// and the admin panel's side of it. simulated players, a real server.
|
|
|
|
const assert = require("assert");
|
|
const art = require("../lib/ecard-art.json");
|
|
const harness = require("./harness.js");
|
|
|
|
const HTTP_PORT = 18084;
|
|
const GAME_PORT = 19343;
|
|
const BASE = `http://127.0.0.1:${HTTP_PORT}`;
|
|
const TOWNSHIP = "jamaa_township.room_main#1";
|
|
const {postJson} = harness;
|
|
|
|
const authenticate = (username, password) => postJson(`${BASE}/authenticate`, {username, password});
|
|
|
|
const arrive = async (username, password) => {
|
|
const auth = await (await authenticate(username, password)).json();
|
|
const client = new harness.GameClient(GAME_PORT);
|
|
await client.connect();
|
|
const login = await client.logIn(username, auth.auth_token);
|
|
assert.strictEqual(login.status, "1");
|
|
client.xt("rj", 1, TOWNSHIP, 1, 0, 0);
|
|
const roomId = (await client.untilXt("rj"))[4];
|
|
await client.untilXt("rp");
|
|
client.xt("au", roomId, 1, 400, 400, 14, 1);
|
|
return {client, roomId, token: auth.auth_token};
|
|
};
|
|
|
|
// A request to one of the two cookie-guarded pages' APIs.
|
|
const page = prefix => async (pathname, body, cookie, headers = {}) => {
|
|
const response = await fetch(`${BASE}/${prefix}/api/${pathname}`, {
|
|
method: body === undefined ? "GET" : "POST",
|
|
headers: {"Content-Type": "application/json", ...(cookie ? {Cookie: cookie} : {}), ...headers},
|
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
});
|
|
return {status: response.status, data: await response.json(), cookie: (response.headers.get("set-cookie") || "").split(";")[0]};
|
|
};
|
|
const mine = page("account");
|
|
const panel = page("admin");
|
|
|
|
const run = async () => {
|
|
const register = (username, avatarType) => fetch(`${BASE}/api/register`, {method: "POST", headers: {"Content-Type": "application/json"},
|
|
body: JSON.stringify({username, password: "KettlePass01", avatarType, agreed: true})});
|
|
assert.strictEqual((await register("Ann", 4)).status, 200);
|
|
assert.strictEqual((await register("Ben", 24)).status, 200);
|
|
// what a client shows beside its login form.
|
|
const status = await (await fetch(`${BASE}/api/status`)).json();
|
|
assert.ok(status.online === 0 && status.uptimeSeconds >= 0);
|
|
|
|
// --- the page and who may use it
|
|
assert.match(await (await fetch(`${BASE}/account`)).text(), /Your account/);
|
|
assert.strictEqual((await mine("me")).status, 401);
|
|
assert.strictEqual((await mine("login", {username: "Ann", password: "wrong"})).status, 401);
|
|
assert.strictEqual((await mine("login", {username: "Nobody", password: "KettlePass01"})).status, 401);
|
|
const signedIn = await mine("login", {username: "ann", password: "KettlePass01"});
|
|
assert.strictEqual(signedIn.status, 200);
|
|
assert.match(signedIn.cookie, /^ajc_account=[0-9a-f]{48}$/);
|
|
const ann = signedIn.cookie;
|
|
assert.strictEqual((await mine("act", {action: "lock", locked: true}, ann, {Origin: "http://evil.example"})).status, 403);
|
|
let me = (await mine("me", undefined, ann)).data;
|
|
assert.deepStrictEqual([me.username, me.animalType, me.locked, me.features.chat], ["Ann", 4, false, true]); // the wolf she picked
|
|
// the wrong password and the sign-in are both in her history, newest first.
|
|
assert.deepStrictEqual(me.history.map(login => [login.via, login.ok]), [["web", true], ["web", false]]);
|
|
|
|
// --- parts of the game switched off
|
|
const {client: a, roomId} = await arrive("Ann", "KettlePass01");
|
|
const {client: b} = await arrive("Ben", "KettlePass01");
|
|
await a.untilXt("ac");
|
|
const set = async (feature, on) => assert.strictEqual((await mine("act", {action: "feature", feature, on}, ann)).status, 200);
|
|
assert.strictEqual((await mine("act", {action: "feature", feature: "flying", on: false}, ann)).status, 400);
|
|
|
|
await set("buddies", false);
|
|
b.xt("ba", roomId, "Ann");
|
|
assert.deepStrictEqual((await b.untilXt("ba")).slice(2, 4), ["3", "Ann"]); // not accepting requests
|
|
a.xt("ba", roomId, "Ben");
|
|
assert.strictEqual((await a.untilXt("ba"))[2], "3");
|
|
await set("buddies", true);
|
|
b.xt("ba", roomId, "Ann");
|
|
assert.strictEqual((await a.untilXt("ba"))[3], "Ben"); // it arrives now
|
|
|
|
await set("chat", false);
|
|
a.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[hello%0]]></txt></body></msg>`);
|
|
assert.deepStrictEqual((await a.untilXt("uc")).slice(3), ["-1", "5"]); // her line goes nowhere
|
|
b.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[anyone%0]]></txt></body></msg>`);
|
|
assert.strictEqual((await b.untilXt("uc"))[3], "anyone");
|
|
await set("chat", true);
|
|
b.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[again%0]]></txt></body></msg>`);
|
|
assert.strictEqual((await a.untilXt("uc"))[3], "again"); // "anyone" never reached her
|
|
|
|
await set("trading", false);
|
|
b.xt("ti", roomId, 0, "Ann", 0, 1, 0, 0, 0, 0);
|
|
assert.deepStrictEqual((await b.untilXt("ti")).slice(2, 4), ["4", "Ann"]); // unavailable, before anything else is looked at
|
|
await set("jamagrams", false);
|
|
b.xt("es", roomId, "Ann", art.cards[0], art.stamps[0], 0, "hi", 0, 0, 0);
|
|
assert.strictEqual((await b.untilXt("es"))[2], "-2"); // not accepting them
|
|
await set("jamagrams", true);
|
|
b.xt("es", roomId, "Ann", art.cards[0], art.stamps[0], 0, "hi", 0, 0, 0);
|
|
assert.strictEqual((await b.untilXt("es"))[2], "1");
|
|
await set("jamagrams", false);
|
|
me = (await mine("me", undefined, ann)).data;
|
|
assert.deepStrictEqual([me.features.trading, me.features.jamagrams, me.features.buddies, me.online], [false, false, true, true]);
|
|
|
|
// --- buddies with a note, the block list, achievements, den visitors
|
|
b.xt("bc", roomId, "Ann", 1); // ben says yes to her request from before
|
|
a.xt("ba", roomId, "Ben");
|
|
await b.untilXt("ba");
|
|
b.xt("bc", roomId, "Ann", 1);
|
|
await a.untilXt("bs");
|
|
assert.strictEqual((await mine("act", {action: "buddyNote", name: "Ben", note: " met at the fountain "}, ann)).status, 200);
|
|
assert.strictEqual((await mine("act", {action: "buddyNote", name: "Nobody", note: "x"}, ann)).status, 400);
|
|
assert.strictEqual((await mine("act", {action: "block", name: "Nobody"}, ann)).status, 400);
|
|
assert.strictEqual((await mine("act", {action: "block", name: "Ben"}, ann)).status, 200);
|
|
await a.untilXt("bl"); // her game hears of it: its buddy list, then its block list
|
|
assert.deepStrictEqual((await a.untilXt("bl")).slice(2, 5), ["1", "1", "ben"]);
|
|
assert.strictEqual((await mine("act", {action: "block", name: "Ben"}, ann)).status, 400);
|
|
b.xt("dj", roomId, "denAnn", 1, -1);
|
|
await b.untilXt("rj"); // locked out: she blocked him
|
|
assert.strictEqual((await mine("act", {action: "unblock", name: "ben"}, ann)).status, 200);
|
|
b.xt("dj", roomId, "denAnn", 1, -1);
|
|
const inDen = await b.untilXt("rj");
|
|
assert.strictEqual(inDen[3], "denAnn");
|
|
b.xt("rj", inDen[4], TOWNSHIP, 1, 0, 0);
|
|
await b.untilXt("rp");
|
|
me = (await mine("me", undefined, ann)).data;
|
|
assert.deepStrictEqual(me.buddyList, [{name: "Ben", online: true, note: "met at the fountain"}]);
|
|
assert.deepStrictEqual([me.blocked, me.denVisits.map(visit => visit.name), me.trades, me.offers], [[], ["Ben"], [], {incoming: [], outgoing: []}]);
|
|
assert.ok(me.achievements.of > 200 && me.achievements.counted.some(counted => counted.name === "Gems Earned" && counted.next > 0));
|
|
|
|
// --- a trade offer left for someone, answered from their page
|
|
const giveTo = async (username, query) => {
|
|
const found = (await (await fetch(`${BASE}/api/search?q=${query}&kind=clothing`)).json()).results[0];
|
|
await fetch(`${BASE}/api/give`, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({username, kind: "clothing", id: found.id, colorIndex: 0})});
|
|
return found.name;
|
|
};
|
|
const hatName = await giveTo("Ann", "top+hat");
|
|
const scarfName = await giveTo("Ben", "scarf");
|
|
let benHas = await b.untilXt("il");
|
|
while (benHas[2] !== "2" || benHas[5] !== "Ben") { // past the lists he was sent of Ann's clothes
|
|
benHas = await b.untilXt("il");
|
|
}
|
|
b.xt("ts", roomId, 0, 1, 0, benHas[9]); // ben puts his scarf up for trade, in the game
|
|
await b.untilXt("tl");
|
|
const benPageCookie = (await mine("login", {username: "Ben", password: "KettlePass01"})).cookie;
|
|
const tradable = (await mine("tradable?of=ben", undefined, ann)).data;
|
|
assert.deepStrictEqual([tradable.found, tradable.theirs.map(item => item.name), tradable.mine.map(item => item.name)], [true, [scarfName], [hatName]]);
|
|
assert.strictEqual((await mine("act", {action: "offer", to: "Ben", wanted: tradable.theirs[0], offered: []}, ann)).status, 400);
|
|
assert.strictEqual((await mine("act", {action: "offer", to: "Ben", wanted: {type: 0, inv: 999999}, offered: tradable.mine}, ann)).status, 400);
|
|
assert.strictEqual((await mine("act", {action: "offer", to: "Ben", wanted: tradable.theirs[0], offered: tradable.mine}, ann)).status, 400); // she has trading off
|
|
await set("trading", true);
|
|
assert.strictEqual((await mine("act", {action: "offer", to: "Ben", wanted: tradable.theirs[0], offered: tradable.mine}, ann)).status, 200);
|
|
let benPage = (await mine("me", undefined, benPageCookie)).data;
|
|
assert.deepStrictEqual(benPage.offers.incoming.map(offer => [offer.from, offer.wanted.name, offer.offered.map(item => item.name)]), [["Ann", scarfName, [hatName]]]);
|
|
assert.strictEqual((await mine("me", undefined, ann)).data.offers.outgoing.length, 1);
|
|
assert.strictEqual((await mine("act", {action: "answerOffer", id: benPage.offers.incoming[0].id, accept: true}, benPageCookie)).status, 200);
|
|
await a.untilXt("di"); // both are in the game: their inventories are sent afresh
|
|
await b.untilXt("di");
|
|
benPage = (await mine("me", undefined, benPageCookie)).data;
|
|
assert.deepStrictEqual([benPage.offers.incoming, benPage.trades.map(trade => [trade.with, trade.got, trade.gave])], [[], [["Ann", [hatName], [scarfName]]]]);
|
|
assert.deepStrictEqual((await mine("tradable?of=ben", undefined, ann)).data.mine.map(item => item.name), [scarfName]);
|
|
|
|
// --- a username request, approved from the admin panel
|
|
assert.strictEqual((await mine("act", {action: "requestName", newName: "Ben"}, ann)).status, 400); // taken
|
|
assert.strictEqual((await mine("act", {action: "requestName", newName: "Ann"}, ann)).status, 400); // hers already
|
|
assert.strictEqual((await mine("act", {action: "requestName", newName: "x"}, ann)).status, 400);
|
|
const asked = await mine("act", {action: "requestName", newName: "Annabel", reason: "my real nickname"}, ann);
|
|
assert.strictEqual(asked.status, 200);
|
|
assert.deepStrictEqual(asked.data.account.nameRequests.map(request => [request.newName, request.status]), [["Annabel", "waiting"]]);
|
|
assert.strictEqual((await mine("act", {action: "feedback", kind: "bug", text: " the slide is stuck "}, ann)).status, 200);
|
|
assert.strictEqual((await mine("act", {action: "feedback", kind: "bug", text: " "}, ann)).status, 400);
|
|
assert.strictEqual((await mine("act", {action: "feedback", kind: "rant", text: "x"}, ann)).status, 400);
|
|
|
|
const admin = (await panel("setup", {password: "admin-password-1"})).cookie;
|
|
const waiting = (await panel("support?handled=0", undefined, admin)).data;
|
|
assert.deepStrictEqual([waiting.open, waiting.names[0].newName, waiting.names[0].reason, waiting.feedback[0].text],
|
|
[2, "Annabel", "my real nickname", "the slide is stuck"]);
|
|
assert.strictEqual((await panel("overview", undefined, admin)).data.stats.support, 2);
|
|
assert.strictEqual((await panel("support", {action: "read", id: waiting.feedback[0].id}, admin)).status, 200);
|
|
assert.strictEqual((await panel("support", {action: "approve", id: waiting.names[0].id}, admin)).status, 200);
|
|
assert.strictEqual((await panel("support", {action: "approve", id: waiting.names[0].id}, admin)).status, 400); // only once
|
|
assert.strictEqual((await mine("me", undefined, ann)).status, 401); // renamed: sign in again, with the new name
|
|
assert.strictEqual((await authenticate("Ann", "KettlePass01")).status, 401);
|
|
const annabel = (await mine("login", {username: "Annabel", password: "KettlePass01"})).cookie;
|
|
me = (await mine("me", undefined, annabel)).data;
|
|
assert.deepStrictEqual([me.username, me.nameRequests[0].status, me.feedback[0].handledAt > 0], ["Annabel", "approved", true]);
|
|
|
|
// --- the lock: out of the game, and no way back in until it is undone
|
|
const {token} = await arrive("Annabel", "KettlePass01");
|
|
assert.strictEqual((await mine("act", {action: "lock", locked: true}, annabel)).status, 200);
|
|
assert.strictEqual((await authenticate("Annabel", "KettlePass01")).status, 401);
|
|
assert.strictEqual((await postJson(`${BASE}/authenticate`, {refresh_token: token})).status, 401); // the saved sign-in is gone
|
|
assert.strictEqual((await panel("accounts", undefined, admin)).data.accounts.find(account => account.username === "Annabel").locked, true);
|
|
assert.strictEqual((await mine("login", {username: "Annabel", password: "KettlePass01"})).status, 200); // the page still lets her in
|
|
assert.strictEqual((await mine("act", {action: "lock", locked: false}, annabel)).status, 200);
|
|
assert.strictEqual((await authenticate("Annabel", "KettlePass01")).status, 200);
|
|
|
|
// --- the password: the old one is asked for, and stops working
|
|
assert.strictEqual((await mine("act", {action: "password", current: "wrong", password: "KettlePass02"}, annabel)).status, 400);
|
|
assert.strictEqual((await mine("act", {action: "password", current: "KettlePass01", password: "short"}, annabel)).status, 400);
|
|
assert.strictEqual((await mine("act", {action: "password", current: "KettlePass01", password: "KettlePass02"}, annabel)).status, 200);
|
|
assert.strictEqual((await authenticate("Annabel", "KettlePass01")).status, 401);
|
|
assert.strictEqual((await authenticate("Annabel", "KettlePass02")).status, 200);
|
|
me = (await mine("me", undefined, annabel)).data;
|
|
assert.ok(me.history.some(login => login.via === "launcher" && !login.ok) && me.history.some(login => login.via === "game" && login.ok));
|
|
|
|
assert.strictEqual((await mine("logout", {}, annabel)).status, 200);
|
|
assert.strictEqual((await mine("me", undefined, annabel)).status, 401);
|
|
|
|
// --- deleting one's own account: the password and the name, then it is gone
|
|
const {client: b2} = await arrive("Ben", "KettlePass01");
|
|
const ben = (await mine("login", {username: "Ben", password: "KettlePass01"})).cookie;
|
|
assert.strictEqual((await mine("act", {action: "delete", current: "wrong", confirm: "Ben"}, ben)).status, 400);
|
|
assert.strictEqual((await mine("act", {action: "delete", current: "KettlePass01", confirm: "Annabel"}, ben)).status, 400);
|
|
const gone = await mine("act", {action: "delete", current: "KettlePass01", confirm: "ben"}, ben);
|
|
assert.deepStrictEqual([gone.status, gone.data.deleted, gone.data.account], [200, true, undefined]);
|
|
assert.strictEqual((await mine("me", undefined, ben)).status, 401);
|
|
assert.strictEqual((await authenticate("Ben", "KettlePass01")).status, 401);
|
|
assert.ok(!(await panel("accounts", undefined, admin)).data.accounts.some(account => account.username === "Ben"));
|
|
// the name is held for a while (lib/accounts.js, NAME_HELD_DAYS): the
|
|
// players Ben met still know him by it.
|
|
assert.deepStrictEqual(await (await register("Ben", 5)).json(), {error: "username_taken"});
|
|
b2.socket.destroy();
|
|
a.socket.destroy();
|
|
b.socket.destroy();
|
|
};
|
|
|
|
harness.withServer("account page test", HTTP_PORT, GAME_PORT, run).catch(err => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|