A staff window in the game, from the report button of a player's card

For staff, the report button of a player's card opens a window for that
player instead (AJClient.openModerate): warn with a reason, send a
message, silence for an hour or a day or lift it, bring them here, go to
them, disconnect, and their warnings. Only what the role allows is shown.

The window sends "xmd" [command, username, ...], which the server runs as
the staff command typed in chat (lib/commands.js), so the permission check
and the moderators' log are the same; the answer comes as a message box.
Only active staff, and only these commands. Staff are sent their role and
permissions at login ("xsp"); nobody else is sent anything.

test/staff.js covers xsp and xmd, and that a player's xmd does nothing.

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 6563d5de99
commit 627e6f9180
5 files changed
+262 -4

No files matched your search

+25 -3
View File
@@ -61,8 +61,9 @@ const webSession = () => {
const say = (client, roomId, text) =>
client.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[${text}%0]]></txt></body></msg>`);
// logs in (with a 2FA code when given) and walks into `room`.
const arrive = async (username, password, room, totp) => {
// logs in (with a 2FA code when given) and walks into `room`. `onLogin`
// sees what comes with the login, before joining skips past it.
const arrive = async (username, password, room, totp, onLogin = async () => {}) => {
const res = await postJson(`${BASE}/authenticate`, {username, password, ...(totp ? {totp} : {})});
const auth = await res.json();
assert.strictEqual(res.status, 200, `${username} could not sign in: ${JSON.stringify(auth)}`);
@@ -70,6 +71,7 @@ const arrive = async (username, password, room, totp) => {
await client.connect();
const login = await client.logIn(username, auth.auth_token);
assert.strictEqual(login.status, "1");
await onLogin(client);
client.xt("rj", 1, room, 1, 0, 0);
const rj = await client.untilXt("rj");
await client.untilXt("rp");
@@ -134,7 +136,13 @@ const run = async () => {
// --- the game: the login reply carries your own role, and nobody else's
usedStep.Mira++;
const mira = await arrive("Mira", people.Mira, TOWNSHIP, codeAt(secrets.Mira, usedStep.Mira));
// and the patched client's staff window is told the same ("xsp")
let staffSaid = null;
const mira = await arrive("Mira", people.Mira, TOWNSHIP, codeAt(secrets.Mira, usedStep.Mira), async client => {
staffSaid = await client.untilXt("xsp");
});
assert.strictEqual(staffSaid[2], "moderator");
assert.ok(staffSaid[3].split(",").includes("player.summon"));
assert.strictEqual(mira.login.params.staffRole, "moderator");
assert.ok(mira.login.params.staffPermissions.split(",").includes("player.summon"));
usedStep.Hal++;
@@ -186,6 +194,20 @@ const run = async () => {
assert.strictEqual(await nextBox(mira.client), "Shown to Ann.");
say(mira.client, ann.roomId, "!warnings Ann");
assert.match(await nextBox(mira.client), /^Ann has 2 warnings\. Latest: \S+ behavior by Mira; \S+ bullying by Mira \(called names\)$/);
// the client's staff window ("xmd"): the same commands, one field each
mira.client.xt("xmd", ann.roomId, "warn", "Ann", "personal");
assert.deepStrictEqual((await ann.client.untilXt("fd")).slice(2, 4), ["fw", "3"]);
assert.strictEqual(await nextBox(mira.client), "Ann warned (personal): warning 3.");
mira.client.xt("xmd", ann.roomId, "message", "Ann", "hello there");
assert.deepStrictEqual((await ann.client.untilXt("fd")).slice(2, 4), ["fp", "hello there"]);
assert.strictEqual(await nextBox(mira.client), "Shown to Ann.");
mira.client.xt("xmd", ann.roomId, "ban", "Ann"); // not one the window has: nothing
// and from a player, nothing at all: Ann warns Mira
ann.client.xt("xmd", ann.roomId, "warn", "Mira", "bullying");
mira.client.xt("xmd", ann.roomId, "warnings", "Ann");
assert.match(await nextBox(mira.client), /^Ann has 3 warnings\. /);
say(mira.client, ann.roomId, "!warnings Mira");
assert.strictEqual(await nextBox(mira.client), "Mira has no warnings.");
say(mira.client, ann.roomId, "!kick Ann");
assert.strictEqual((await ann.client.untilXt("fd"))[2], "fk");
assert.strictEqual(await nextBox(mira.client), "Ann was disconnected.");