Staff roles with permissions, warnings, in-game staff commands

Moderators were one flag on the account. Now an account can hold a staff
role (lib/roles.js): helper, moderator or admin, each a list of named
permissions, with a higher role holding everything below it. An account
only marked `moderator` still counts as a moderator.

Every staff action checks the permission it needs, and staff never act
on staff of their own rank or above:

- warnings: kept on the account (who, when, the reason, a note for
  staff), and shown to the player with the game's own warning popup for
  the reason ("fw": inappropriate behavior, bullying, personal
  information, scamming), which this server's strings already word as the
  Burrow Rules.
- moderator panel: each action is checked against the role; new actions
  "warn" (with a reason and note), "summon" (bring a player to the room you
  are in) and "goto"; the player's page shows their warnings; GET
  /mod/api/me returns your role and permissions, and the page hides the
  buttons yours does not allow.
- in the game: !staff, !summon, !goto, !kick, !silence (HOURS, 0, or
  off), !warn PLAYER [reason] [note], !warnings PLAYER and !message, for
  staff whose role allows each, written to the moderators' log like the
  panel's actions, marked "(in game)". To anyone else they are plain chat.
  Usernames with spaces work.
- the login reply carries the player's own staffRole and
  staffPermissions (empty for everyone else), so a client can show staff
  tools only to staff.
- admin panel: a role picker on the account, "role" on POST
  /admin/api/account, and GET /admin/api/roles listing what each allows.
  The old moderator switch still works.

Also: the moderators' message box showed "--Message From Moderator--\n\n"
with the "\n" as written (strings 11134 and 11135 keep it as two
characters); they get real line breaks.

Staff powers need 2FA turned on, as the moderator panel already did. In
the game they come with the game session, which a trusted device opens
without a code; requiring a recent code there is left for later.

test/staff.js covers all of the above end to end.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
SnipzilandClaude Opus 5.5 committed 2026-10-16 22:42:46 -04:00
1 parent 63dc43ebb3
commit 2fba9f1612
10 files changed
+756 -21

No files matched your search

+30 -1
View File
@@ -18,6 +18,18 @@ const CURRENCY_GEMS = 0;
// client says "You earned N ..." in a popup when the amount went up.
const REASON_ANNOUNCE = 3;
// a warning's reason, and the client's own warning popup for it
// (FacilitatorXtCommManager.showContextualWarningPopup, "fw"): its artwork
// and its words, which this server's strings already say in its own name.
const WARNINGS = {
behavior: 4, // "Inappropriate Behavior"
bullying: 1, // "Bullying"
personal: 3, // "Personal Information"
scamming: 9, // "Scamming"
};
const MAX_WARNINGS_KEPT = 100;
const MAX_WARNING_NOTE = 200;
const now = () => Math.floor(Date.now() / 1000);
// seconds of ban left, PERMANENT, or 0 when not banned.
@@ -171,6 +183,23 @@ module.exports = ({findOnline}) => {
notify(session, text);
return true;
},
// a warning: kept on the account (who, when, why and a note for staff),
// and shown with the game's own warning popup if they are online.
// returns {count, online}, or null for a reason that is not one.
warn(target, reason, by, note = "") {
if (!Object.hasOwn(WARNINGS, reason)) {
return null;
}
target.warnings = [...(target.warnings || []), {at: now(), by, reason, note: String(note).slice(0, MAX_WARNING_NOTE)}]
.slice(-MAX_WARNINGS_KEPT);
accounts.save();
const session = findOnline(target.username);
if (session) {
discipline(session, "fw", WARNINGS[reason]);
}
return {count: target.warnings.length, online: Boolean(session)};
},
};
// the client's moderator requests, refused whoever sends them. each
@@ -178,7 +207,7 @@ module.exports = ({findOnline}) => {
const refuse = reply => session => session.sendXt(reply, -1, 0);
const handlers = {fk: refuse("fk"), fb: refuse("fb"), fs: refuse("fs"), fm: refuse("fm"), fg: refuse("fg"), fp: refuse("fp"), fc() {}};
return {handlers, actions, banRemaining, banOf, isSilenced, silenceRemaining, PERMANENT};
return {handlers, actions, banRemaining, banOf, isSilenced, silenceRemaining, PERMANENT, WARNINGS: Object.keys(WARNINGS)};
};
Object.assign(module.exports, {isSilenced, banRemaining, banOf});