mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 09:37:50 -05:00
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:
1 parent
63dc43ebb3
commit
2fba9f1612
10 files changed
+756
-21
No files matched your search
+49
-1
@@ -226,7 +226,7 @@
|
||||
#chat-context { margin: 0; padding: 0; list-style: none; }
|
||||
#chat-context li.this { background: var(--raised); border-radius: 10px; }
|
||||
#player-facts { margin-bottom: 14px; }
|
||||
#player-history { margin: 0; padding-left: 18px; font-size: 13px; overflow-wrap: anywhere; }
|
||||
#player-history, #player-warnings { margin: 0; padding-left: 18px; font-size: 13px; overflow-wrap: anywhere; }
|
||||
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
|
||||
</style>
|
||||
</head>
|
||||
@@ -303,11 +303,25 @@
|
||||
<button type="button" data-action="unsilence">Lift</button></div>
|
||||
<div class="row" style="margin-top:8px"><button type="button" id="open-chat">Chat history</button></div>
|
||||
</div>
|
||||
<div class="action">
|
||||
<h3>Warn</h3>
|
||||
<div class="row"><select id="warn-reason" aria-label="Reason">
|
||||
<option value="behavior">Inappropriate behavior</option>
|
||||
<option value="bullying">Bullying</option>
|
||||
<option value="personal">Personal information</option>
|
||||
<option value="scamming">Scamming</option>
|
||||
</select>
|
||||
<input id="warn-note" maxlength="200" placeholder="Note for staff (optional)" aria-label="Note">
|
||||
<button type="button" data-action="warn">Warn</button></div>
|
||||
</div>
|
||||
<div class="action">
|
||||
<h3>Message</h3>
|
||||
<div class="row"><input id="message-text" maxlength="200" placeholder="Text" aria-label="Message">
|
||||
<button type="button" data-action="message">Send</button></div>
|
||||
<div class="row" style="margin-top:8px"><button type="button" data-action="kick">Disconnect</button></div>
|
||||
<div class="row" style="margin-top:8px" title="In the game: both of you online, you in a room">
|
||||
<button type="button" data-action="summon">Bring to me</button>
|
||||
<button type="button" data-action="goto">Go to them</button></div>
|
||||
</div>
|
||||
<div class="action">
|
||||
<h3>Username and bio</h3>
|
||||
@@ -319,6 +333,8 @@
|
||||
</div>
|
||||
<h3 style="margin:16px 0 4px" id="history-title" hidden>Ban history</h3>
|
||||
<ul id="player-history"></ul>
|
||||
<h3 style="margin:16px 0 4px" id="warnings-title" hidden>Warnings</h3>
|
||||
<ul id="player-warnings"></ul>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -569,6 +585,7 @@
|
||||
["Ban", player.banned === 0 ? "—" : `${left(player.banned)} · ${player.banReason}`],
|
||||
["Chat", player.silenced === 0 ? "—" : `Silenced: ${left(player.silenced).toLowerCase()}`],
|
||||
["Reports waiting", String(player.openReports)],
|
||||
["Warnings", String(player.warnings || 0)],
|
||||
["Appeal", player.appeal ? `${player.appeal.status} · ${player.appeal.text}` : "—"],
|
||||
["Discord", player.discord || "—"],
|
||||
["Bio", player.bio || "—"],
|
||||
@@ -584,6 +601,11 @@
|
||||
if (document.activeElement !== $("ban-reason")) {
|
||||
$("ban-reason").value = player.banned === 0 ? "" : player.banReason;
|
||||
}
|
||||
const WARNING_REASONS = {behavior: "Inappropriate behavior", bullying: "Bullying", personal: "Personal information", scamming: "Scamming"};
|
||||
const warnings = player.warningList || [];
|
||||
$("warnings-title").hidden = warnings.length === 0;
|
||||
$("player-warnings").replaceChildren(...warnings.map(entry => el("li", [when(entry.at), WARNING_REASONS[entry.reason] || entry.reason,
|
||||
entry.note, entry.by && `by ${entry.by}`].filter(Boolean).join(" · "))));
|
||||
$("history-title").hidden = player.history.length === 0;
|
||||
$("player-history").replaceChildren(...player.history.map(entry => el("li", [when(entry.at), HISTORY[entry.action] || entry.action,
|
||||
entry.action === "ban" ? (entry.seconds === -1 ? "for good" : duration(entry.seconds)) : "", entry.reason, entry.by && `by ${entry.by}`]
|
||||
@@ -614,6 +636,7 @@
|
||||
case "banReason": case "banAddress": return {reason: $("ban-reason").value};
|
||||
case "silence": return {hours: numberFrom("silence-hours")};
|
||||
case "message": return {text: $("message-text").value};
|
||||
case "warn": return {reason: $("warn-reason").value, note: $("warn-note").value};
|
||||
default: return {};
|
||||
}
|
||||
};
|
||||
@@ -976,12 +999,37 @@
|
||||
one.addEventListener("click", () => showTab(one.dataset.tab));
|
||||
}
|
||||
|
||||
// the permission (lib/roles.js) each button needs: one the signed-in
|
||||
// role does not hold is not shown. the server checks again either way.
|
||||
const ACTION_PERMISSIONS = {
|
||||
ban: "player.ban", banReason: "player.ban", unban: "player.ban",
|
||||
silence: "chat.silence", unsilence: "chat.silence",
|
||||
kick: "player.kick", message: "player.warn", warn: "player.warn",
|
||||
rejectName: "player.names", acceptName: "player.names", clearBio: "player.names",
|
||||
banAddress: "address.ban", summon: "player.summon", goto: "player.goto",
|
||||
};
|
||||
const applyPermissions = async () => {
|
||||
const result = await api("me");
|
||||
if (!result.ok) {
|
||||
return;
|
||||
}
|
||||
const allowed = new Set(result.data.permissions || []);
|
||||
for (const pressed of document.querySelectorAll("button[data-action]")) {
|
||||
const needed = ACTION_PERMISSIONS[pressed.dataset.action];
|
||||
pressed.hidden = Boolean(needed) && !allowed.has(needed);
|
||||
}
|
||||
if (result.data.role) {
|
||||
$("who").textContent = `${result.data.username} (${result.data.role})`;
|
||||
}
|
||||
};
|
||||
|
||||
const showPanel = username => {
|
||||
signedIn = true;
|
||||
$("who").textContent = username;
|
||||
$("gate").hidden = true;
|
||||
$("panel").hidden = false;
|
||||
showTab(tab);
|
||||
applyPermissions();
|
||||
};
|
||||
|
||||
$("gate-form").addEventListener("submit", async event => {
|
||||
|
||||
Reference in new issue
Block a user