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

+28 -3
View File
@@ -28,6 +28,8 @@ const SIGNUP_LIFETIME_MS = 5 * 60000;
const forLog = message => message.replace(/(<pword><!\[CDATA\[)[\s\S]*?(\]\]>)/, "$1(hidden)$2");
const connections = new Map(); // remote address -> open sockets
let connectionCount = 0;
const metrics = {accepted: 0, rejected: 0, floodDisconnects: 0, handlerErrors: 0};
let nextUserId = 1;
@@ -139,13 +141,18 @@ const start = handlers => new Promise((resolve, reject) => {
const onConnection = socket => {
const address = limits.key(socket.remoteAddress);
const open = connections.get(address) || 0;
const total = [...connections.values()].reduce((sum, count) => sum + count, 0);
// Kept as a counter instead of summing every address on every new socket.
// Under a burst of logins the old O(addresses) work delayed everyone else.
const total = connectionCount;
socket.on("error", () => {});
if (open >= config.maxConnectionsPerAddress || total >= config.maxConnections) {
metrics.rejected++;
socket.destroy();
return;
}
connections.set(address, open + 1);
connectionCount++;
metrics.accepted++;
const session = new Session(socket);
let buffer = Buffer.alloc(0);
@@ -179,11 +186,15 @@ const start = handlers => new Promise((resolve, reject) => {
}
bytesInWindow += chunk.length;
if (bytesInWindow > config.maxBytesPerTenSeconds) {
metrics.floodDisconnects++;
console.log(`[game] ${logText(session.name)} disconnected for flooding`);
socket.destroy();
return;
}
buffer = Buffer.concat([buffer, chunk]);
// Node normally gives complete SmartFox packets in one chunk. Avoiding
// Buffer.concat in that common case reduces allocation and GC during
// busy logins; fragments still retain the exact old behaviour.
buffer = buffer.length === 0 ? chunk : Buffer.concat([buffer, chunk]);
let end;
while ((end = buffer.indexOf(0)) !== -1) {
if (end > MAX_MESSAGE) {
@@ -191,6 +202,7 @@ const start = handlers => new Promise((resolve, reject) => {
return;
}
if (++messagesInWindow > config.maxMessagesPerTenSeconds) {
metrics.floodDisconnects++;
console.log(`[game] ${logText(session.name)} disconnected for flooding`);
socket.destroy();
return;
@@ -201,6 +213,7 @@ const start = handlers => new Promise((resolve, reject) => {
dispatch(session, message);
}
catch (err) {
metrics.handlerErrors++;
// one line a failure, and an end to them: a client that sends
// nonsense in a loop is not to fill the log.
const where = String(err.stack || "").split("\n")[1] || "";
@@ -229,6 +242,7 @@ const start = handlers => new Promise((resolve, reject) => {
else {
connections.delete(address);
}
connectionCount = Math.max(0, connectionCount - 1);
console.log(`[game] ${logText(session.name)} disconnected`);
// nothing thrown while a player is seen off may take the server down.
try {
@@ -277,4 +291,15 @@ const start = handlers => new Promise((resolve, reject) => {
});
});
module.exports = {start};
// This intentionally exposes counts only: staff can see whether the service
// is healthy without receiving player addresses or packet contents.
const health = () => ({
openConnections: connectionCount,
connectedAddresses: connections.size,
accepted: metrics.accepted,
rejected: metrics.rejected,
floodDisconnects: metrics.floodDisconnects,
handlerErrors: metrics.handlerErrors,
});
module.exports = {start, health};