mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 17:37:50 -05:00
feat: stats graphs, playtime, ip search against ban evasion, 150-char chat
- stats graphs for the admin and moderator panels (lib/stats.js, public/stats-view.html) - playtime, private unless shown on the card's bio tab; set on the account page - search accounts by ip address, only against ban evasion; mods see no addresses and each search is logged - privacy policy for the above (terms version 2026-10-17) - the per-second save looks only at accounts in play, with a slow sweep of the rest - items in several dens at once; chat filter hides slurs and threats by default - sexual usernames refused; moderators may enter full rooms; guide login allowed - 150-character chat box (client build 55) - fixes: gifts, trades, dens, pets in dens, den recycling, special animals' colours, jammer walls, settings switches; the buddy list sent at login - the item giver, the rules screen and the art studio rework
This commit is contained in:
1 parent
8400d2f928
commit
04f468af2c
56 files changed
+25667
-3894
No files matched your search
+148
-22
@@ -56,6 +56,10 @@ const MIN_LETTERS = 3; // the client's own rule (SbiConstants.USERNAME_REGEX)
|
||||
const MIN_PASSWORD_LENGTH = 10;
|
||||
const MAX_DEN_SLOTS = 200; // DenSwitch.nextFreeSlotIdx
|
||||
const DEN_OPEN = 2; // den privacy: 0 locked, 1 buddies only, 2 everyone
|
||||
const USER_VAR_SETTINGS = 363; // the settings menu's switches, a bit each (gui.MySettings)
|
||||
// the chat filter an account starts with: level 1 slurs and threats, mode 1
|
||||
// the whole message left out (see account.filter below).
|
||||
const DEFAULT_FILTER = {level: 1, mode: 1, words: ""};
|
||||
const MAX_PASSWORD_LENGTH = 100;
|
||||
// parts of the game a player can switch off for their own account, each
|
||||
// enforced where the game asks for it (featureOn below).
|
||||
@@ -109,7 +113,7 @@ const newAvatar = (ids, name, type, customAvId) => {
|
||||
customAvId: custom ? Number(customAvId) : -1,
|
||||
colors: [def.colorLayer1, Number(custom && custom.overrideColorLayer2) || def.colorLayer2, def.colorLayer3].map(Number),
|
||||
eyes: Number(def.baseEyesId) || 0,
|
||||
pattern: Number(custom ? custom.patternRefId : def.basePatternId) || 0,
|
||||
pattern: Number(custom ? defpacks.customPattern(customAvId) : def.basePatternId) || 0,
|
||||
petInvId: 0,
|
||||
};
|
||||
};
|
||||
@@ -153,6 +157,10 @@ const normalize = account => {
|
||||
account.outfitUndo.avInvId = avatar.avInvId;
|
||||
}
|
||||
}
|
||||
// custom animals made while their pattern list was a 0 (lib/defpacks.js)
|
||||
for (const avatar of account.avatars.filter(candidate => candidate.customAvId !== -1 && !candidate.pattern)) {
|
||||
avatar.pattern = defpacks.customPattern(avatar.customAvId);
|
||||
}
|
||||
account.pets = account.pets || []; // {inv, lBits, uBits, eBits, name, createdAt}
|
||||
account.dens = account.dens || [{inv: 0, def: config.denDefId}]; // den rooms owned
|
||||
account.activeDen = account.activeDen || 0; // inv of the den in use
|
||||
@@ -174,14 +182,34 @@ const normalize = account => {
|
||||
account.activeDen = moved.has(account.activeDen) ? moved.get(account.activeDen) : account.activeDen;
|
||||
for (const item of account.denItems || []) {
|
||||
item.den = moved.has(item.den) ? moved.get(item.den) : item.den;
|
||||
if (item.spots) {
|
||||
item.spots = Object.fromEntries(Object.entries(item.spots).map(([den, spot]) => [moved.has(Number(den)) ? moved.get(Number(den)) : den, spot]));
|
||||
}
|
||||
}
|
||||
}
|
||||
account.denPrivacy = account.denPrivacy === undefined ? DEN_OPEN : account.denPrivacy;
|
||||
account.denItems = account.denItems || []; // {inv, def, version, placed, den, x, y, flip, mannequin?, image?}: lib/dens.js
|
||||
// {inv, def, version, spots, mannequin?, image?}: lib/dens.js. spots: where
|
||||
// it stands, {den inventory id: {cat, x, y, flip}}, as many dens as it is in.
|
||||
account.denItems = account.denItems || [];
|
||||
for (const item of account.denItems) {
|
||||
item.den = item.den === undefined ? account.activeDen : item.den; // which den it is placed in
|
||||
// from when an item stood in one den at most: {placed, den, x, y, flip, cat}.
|
||||
if (!item.spots) {
|
||||
const den = item.den === undefined ? account.activeDen : item.den;
|
||||
item.spots = item.placed ? {[den]: {cat: item.cat || 1, x: item.x || 0, y: item.y || 0, flip: item.flip || 0}} : {};
|
||||
}
|
||||
for (const old of ["placed", "den", "x", "y", "flip", "cat"]) {
|
||||
delete item[old];
|
||||
}
|
||||
}
|
||||
account.userVars = account.userVars || {};
|
||||
// the settings menu's switches (user var 363) were once stored as the
|
||||
// number of the last switch touched rather than as bits: such a value
|
||||
// cannot be told from a real one, so every account starts again from the
|
||||
// game's defaults, once.
|
||||
if (!account.settingsBitsFixed) {
|
||||
delete account.userVars[USER_VAR_SETTINGS];
|
||||
account.settingsBitsFixed = true;
|
||||
}
|
||||
account.theme = account.theme || ""; // seasonal look of the lands, see themes in config.js
|
||||
account.lastSeen = account.lastSeen || 0; // when they last left the game, in seconds; 0 = never recorded
|
||||
// what the player set on the account page (lib/manage.js).
|
||||
@@ -219,12 +247,25 @@ const normalize = account => {
|
||||
account.discord = typeof account.discord === "string" ? account.discord : ""; // their Discord username, as they gave it
|
||||
account.badges = Array.isArray(account.badges) ? account.badges : []; // badge ids, given in the admin panel
|
||||
account.bio = typeof account.bio === "string" ? account.bio : ""; // their own words, for the card's Bio tab
|
||||
// seconds spent in the game in all (lib/world.js counts it), and whether
|
||||
// their card shows it to others: theirs to choose on the account page.
|
||||
account.playtime = Number.isFinite(account.playtime) && account.playtime > 0 ? Math.floor(account.playtime) : 0;
|
||||
account.playtimePublic = account.playtimePublic === true;
|
||||
// the chat filter, which the player's own game applies (AJClient in the
|
||||
// patched SWF; "xfl" in lib/world.js): {level: 1 slurs and threats, 2
|
||||
// swearing too, 0 off; mode: 0 stars over the words, 1 the message left
|
||||
// out; words: their own, commas between; chosen: have they been asked}.
|
||||
// an account that has not chosen has no filter: that is the start.
|
||||
account.filter = account.filter && typeof account.filter === "object" && account.filter.chosen ? account.filter : {level: 0, mode: 0, words: "", chosen: false};
|
||||
// an account starts with slurs and threats hidden, and may turn it off.
|
||||
account.filter = account.filter && typeof account.filter === "object" && account.filter.chosen ? account.filter : {...DEFAULT_FILTER, chosen: false};
|
||||
// that default came after accounts that had none, or had turned it off:
|
||||
// they get it too, once. a stricter level, and the way it is shown when
|
||||
// they had one, stay as they were.
|
||||
if (!account.filterDefaultApplied) {
|
||||
if (!(account.filter.level >= DEFAULT_FILTER.level)) {
|
||||
Object.assign(account.filter, {level: DEFAULT_FILTER.level, mode: DEFAULT_FILTER.mode});
|
||||
}
|
||||
account.filterDefaultApplied = true;
|
||||
}
|
||||
// two-step sign-in: lib/totp.js.
|
||||
account.totp = account.totp || null;
|
||||
account.totpSetup = account.totpSetup || null;
|
||||
@@ -245,11 +286,13 @@ const MAX_START_ROOM = 80;
|
||||
function setLoginChoices(account, choices) {
|
||||
const asked = config.loginChoices && choices && typeof choices === "object" ? choices : {};
|
||||
const whole = (value, max) => Number.isInteger(value) && value >= 0 && value <= max;
|
||||
// member or not is the player's own choice on any server, the rest only
|
||||
// with config.loginChoices: another account type shows to everyone.
|
||||
const type = choices && typeof choices === "object" && MEMBERSHIP_TYPES.includes(choices.accountType) ? choices.accountType : asked.accountType;
|
||||
// member or not, and guide or not, are the player's own choice on any
|
||||
// server; the rest only with config.loginChoices: another account type
|
||||
// shows to everyone.
|
||||
const own = choices && typeof choices === "object" ? choices : {};
|
||||
const type = MEMBERSHIP_TYPES.includes(own.accountType) ? own.accountType : asked.accountType;
|
||||
account.accountType = whole(type, MAX_ACCOUNT_TYPE) ? type : config.defaultAccountType;
|
||||
account.isGuide = asked.isGuide === true;
|
||||
account.isGuide = own.isGuide === true;
|
||||
account.isModerator = asked.isModerator === true;
|
||||
account.membershipDays = whole(asked.membershipDays, MAX_MEMBERSHIP_DAYS) ? asked.membershipDays : DEFAULT_MEMBERSHIP_DAYS;
|
||||
// where to start is the player's to say on any server: their own den in
|
||||
@@ -277,6 +320,7 @@ const insert = (username, salt, hash, createdAt, state) => {
|
||||
account.id = Number(result.lastInsertRowid);
|
||||
savedState.set(account.id, json);
|
||||
remember(account);
|
||||
touch(account);
|
||||
return account;
|
||||
};
|
||||
|
||||
@@ -371,20 +415,101 @@ const load = () => {
|
||||
console.log(`[accounts] ${byKey.size} accounts in ${path.join(config.dataDir, "game.sqlite")}`);
|
||||
};
|
||||
|
||||
// Which accounts the save after a message looks at. turning an account into
|
||||
// JSON to see whether it changed costs, and doing it for every account there
|
||||
// is, a second after nearly every message, held the whole server up for
|
||||
// longer the more accounts there were: a second and more, for everyone. so
|
||||
// it looks at the accounts in play: online ones (hold, from lib/world.js),
|
||||
// and ones looked up lately (by name, id, token, password: how the admin
|
||||
// panel, buddies and the like get at an offline account), until a save
|
||||
// finds them written and WARM_MS has gone by. the rest are looked at a few
|
||||
// at a time behind those (SWEEP_BUDGET_MS a save), round and round, for
|
||||
// what reached an account some other way (accounts.all()). a stop of the
|
||||
// server, and every flush() called by name, looks at all of them.
|
||||
const WARM_MS = 10 * 60 * 1000;
|
||||
const SWEEP_BUDGET_MS = 5;
|
||||
const held = new Set(); // accounts online
|
||||
const warm = new Map(); // account -> when last looked up
|
||||
let sweepOrder = [];
|
||||
let sweepAt = 0;
|
||||
let sweepLeft = 0; // accounts the sweep still has to look at since the last save()
|
||||
const touch = account => {
|
||||
if (account) {
|
||||
warm.set(account, Date.now());
|
||||
}
|
||||
return account;
|
||||
};
|
||||
const hold = account => {
|
||||
held.add(account);
|
||||
touch(account);
|
||||
};
|
||||
const release = account => {
|
||||
held.delete(account);
|
||||
touch(account);
|
||||
};
|
||||
|
||||
const changedState = (account, changed) => {
|
||||
const json = stateJson(account);
|
||||
if (savedState.get(account.id) !== json) {
|
||||
changed.push([account.id, json]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// writes every account whose state changed since it was last written, in
|
||||
// one transaction.
|
||||
const flush = () => {
|
||||
// one transaction; with {some: true}, of the accounts in play and the
|
||||
// sweep's next few (above).
|
||||
const flush = ({some = false} = {}) => {
|
||||
clearTimeout(saveTimer);
|
||||
saveTimer = null;
|
||||
if (!db) {
|
||||
return;
|
||||
}
|
||||
const changed = [];
|
||||
for (const account of byId.values()) {
|
||||
const json = stateJson(account);
|
||||
if (savedState.get(account.id) !== json) {
|
||||
changed.push([account.id, json]);
|
||||
if (some) {
|
||||
const now = Date.now();
|
||||
const looked = new Set();
|
||||
for (const account of held) {
|
||||
looked.add(account);
|
||||
changedState(account, changed);
|
||||
}
|
||||
for (const [account, at] of warm) {
|
||||
if (looked.has(account)) {
|
||||
continue;
|
||||
}
|
||||
looked.add(account);
|
||||
if (byId.get(account.id) !== account) {
|
||||
warm.delete(account); // removed
|
||||
}
|
||||
else if (!changedState(account, changed) && now - at > WARM_MS && !held.has(account)) {
|
||||
warm.delete(account);
|
||||
}
|
||||
}
|
||||
const started = process.hrtime.bigint();
|
||||
while (sweepLeft > 0 && Number(process.hrtime.bigint() - started) / 1e6 < SWEEP_BUDGET_MS) {
|
||||
if (sweepAt >= sweepOrder.length) {
|
||||
sweepOrder = [...byId.values()];
|
||||
sweepAt = 0;
|
||||
if (sweepOrder.length === 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
const account = sweepOrder[sweepAt++];
|
||||
sweepLeft--;
|
||||
if (!looked.has(account) && byId.get(account.id) === account) {
|
||||
changedState(account, changed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const account of byId.values()) {
|
||||
changedState(account, changed);
|
||||
}
|
||||
sweepLeft = 0;
|
||||
}
|
||||
if (sweepLeft > 0) {
|
||||
save(); // the sweep goes on in a moment
|
||||
}
|
||||
if (changed.length === 0) {
|
||||
return;
|
||||
@@ -415,10 +540,11 @@ const flush = () => {
|
||||
const SAVE_DELAY_MS = 1000;
|
||||
let saveTimer = null;
|
||||
const save = () => {
|
||||
sweepLeft = byId.size;
|
||||
if (saveTimer === null) {
|
||||
saveTimer = setTimeout(() => {
|
||||
try {
|
||||
flush();
|
||||
flush({some: true});
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`[accounts] could not save: ${err.message}`);
|
||||
@@ -512,7 +638,7 @@ const register = (username, password, avatar = {}) => {
|
||||
|
||||
const authenticate = (username, password) => {
|
||||
// "name" and "name " are the same account.
|
||||
const account = typeof username === "string" ? byKey.get(username.trim().toLowerCase()) : null;
|
||||
const account = typeof username === "string" ? touch(byKey.get(username.trim().toLowerCase())) : null;
|
||||
if (typeof password !== "string" || !password) {
|
||||
return null;
|
||||
}
|
||||
@@ -534,7 +660,7 @@ const authenticate = (username, password) => {
|
||||
|
||||
// the same, with the password worked out off the main thread (above).
|
||||
const authenticateAsync = async (username, password) => {
|
||||
const account = typeof username === "string" ? byKey.get(username.trim().toLowerCase()) : null;
|
||||
const account = typeof username === "string" ? touch(byKey.get(username.trim().toLowerCase())) : null;
|
||||
if (typeof password !== "string" || !password || password.length > MAX_PASSWORD_LENGTH) {
|
||||
return null;
|
||||
}
|
||||
@@ -684,15 +810,15 @@ const issueToken = account => {
|
||||
|
||||
const byToken = token => {
|
||||
const entry = typeof token === "string" && token.length === TOKEN_HEX_LENGTH ? tokens.get(tokenHash(token)) : null;
|
||||
return entry && !tokenExpired(entry.createdAt) ? byId.get(entry.id) || null : null;
|
||||
return entry && !tokenExpired(entry.createdAt) ? touch(byId.get(entry.id)) || null : null;
|
||||
};
|
||||
|
||||
const byName = username => byKey.get(String(username).toLowerCase()) || null;
|
||||
const byName = username => touch(byKey.get(String(username).toLowerCase())) || null;
|
||||
|
||||
const accountById = id => byId.get(Number(id)) || null;
|
||||
const accountById = id => touch(byId.get(Number(id))) || null;
|
||||
|
||||
const all = () => [...byId.values()];
|
||||
|
||||
const database = () => db;
|
||||
|
||||
module.exports = {FEATURES, featureOn, recordLogin, revokeTokens, load, save, flush, startBackups, database, setLoginChoices, setPassword, rename, remove, setting, setSetting, hashPassword, register, usernameProblem, authenticate, authenticateAsync, issueToken, byToken, byName, byId: accountById, newAvatar, freeAvatarSlot, all};
|
||||
module.exports = {FEATURES, featureOn, recordLogin, revokeTokens, load, save, flush, hold, release, startBackups, database, setLoginChoices, setPassword, rename, remove, setting, setSetting, hashPassword, register, usernameProblem, authenticate, authenticateAsync, issueToken, byToken, byName, byId: accountById, newAvatar, freeAvatarSlot, all};
|
||||
Reference in new issue
Block a user