mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 01:27:51 -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
+93
-20
@@ -32,6 +32,7 @@ const tradeHandlers = require("./trades.js");
|
||||
const stubHandlers = require("./stubs.js");
|
||||
const wallModule = require("./walls.js");
|
||||
const worldItems = require("./worlditems.js");
|
||||
const stats = require("./stats.js");
|
||||
const {CURRENCIES, DIAMOND_TYPES, activeAvatar, avatarById, activePet, equippedBits, wornItems, lastSeenField} = require("./player.js");
|
||||
|
||||
// game logic behind the socket. field orders below mirror the client's
|
||||
@@ -86,6 +87,9 @@ const USER_VAR_DEN_TUTORIAL = 379;
|
||||
const USER_VAR_TRADE_TUTORIAL = 129;
|
||||
const TUTORIALS_ALL_SEEN = 65535;
|
||||
const BIT_FLAG_VARS = [USER_VAR_DEN_TUTORIAL, USER_VAR_TRADE_TUTORIAL];
|
||||
// the settings menu's switches, a bit each (gui.MySettings): the client sends
|
||||
// the bit's number and 1 to set it or 0 to clear it. unset is -1, every bit clear.
|
||||
const USER_VAR_SETTINGS = 363;
|
||||
const GEM_BONUS_NEVER_DUE = 65535;
|
||||
// pets the pet picker must not offer (PetCreator.onNotViewablePetDefsLoaded); none here.
|
||||
const GENERIC_LIST_HIDDEN_PETS = 574;
|
||||
@@ -276,7 +280,11 @@ const login = (session, msg) => {
|
||||
leaveWorld(existing);
|
||||
}
|
||||
session.account = account;
|
||||
accounts.hold(account);
|
||||
account.numLogins++;
|
||||
session.playingSince = Date.now();
|
||||
session.playStarted = Date.now();
|
||||
stats.login(account, account.numLogins === 1);
|
||||
accounts.recordLogin(account, "game", session.address);
|
||||
account.lastLogin = Math.floor(Date.now() / 1000);
|
||||
session.recentChat = [];
|
||||
@@ -440,6 +448,27 @@ const sendUserVars = session => {
|
||||
|
||||
const findOnline = username => online.get(String(username).toLowerCase());
|
||||
|
||||
// a custom colour (lib/colours.js) for these four RGB values, made if it is
|
||||
// new and the account has not made its day's worth; everyone online is told
|
||||
// of a new one before anybody can be given it, and `asker` (a session) of an
|
||||
// old one. returns what colours.allocate does.
|
||||
const makeColour = (account, rgbs, asker = null) => {
|
||||
const today = Math.floor(Date.now() / 86400000);
|
||||
const made = account.coloursMade && account.coloursMade.day === today ? account.coloursMade.count : 0;
|
||||
const entry = colours.allocate(rgbs, made < config.customColoursPerDay);
|
||||
if (!entry || entry.full) {
|
||||
return entry;
|
||||
}
|
||||
if (entry.created) {
|
||||
account.coloursMade = {day: today, count: made + 1};
|
||||
accounts.save();
|
||||
}
|
||||
for (const recipient of entry.created ? online.values() : asker ? [asker] : []) {
|
||||
recipient.sendXt("xcc", -1, 1, entry.id, ...entry.rgbs);
|
||||
}
|
||||
return entry;
|
||||
};
|
||||
|
||||
// the account's chat filter, for its game to apply: [chosen, level, mode, own words].
|
||||
const sendFilter = session => {
|
||||
const {filter} = session.account;
|
||||
@@ -478,23 +507,9 @@ const handlers = {
|
||||
// A colour somebody made before is anybody's to use; a new one counts
|
||||
// against the day's allowance of whoever asks (config.customColoursPerDay).
|
||||
xcc(session, roomId, params) {
|
||||
const {account} = session;
|
||||
const today = Math.floor(Date.now() / 86400000);
|
||||
const made = account.coloursMade && account.coloursMade.day === today ? account.coloursMade.count : 0;
|
||||
const entry = colours.allocate(params.slice(0, 4).map(Number), made < config.customColoursPerDay);
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
if (entry.full) {
|
||||
const entry = makeColour(session.account, params.slice(0, 4).map(Number), session);
|
||||
if (entry && entry.full) {
|
||||
tell(session, "No more new colours today. Colours made before can still be used.");
|
||||
return;
|
||||
}
|
||||
if (entry.created) {
|
||||
account.coloursMade = {day: today, count: made + 1};
|
||||
accounts.save();
|
||||
}
|
||||
for (const recipient of entry.created ? online.values() : [session]) {
|
||||
recipient.sendXt("xcc", -1, 1, entry.id, ...entry.rgbs);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -714,7 +729,7 @@ const handlers = {
|
||||
|
||||
// AchievementXtCommManager.requestSetUserVar: [varId, value, ?]. the reply
|
||||
// (setUserVarResponse) is [varId, value, newAchievementCount].
|
||||
zs(session, roomId, [id, value]) {
|
||||
zs(session, roomId, [id, value, set]) {
|
||||
if (!/^\d{1,4}$/.test(id) || !Number.isFinite(Number(value))) {
|
||||
return;
|
||||
}
|
||||
@@ -731,6 +746,14 @@ const handlers = {
|
||||
else if (BIT_FLAG_VARS.includes(Number(id))) {
|
||||
vars[id] = TUTORIALS_ALL_SEEN;
|
||||
}
|
||||
else if (Number(id) === USER_VAR_SETTINGS) {
|
||||
const bit = Number(value);
|
||||
if (!Number.isInteger(bit) || bit < 0 || bit > 30) {
|
||||
return;
|
||||
}
|
||||
const bits = Math.max(0, Number(vars[id]) || 0);
|
||||
vars[id] = set === "0" ? bits & ~(1 << bit) : bits | (1 << bit);
|
||||
}
|
||||
else if (achievements.counts(id)) {
|
||||
// A var that achievements count in: the games report "one more" as 1
|
||||
// and a best score as the score, and the official server knew which
|
||||
@@ -818,7 +841,7 @@ const handlers = {
|
||||
// the icons after the name, and their bio, for the Bio tab
|
||||
// (lib/badges.js).
|
||||
session.sendXt("xbn", -1, account.username, moderation.banRemaining(account), account.createdAt,
|
||||
account.discord, badges.cardField(account), account.bio);
|
||||
account.discord, badges.cardField(account), cardBio(account));
|
||||
}
|
||||
},
|
||||
|
||||
@@ -931,6 +954,46 @@ const leaveRoom = session => {
|
||||
}
|
||||
};
|
||||
|
||||
// the Bio tab's words: the bio, under the time played when the player
|
||||
// shows it (their account page). the card makes the words smaller to fit.
|
||||
const playedText = seconds => {
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
if (hours >= 1) {
|
||||
return `Played ${hours.toLocaleString("en-US")} hour${hours === 1 ? "" : "s"}`;
|
||||
}
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
return `Played ${minutes} minute${minutes === 1 ? "" : "s"}`;
|
||||
};
|
||||
const cardBio = account => {
|
||||
if (!account.playtimePublic) {
|
||||
return account.bio;
|
||||
}
|
||||
const session = online.get(account.username.toLowerCase());
|
||||
if (session) {
|
||||
countPlaytime(session);
|
||||
}
|
||||
return account.bio ? `${playedText(account.playtime)}\n\n${account.bio}` : playedText(account.playtime);
|
||||
};
|
||||
|
||||
// the time since it was last counted, added to the account's playtime.
|
||||
const countPlaytime = session => {
|
||||
if (session.account && session.playingSince) {
|
||||
const elapsed = Date.now() - session.playingSince;
|
||||
session.account.playtime += Math.floor(elapsed / 1000);
|
||||
session.playingSince = Date.now() - (elapsed % 1000);
|
||||
}
|
||||
};
|
||||
// counted every minute too, so that a server that stops without warning
|
||||
// loses no more than that, and what others see is never far behind.
|
||||
setInterval(() => {
|
||||
for (const session of online.values()) {
|
||||
countPlaytime(session);
|
||||
}
|
||||
if (online.size > 0) {
|
||||
accounts.save();
|
||||
}
|
||||
}, 60000).unref();
|
||||
|
||||
const leaveWorld = session => {
|
||||
minigames.leave(session);
|
||||
trades.forget(session);
|
||||
@@ -938,6 +1001,9 @@ const leaveWorld = session => {
|
||||
if (session.account && online.get(session.account.username.toLowerCase()) === session) {
|
||||
online.delete(session.account.username.toLowerCase());
|
||||
session.account.lastSeen = Math.floor(Date.now() / 1000);
|
||||
countPlaytime(session);
|
||||
stats.session(session.account, (Date.now() - session.playStarted) / 1000);
|
||||
accounts.release(session.account);
|
||||
accounts.save();
|
||||
buddies.announce(session.account);
|
||||
}
|
||||
@@ -1023,7 +1089,8 @@ const enterRoom = (session, name, base, displayName, shardId, props = {}) => {
|
||||
if (room && room === session.room) {
|
||||
return;
|
||||
}
|
||||
if (room && room.sessions.size >= config.maxUsersPerRoom) {
|
||||
// moderators (marked so in the admin panel) are let into a full room.
|
||||
if (room && room.sessions.size >= config.maxUsersPerRoom && !session.account.moderator) {
|
||||
joinFailed(session, "This room is currently full");
|
||||
return;
|
||||
}
|
||||
@@ -1151,6 +1218,11 @@ const joinRoom = (session, requested) => {
|
||||
// reply says; a starting room in the flashvars it does not honour).
|
||||
if (!session.arrived) {
|
||||
session.arrived = true;
|
||||
// the client asks for its buddy list only when a window wants it
|
||||
// (BuddyList.requestBuddyListIfNeeded), and draws every name tag as a
|
||||
// non-buddy's until then: it is sent ahead of the first room, as the
|
||||
// client takes it unasked (BuddyManager.buddyListResponseHandler).
|
||||
handlers.bl(session);
|
||||
const {startInDen, startRoom, username} = session.account;
|
||||
const den = startInDen ? username : /^den/i.test(startRoom || "") ? startRoom.slice(3) : null;
|
||||
if (den !== null && accounts.byName(den)) {
|
||||
@@ -1317,6 +1389,7 @@ module.exports = {
|
||||
close: leaveWorld,
|
||||
|
||||
findOnline,
|
||||
makeColour,
|
||||
sendItemList,
|
||||
setTheme,
|
||||
// offers left on the account page (lib/trades.js); `refresh` shows a
|
||||
@@ -1447,7 +1520,7 @@ module.exports = {
|
||||
continue;
|
||||
}
|
||||
changed.add(account);
|
||||
if (held.some(item => item.placed)) {
|
||||
if (held.some(dens.isPlaced)) {
|
||||
shownIn.push(rooms.get(`den${account.username}`));
|
||||
}
|
||||
account.denItems = account.denItems.filter(item => item.image !== painting.id);
|
||||
|
||||
Reference in new issue
Block a user