feat(dashboard): unify secure staff administration

Provide a single /dashboard entry point for owner and staff tools, with Discord OAuth sign-in for approved owner accounts and active staff. Add owner-managed dashboard access grants, staff server health and update visibility, filtering, moderation improvements, item controls, and per-animal clothing restrictions.

Replace staff-triggered password and 2FA resets with email-verified account recovery. Persist validated recovery addresses, use short-lived hashed recovery tokens, expose recovery flows in registration and account pages, and keep mail delivery disabled until its webhook configuration is present.

Cover dashboard aliases, recovery restrictions, Discord access, monitoring, item locks, wear rules, and staff behavior with regression tests.
This commit is contained in:
Snipzil committed 2026-10-19 10:09:35 -04:00
1 parent 4997315239
commit 7dee29010a
27 files changed
+2303 -346

No files matched your search

+93 -1
View File
@@ -3,6 +3,7 @@
const accounts = require("./accounts.js");
const customItems = require("./customitems.js");
const defpacks = require("./defpacks.js");
const wearRules = require("./wearrules.js");
// what staff who make items (items.create: admins and developers) may do
// about who has them:
@@ -83,6 +84,94 @@ const lockedList = () => [...lockSet()].map(entry => {
return {kind, id: Number(id), name: nameOf(kind, id)};
});
// The animals a moderator can select in the dashboard. Avatar types, rather
// than a hand-written list of species, keep this correct for packs added in
// a later game build.
const wearAnimals = () => defpacks.avatarTypes().sort((one, two) => one - two).map(type => {
const def = defpacks.avatarDef(type) || {};
return {id: Number(type), name: defpacks.string(def.titleStrRef || def.nameStrId) || def.abbrName || `Animal ${type}`};
});
const wearRuleList = () => wearRules.all().flatMap(rule => {
const found = item("clothing", rule.id);
return found.error ? [] : [{id: found.id, name: nameOf(found.kind, found.id), blockedTypes: rule.blocked}];
});
// Remove a new restriction from every possible display of an item. A clothing
// association has an avatar slot; a mannequin keeps the inventory ids in
// five den-item slots. Both must be cleaned or a rule can be bypassed by
// switching animals or visiting a den.
const removeBlockedUses = (account, itemId, blocked) => {
const disallowedAvatarSlots = new Set(account.avatars.filter(avatar => blocked.has(Number(avatar.type))).map(avatar => avatar.avInvId));
const matchingInventory = new Set(account.items.filter(piece => piece.def === itemId).map(piece => piece.inv));
let removed = 0;
let clothingChanged = false;
let mannequinChanged = false;
for (const piece of account.items) {
if (piece.def !== itemId || !Array.isArray(piece.on)) {
continue;
}
const kept = piece.on.filter(avInvId => !disallowedAvatarSlots.has(avInvId));
if (kept.length !== piece.on.length) {
removed += piece.on.length - kept.length;
piece.on = kept;
clothingChanged = true;
}
}
for (const denItem of account.denItems) {
const mannequinType = Number((defpacks.denItemDef(denItem.def) || {}).mannequinAvatarDefId);
if (!blocked.has(mannequinType) || !denItem.mannequin || !Array.isArray(denItem.mannequin.worn)) {
continue;
}
const kept = denItem.mannequin.worn.map(inv => (matchingInventory.has(Number(inv)) ? 0 : inv));
if (kept.some((inv, index) => inv !== denItem.mannequin.worn[index])) {
removed += kept.filter(inv => inv === 0).length - denItem.mannequin.worn.filter(inv => inv === 0).length;
denItem.mannequin.worn = kept;
mannequinChanged = true;
}
}
return {changed: clothingChanged || mannequinChanged, mannequinChanged, removed};
};
// Make a clothing item unavailable to the selected animal types. `world`
// refreshes games and den visitors after the persistent state is cleaned.
const setWearRule = (id, blockedTypes, world) => {
const found = item("clothing", id);
if (found.error) {
return found;
}
const animals = wearAnimals();
const allowed = new Set(animals.map(animal => animal.id));
if (!Array.isArray(blockedTypes) || blockedTypes.length > allowed.size || !blockedTypes.every(Number.isInteger)
|| blockedTypes.some(type => !allowed.has(type))) {
return {error: "Choose only animals from the list."};
}
const blocked = [...new Set(blockedTypes)].sort((one, two) => one - two);
const changedRule = wearRules.setBlockedTypes(found.id, blocked).changed;
let accountsChanged = 0;
let removed = 0;
const blockedSet = new Set(blocked);
for (const account of accounts.all()) {
const cleaned = removeBlockedUses(account, found.id, blockedSet);
if (!cleaned.changed) {
continue;
}
accountsChanged++;
removed += cleaned.removed;
accounts.save(account);
world.wearRulesChanged(account, cleaned.mannequinChanged);
}
// Packs downloaded after this moment, and games already open, use the
// same rule-to-flag transformation. Server checks above remain authority.
defpacks.invalidateClientItemPack();
customItems.sendClothingDefs([found.id]);
const animalNames = blocked.map(type => animals.find(animal => animal.id === type).name);
const subject = describe(found.kind, found.id);
const suffix = blocked.length ? `cannot be worn by ${animalNames.join(", ")}.` : "can be worn by every animal again.";
return {ok: `${subject} ${suffix}${removed ? ` Took it off ${removed} existing use${removed === 1 ? "" : "s"}.` : ""}`,
detail: `clothing ${found.id}; blocked types ${blocked.join(",") || "none"}; ${accountsChanged} account${accountsChanged === 1 ? "" : "s"} changed`, changed: changedRule};
};
// every one of an item an account has, out of its inventory (and its trade
// list). `world` tells a game playing (lib/world.js itemsTaken). returns how
// many went.
@@ -135,7 +224,10 @@ const deleteCustom = (kind, id, world) => {
if (lockSet().delete(key(kind, entry.id))) {
saveLocks();
}
if (kind === "clothing") {
wearRules.forget(entry.id);
}
return {ok: `Deleted ${entry.name} (${kind === "den" ? "den item" : "clothing"} ${entry.id})${count ? `, and took ${count} from players` : ""}.`};
};
module.exports = {isLocked, setLocked, lockedList, take, deleteCustom};
module.exports = {isLocked, setLocked, lockedList, wearAnimals, wearRuleList, setWearRule, take, deleteCustom};