mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat: discord linking, @tags, music and sfx sliders, required device ids
- Discord: the account page links a player's Discord account through Discord's sign-in (lib/discord.js); only linked names are shown on cards (typed ones are cleared). A bot keeps the Server Booster badge on linked accounts that boost. The game tells the client where the player is, for the client's Discord rich presence (flashvars discordAppId). - @username tags in chat, chat balloons and wall posts: only real players' names (asked of the server, "xmn"), names with spaces too, drawn on a blue box; a click opens the player's card. - Settings: separate Music and SFX volume sliders for the old one. - Device ids required: a launcher that sends none (before 1.3.0) is told at the game's login "Your client is outdated. Update at https://burrow.moe/download". AJ_REQUIRE_DEVICE=0 turns it off. - Panels: clear a player's Jammer Wall posts; turning away masterpieces and player items asks first. - Item Giver: negative colour ids (the same colour written signed). - buildVersion 71; the client rebuilt with Snipzil's sitting fix.
This commit is contained in:
1 parent
1d9b70f32e
commit
33f56074a4
35 files changed
+2076
-101
No files matched your search
+12
-2
@@ -245,7 +245,10 @@ const normalize = account => {
|
||||
account.nameBarData = Number.isInteger(account.nameBarData) ? account.nameBarData : 0;
|
||||
account.disguise = Number.isInteger(account.disguise) ? account.disguise : 0; // NPC id, see lib/disguises.js
|
||||
// shown on the player's card: lib/badges.js.
|
||||
account.discord = typeof account.discord === "string" ? account.discord : ""; // their Discord username, as they gave it
|
||||
account.discord = typeof account.discord === "string" ? account.discord : ""; // their Discord username, as Discord gave it (lib/discord.js)
|
||||
if (account.discordId !== undefined && !/^\d{5,25}$/.test(String(account.discordId))) {
|
||||
delete account.discordId; // the linked Discord account's id
|
||||
}
|
||||
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
|
||||
@@ -905,10 +908,17 @@ const byToken = token => {
|
||||
|
||||
const byName = username => touch(byKey.get(String(username).toLowerCase())) || null;
|
||||
|
||||
// a username as its account spells it, or null. only asks whether there is
|
||||
// one: unlike byName it does not count as the account being in use.
|
||||
const nameOf = username => {
|
||||
const account = byKey.get(String(username).toLowerCase());
|
||||
return account ? account.username : 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, hold, release, 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, nameOf, byId: accountById, newAvatar, freeAvatarSlot, all};
|
||||
@@ -110,6 +110,12 @@ const give = (body, seesLocked = false) => {
|
||||
}
|
||||
custom = String(entry.id);
|
||||
}
|
||||
// a colour id written signed, as lists of the game's colours often do
|
||||
// them: the same 32 bits, kept as the game keeps colours (unsigned), so
|
||||
// -16777216 is 4278190080.
|
||||
if (/^-\d{1,10}$/.test(custom) && Number(custom) >= -0x80000000) {
|
||||
custom = String(Number(custom) >>> 0);
|
||||
}
|
||||
if (custom && !isUint(custom)) {
|
||||
return {status: 400, body: {error: "Colour: an id, or #RRGGBB"}};
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ const set = (account, ids) => {
|
||||
};
|
||||
|
||||
// A Discord username as Discord has them now: 2 to 32 of a-z, 0-9, "_" and
|
||||
// ".", with no two dots in a row. nobody checks that it is theirs.
|
||||
// ".", with no two dots in a row. players link theirs (lib/discord.js).
|
||||
const DISCORD_NAME = /^(?!.*\.\.)[a-z0-9_.]{2,32}$/;
|
||||
|
||||
// returns the username as it will be kept ("" for none), or null when it
|
||||
|
||||
@@ -144,6 +144,9 @@ const withRestoredParties = pack => {
|
||||
// text of our own, for things the game has no string for. added to the
|
||||
// English localization pack under ids far above the game's (about 41,000).
|
||||
const ADDED_STRINGS = {
|
||||
// the login popup for a launcher too old to send device ids (lib/world.js
|
||||
// LOGIN_OUTDATED), in place of "Your account is currently under maintenance."
|
||||
11198: "Your client is outdated. Update at https://burrow.moe/download",
|
||||
9000001: "Castle (2010 draft)",
|
||||
9000002: "Water Park (three slides)",
|
||||
9000003: "Water Park (five slides)",
|
||||
|
||||
+22
-1
@@ -397,4 +397,25 @@ const forget = account => {
|
||||
db().prepare("DELETE FROM device_alerts WHERE account_id = ?").run(account.id);
|
||||
};
|
||||
|
||||
module.exports = {load, read, banOf, banOfAccount, seen, alts, knownFor, banAccount, accountsUnder, unban, list, idsFor, bansOfAccount, search, bannedId, alerts, alertsOf, forget, clientHash};
|
||||
// sign-in tokens last given to (or brought back by) a launcher that sent no
|
||||
// device ids: one from before 1.3.0, or not ours. with config.requireDevice
|
||||
// its sign-in still goes through, so that the game loads and its own login
|
||||
// popup can say to update (lib/world.js), which a refused sign-in cannot.
|
||||
// kept by hash, in memory: such a launcher signs in again each time it starts.
|
||||
const MAX_OUTDATED = 20000;
|
||||
const outdatedTokens = new Set();
|
||||
const tokenKey = token => crypto.createHash("sha256").update(String(token)).digest("hex");
|
||||
const noteLauncher = (token, hasIds) => {
|
||||
const key = tokenKey(token);
|
||||
if (hasIds) {
|
||||
outdatedTokens.delete(key);
|
||||
return;
|
||||
}
|
||||
if (outdatedTokens.size >= MAX_OUTDATED) {
|
||||
outdatedTokens.delete(outdatedTokens.values().next().value);
|
||||
}
|
||||
outdatedTokens.add(key);
|
||||
};
|
||||
const launcherOutdated = token => outdatedTokens.has(tokenKey(token));
|
||||
|
||||
module.exports = {noteLauncher, launcherOutdated, load, read, banOf, banOfAccount, seen, alts, knownFor, banAccount, accountsUnder, unban, list, idsFor, bansOfAccount, search, bannedId, alerts, alertsOf, forget, clientHash};
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
"use strict";
|
||||
|
||||
const crypto = require("crypto");
|
||||
const {logText} = require("./logtext.js");
|
||||
const accounts = require("./accounts.js");
|
||||
const badges = require("./badges.js");
|
||||
const config = require("../config.js");
|
||||
|
||||
// a player's Discord account, linked on the account page by signing in to
|
||||
// Discord (OAuth2, scope "identify"): the only way a Discord username gets
|
||||
// onto a player's card, so the name shown is theirs. one Discord account
|
||||
// for one Burrow account, or a single boost would badge a player's every
|
||||
// account.
|
||||
//
|
||||
// the Discord Server Booster badge follows the linked account: given while
|
||||
// it boosts Burrow's Discord server, taken off when it stops, checked when
|
||||
// the account is linked and again every RECHECK_HOURS. Burrow's bot asks
|
||||
// Discord (GET /guilds/<id>/members/<user id>, which needs no privileged
|
||||
// intent: the bot only has to be in the server). an account that is not
|
||||
// linked keeps whatever badges the admin gave it.
|
||||
//
|
||||
// with AJ_DISCORD_CLIENT_ID and AJ_DISCORD_CLIENT_SECRET unset, linking is
|
||||
// off; without AJ_DISCORD_BOT_TOKEN and AJ_DISCORD_GUILD_ID, the booster
|
||||
// badge is left alone.
|
||||
|
||||
const API = "https://discord.com/api/v10";
|
||||
const AUTHORIZE = "https://discord.com/oauth2/authorize";
|
||||
const STATE_MINUTES = 10;
|
||||
const MAX_STATES = 10000;
|
||||
const RECHECK_HOURS = 6;
|
||||
const RECHECK_GAP_MS = 300; // between two members asked about, under Discord's rate limit
|
||||
const TIMEOUT_MS = 15000;
|
||||
const BOOSTER = "booster";
|
||||
|
||||
const linking = () => Boolean(config.discord.clientId && config.discord.clientSecret);
|
||||
const boostChecks = () => Boolean(config.discord.botToken && config.discord.guildId);
|
||||
const redirectUri = () => `${config.siteUrl}account/discord/callback`;
|
||||
|
||||
// a link under way: state (in Discord's address) -> {accountId, nonce (in a
|
||||
// cookie of the browser that asked), expires}. both must come back.
|
||||
const states = new Map();
|
||||
|
||||
const start = account => {
|
||||
for (const [state, entry] of states) {
|
||||
if (entry.expires < Date.now()) {
|
||||
states.delete(state);
|
||||
}
|
||||
}
|
||||
if (states.size >= MAX_STATES) {
|
||||
states.delete(states.keys().next().value);
|
||||
}
|
||||
const state = crypto.randomBytes(24).toString("hex");
|
||||
const nonce = crypto.randomBytes(24).toString("hex");
|
||||
states.set(state, {accountId: account.id, nonce, expires: Date.now() + STATE_MINUTES * 60000});
|
||||
const url = new URL(AUTHORIZE);
|
||||
url.search = new URLSearchParams({client_id: config.discord.clientId, response_type: "code", scope: "identify",
|
||||
redirect_uri: redirectUri(), state, prompt: "consent"}).toString();
|
||||
return {url: url.href, nonce};
|
||||
};
|
||||
|
||||
const call = async (path, options = {}) => {
|
||||
const res = await fetch(`${API}${path}`, {...options, signal: AbortSignal.timeout(TIMEOUT_MS)});
|
||||
const body = await res.json().catch(() => ({}));
|
||||
return {status: res.status, body};
|
||||
};
|
||||
|
||||
// how a Discord username is kept and shown: as Discord spells them now, or,
|
||||
// for an old "name#1234" one, without the characters a card cannot carry.
|
||||
const shownName = user => badges.discordName(user.username)
|
||||
|| `${String(user.username).replace(/[,|%\s]/g, "")}${user.discriminator && user.discriminator !== "0" ? `#${user.discriminator}` : ""}`.slice(0, 40);
|
||||
|
||||
const setBooster = (account, on) => {
|
||||
if (account.badges.includes(BOOSTER) === on) {
|
||||
return false;
|
||||
}
|
||||
badges.set(account, on ? [...account.badges, BOOSTER] : account.badges.filter(id => id !== BOOSTER));
|
||||
return true;
|
||||
};
|
||||
|
||||
// whether the linked account boosts the server now: true, false, or null
|
||||
// when Discord could not be asked.
|
||||
const boosting = async account => {
|
||||
if (!boostChecks() || !account.discordId) {
|
||||
return null;
|
||||
}
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
const {status, body} = await call(`/guilds/${config.discord.guildId}/members/${account.discordId}`,
|
||||
{headers: {Authorization: `Bot ${config.discord.botToken}`}}).catch(() => ({status: 0, body: {}}));
|
||||
if (status === 200) {
|
||||
return Boolean(body.premium_since);
|
||||
}
|
||||
if (status === 404) {
|
||||
return false; // not in the server (any more)
|
||||
}
|
||||
if (status === 429) {
|
||||
await new Promise(resolve => setTimeout(resolve, Math.min(60, Number(body.retry_after) || 5) * 1000));
|
||||
continue;
|
||||
}
|
||||
console.log(`[discord] could not check ${logText(account.username)}'s boost: ${logText(status)}`);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const checkBoost = async account => {
|
||||
const on = await boosting(account);
|
||||
if (on !== null && setBooster(account, on)) {
|
||||
accounts.save(account);
|
||||
console.log(`[discord] ${logText(account.username)} ${on ? "boosts: booster badge given" : "no longer boosts: booster badge taken off"}`);
|
||||
}
|
||||
};
|
||||
|
||||
// the end of a link: the code Discord gave, for the state and the nonce the
|
||||
// browser brought back. {ok, account} or {error}.
|
||||
const finish = async (state, nonce, code) => {
|
||||
const entry = typeof state === "string" ? states.get(state) : null;
|
||||
states.delete(state);
|
||||
const digest = text => crypto.createHash("sha256").update(String(text)).digest();
|
||||
if (!entry || entry.expires < Date.now() || typeof nonce !== "string" || !crypto.timingSafeEqual(digest(entry.nonce), digest(nonce))) {
|
||||
return {error: "expired"};
|
||||
}
|
||||
const account = accounts.byId(entry.accountId);
|
||||
if (!account || typeof code !== "string" || !code) {
|
||||
return {error: "expired"};
|
||||
}
|
||||
try {
|
||||
const token = await call("/oauth2/token", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/x-www-form-urlencoded"},
|
||||
body: new URLSearchParams({client_id: config.discord.clientId, client_secret: config.discord.clientSecret,
|
||||
grant_type: "authorization_code", code, redirect_uri: redirectUri()}).toString(),
|
||||
});
|
||||
if (token.status !== 200 || !token.body.access_token) {
|
||||
return {error: "discord"};
|
||||
}
|
||||
const me = await call("/users/@me", {headers: {Authorization: `Bearer ${token.body.access_token}`}});
|
||||
if (me.status !== 200 || !/^\d{5,25}$/.test(String(me.body.id))) {
|
||||
return {error: "discord"};
|
||||
}
|
||||
const id = String(me.body.id);
|
||||
if (accounts.all().some(other => other !== account && other.discordId === id)) {
|
||||
return {error: "taken"};
|
||||
}
|
||||
account.discordId = id;
|
||||
account.discord = shownName(me.body);
|
||||
accounts.save(account);
|
||||
console.log(`[discord] ${logText(account.username)} linked Discord ${logText(account.discord)} (${logText(id)})`);
|
||||
await checkBoost(account);
|
||||
return {ok: true, account};
|
||||
}
|
||||
catch (err) {
|
||||
console.log(`[discord] link failed: ${logText(err.message)}`);
|
||||
return {error: "discord"};
|
||||
}
|
||||
};
|
||||
|
||||
// the link undone, by the player or an admin; the booster badge goes with it.
|
||||
const unlink = account => {
|
||||
const had = Boolean(account.discordId || account.discord);
|
||||
delete account.discordId;
|
||||
account.discord = "";
|
||||
if (had) {
|
||||
setBooster(account, false);
|
||||
}
|
||||
accounts.save(account);
|
||||
return had;
|
||||
};
|
||||
|
||||
// every linked account in turn, a little apart, again and again.
|
||||
let rechecking = false;
|
||||
const recheckAll = async () => {
|
||||
if (rechecking || !boostChecks()) {
|
||||
return;
|
||||
}
|
||||
rechecking = true;
|
||||
try {
|
||||
for (const account of accounts.all().filter(one => one.discordId)) {
|
||||
await checkBoost(account);
|
||||
await new Promise(resolve => setTimeout(resolve, RECHECK_GAP_MS));
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rechecking = false;
|
||||
}
|
||||
};
|
||||
|
||||
// at start: Discord usernames typed in by hand before linking existed are
|
||||
// cleared (only a linked one is shown now), then the boosts are looked at
|
||||
// and looked at again every RECHECK_HOURS.
|
||||
const startup = () => {
|
||||
const typed = accounts.all().filter(account => account.discord && !account.discordId);
|
||||
for (const account of typed) {
|
||||
account.discord = "";
|
||||
}
|
||||
if (typed.length) {
|
||||
accounts.save(...typed);
|
||||
console.log(`[discord] ${typed.length} Discord usernames typed in by hand were cleared`);
|
||||
}
|
||||
if (boostChecks()) {
|
||||
setTimeout(recheckAll, 30000).unref();
|
||||
setInterval(recheckAll, RECHECK_HOURS * 3600000).unref();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {linking, boostChecks, start, finish, unlink, startup};
|
||||
+10
-6
@@ -73,6 +73,10 @@ const flashVars = () => ({
|
||||
startupRoom: config.startupRoom,
|
||||
// "-1" turns the client's stats socket off.
|
||||
sbStatTrackerIp: "-1",
|
||||
// the client's Discord rich presence (its app/discord.js): the Discord
|
||||
// application it shows as, "" for none, and where its button goes.
|
||||
discordAppId: config.discord.clientId,
|
||||
presenceUrl: `${config.siteUrl}download`,
|
||||
sbStatModulator: "0",
|
||||
currentTimestamp: Math.floor(Date.now() / 1000),
|
||||
country: "US",
|
||||
@@ -469,6 +473,7 @@ const renameAndSignIn = (res, body, from) => {
|
||||
console.log(`[accounts] a rejected username was replaced by "${logText(account.username)}"`);
|
||||
accounts.setLoginChoices(account, body.login_choices);
|
||||
const token = accounts.issueToken(account);
|
||||
devices.noteLauncher(token, Boolean(devices.read(body.device)));
|
||||
send(res, 200, {auth_token: token, refresh_token: token, device_token: entry.deviceToken});
|
||||
};
|
||||
|
||||
@@ -479,13 +484,11 @@ const authenticate = async (req, res, from) => {
|
||||
return;
|
||||
}
|
||||
// the computer it is on (lib/devices.js): a client that does not say is
|
||||
// out of date (before 1.3.0) or not ours. 1.2 shows "The server refused
|
||||
// the login (426)", and still offers its update.
|
||||
// out of date (before 1.3.0) or not ours. it is signed in all the same,
|
||||
// and its token noted (signInChecked): with config.requireDevice the game
|
||||
// then loads and its login popup says to update (lib/world.js), where a
|
||||
// refusal here only ever showed "The server refused the login (426)".
|
||||
const device = devices.read(body.device);
|
||||
if (!device && config.requireDevice) {
|
||||
send(res, 426, {error_code: 101, error: "client_outdated"});
|
||||
return;
|
||||
}
|
||||
const accountKey = String(body.username).trim().toLowerCase();
|
||||
if (!from.local && failuresByAddress.blocked(from.key)) {
|
||||
send(res, 429, {error_code: 429, error: "too_many_attempts"});
|
||||
@@ -609,6 +612,7 @@ const signInChecked = async (res, body, from, account, saved, device) => {
|
||||
// the custom client's advanced settings; the official launcher sends none.
|
||||
accounts.setLoginChoices(account, body.login_choices);
|
||||
const token = byRefresh ? body.refresh_token : accounts.issueToken(account);
|
||||
devices.noteLauncher(token, Boolean(device));
|
||||
send(res, 200, {auth_token: token, refresh_token: token, device_token: deviceToken});
|
||||
};
|
||||
|
||||
|
||||
+43
-9
@@ -12,6 +12,7 @@ const config = require("../config.js");
|
||||
const limits = require("./limits.js");
|
||||
const achievements = require("./achievements.js");
|
||||
const badges = require("./badges.js");
|
||||
const discord = require("./discord.js");
|
||||
const bans = require("./bans.js");
|
||||
const captcha = require("./captcha.js");
|
||||
const chatlog = require("./chatlog.js");
|
||||
@@ -40,6 +41,12 @@ const world = require("./world.js");
|
||||
const COOKIE = "ajc_account";
|
||||
// A device that gave its two-step code keeps this for 30 days (lib/totp.js).
|
||||
const DEVICE_COOKIE = "ajc_device";
|
||||
// a Discord link under way (lib/discord.js): the browser that started it
|
||||
// must be the one that comes back. Lax, as Discord's redirect back is from
|
||||
// another site, which the page's own (Strict) cookie is not sent from.
|
||||
const DISCORD_COOKIE = "ajc_dlink";
|
||||
const discordCookie = (value, maxAgeSeconds) =>
|
||||
`${DISCORD_COOKIE}=${value}; Path=/account/discord; HttpOnly; SameSite=Lax; Max-Age=${maxAgeSeconds}${config.secureCookies ? "; Secure" : ""}`;
|
||||
const SESSION_HOURS = 12;
|
||||
const TEN_MINUTES_MS = 600000;
|
||||
const MAX_NOTE = 120;
|
||||
@@ -164,6 +171,8 @@ const profile = (account, from) => {
|
||||
locked: account.locked,
|
||||
twoStep: twoStepOf(account),
|
||||
discord: account.discord,
|
||||
discordLinked: Boolean(account.discordId),
|
||||
discordLinking: discord.linking(),
|
||||
bio: account.bio,
|
||||
bioLimit: badges.MAX_BIO,
|
||||
badges: badges.of(account).map(badge => badge.label),
|
||||
@@ -403,16 +412,15 @@ const act = (account, body, req, from, res) => {
|
||||
account.playtimePublic = body.on === true;
|
||||
accounts.save(account);
|
||||
return {ok: account.playtimePublic ? "Others can see your playtime on your card." : "Your playtime is private."};
|
||||
// their Discord username, for their card in the game. empty takes it off.
|
||||
case "discord": {
|
||||
const name = badges.discordName(body.name);
|
||||
if (name === null) {
|
||||
return {error: "Not a Discord username."};
|
||||
// their Discord account, for their card in the game: it is linked by
|
||||
// signing in to Discord (GET /account/discord/link), and only taken off
|
||||
// here, with the booster badge it brought.
|
||||
case "discord":
|
||||
if (String(body.name || "") !== "") {
|
||||
return {error: "Link your Discord account instead."};
|
||||
}
|
||||
account.discord = name;
|
||||
accounts.save(account);
|
||||
return {ok: name ? "Saved." : "Removed."};
|
||||
}
|
||||
discord.unlink(account);
|
||||
return {ok: "Removed."};
|
||||
// the player's own words about a buddy; only they see them.
|
||||
case "buddyNote": {
|
||||
const key = String(body.name || "").toLowerCase();
|
||||
@@ -570,12 +578,38 @@ const handle = async (req, res, url, from, web) => {
|
||||
}
|
||||
}
|
||||
|
||||
// back from Discord (lib/discord.js): the state and the nonce must be the
|
||||
// ones the link began with. the page then says how it went.
|
||||
if (route === "GET /account/discord/callback") {
|
||||
const nonce = (new RegExp(`(?:^|;\\s*)${DISCORD_COOKIE}=([0-9a-f]{48})(?:;|$)`).exec(req.headers.cookie || "") || [])[1];
|
||||
const result = url.searchParams.get("error") ? {error: "cancelled"}
|
||||
: await discord.finish(url.searchParams.get("state"), nonce, url.searchParams.get("code"));
|
||||
res.setHeader("Set-Cookie", discordCookie("", 0));
|
||||
res.writeHead(302, {Location: `/account?discord=${result.ok ? "linked" : result.error}`});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
const account = signedInAs(req);
|
||||
if (!account) {
|
||||
reply(401, {error: "Sign in first."});
|
||||
return;
|
||||
}
|
||||
switch (route) {
|
||||
// the page's "Link Discord": off to Discord's sign-in, which comes back
|
||||
// to /account/discord/callback.
|
||||
case "GET /account/discord/link": {
|
||||
if (!discord.linking() || banFor(account, from)) {
|
||||
res.writeHead(302, {Location: "/account?discord=off"});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
const {url: to, nonce} = discord.start(account);
|
||||
res.setHeader("Set-Cookie", discordCookie(nonce, 600));
|
||||
res.writeHead(302, {Location: to});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
// A copy of their data, as a file. also from the page of a ban.
|
||||
case "GET /account/api/export":
|
||||
if (!writesPerTenMinutes.allow(account.id)) {
|
||||
|
||||
@@ -183,6 +183,34 @@ module.exports = ({findOnline}) => {
|
||||
return true;
|
||||
},
|
||||
|
||||
// every post they wrote on anyone's Jammer Wall (lib/walls.js), their
|
||||
// own included, and the replies to those, as deleting a post in the game
|
||||
// takes its replies. returns {posts, replies, walls}.
|
||||
clearWallPosts(author) {
|
||||
const changed = [];
|
||||
let posts = 0;
|
||||
let replies = 0;
|
||||
for (const owner of accounts.all()) {
|
||||
const {wall} = owner;
|
||||
const gone = new Set(wall.posts.filter(post => post.uid === author.id).map(post => post.x));
|
||||
if (!gone.size) {
|
||||
continue;
|
||||
}
|
||||
const kept = wall.posts.filter(post => !gone.has(post.x) && !gone.has(post.pp));
|
||||
posts += gone.size;
|
||||
replies += wall.posts.length - kept.length - gone.size;
|
||||
const left = new Set(kept.map(post => post.x));
|
||||
wall.posts = kept;
|
||||
wall.hidden = wall.hidden.filter(id => left.has(id));
|
||||
wall.modified = Date.now();
|
||||
changed.push(owner);
|
||||
}
|
||||
if (changed.length) {
|
||||
accounts.save(...changed);
|
||||
}
|
||||
return {posts, replies, walls: changed.length};
|
||||
},
|
||||
|
||||
grantGems(target, amount) {
|
||||
return actions.grantCurrency(target, CURRENCY_GEMS, amount, false);
|
||||
},
|
||||
|
||||
+10
-1
@@ -159,7 +159,7 @@ const ACTION_PERMISSIONS = {
|
||||
silence: "chat.silence", unsilence: "chat.silence",
|
||||
kick: "player.kick", message: "player.warn", warn: "player.warn", unwarn: "player.warn",
|
||||
rejectName: "player.names", acceptName: "player.names", clearBio: "player.names",
|
||||
banAddress: "address.ban",
|
||||
clearWallPosts: "player.names", banAddress: "address.ban",
|
||||
summon: "player.summon", goto: "player.goto",
|
||||
note: "player.view", deleteNote: "player.view",
|
||||
};
|
||||
@@ -256,6 +256,15 @@ const act = (mod, target, body) => {
|
||||
target.bio = "";
|
||||
accounts.save(target);
|
||||
return {ok: "Bio cleared."};
|
||||
case "clearWallPosts": {
|
||||
const {posts, replies, walls} = actions.clearWallPosts(target);
|
||||
if (!posts) {
|
||||
return {error: `${name} has no posts on any Jammer Wall.`};
|
||||
}
|
||||
const text = `${posts} wall ${posts === 1 ? "post" : "posts"} by ${name} removed from ${walls} ${walls === 1 ? "wall" : "walls"}`
|
||||
+ `${replies ? ` (with ${replies} ${replies === 1 ? "reply" : "replies"} to them)` : ""}.`;
|
||||
return {ok: text, detail: `${posts} posts, ${replies} replies, ${walls} walls`};
|
||||
}
|
||||
// a note for the other staff (lib/modnotes.js); the player never sees it.
|
||||
case "note": {
|
||||
const result = modNotes.add(target, by, body.text);
|
||||
|
||||
+15
-8
@@ -8,6 +8,7 @@ const accounts = require("./accounts.js");
|
||||
const achievements = require("./achievements.js");
|
||||
const adopt = require("./adopt.js");
|
||||
const badges = require("./badges.js");
|
||||
const discordLinks = require("./discord.js");
|
||||
const bans = require("./bans.js");
|
||||
const colours = require("./colours.js");
|
||||
const chatlog = require("./chatlog.js");
|
||||
@@ -452,16 +453,13 @@ const act = (account, body) => {
|
||||
world.checkNameTag(account);
|
||||
return {ok: account.badges.length ? `${name} has: ${badges.of(account).map(badge => badge.label).join(", ")}.` : `${name} has no badges.`};
|
||||
}
|
||||
// their Discord username, which they otherwise set on the account
|
||||
// page; empty takes it off.
|
||||
// their linked Discord account (lib/discord.js), taken off.
|
||||
case "discord": {
|
||||
const discord = badges.discordName(body.name);
|
||||
if (discord === null) {
|
||||
return {error: "Not a Discord username."};
|
||||
// only taken off: a player links their own (lib/discord.js)
|
||||
if (String(body.name || "") !== "") {
|
||||
return {error: "Players link their Discord themselves, on the account page."};
|
||||
}
|
||||
account.discord = discord;
|
||||
accounts.save(account);
|
||||
return {ok: discord ? `Discord set to "${discord}".` : "Discord cleared."};
|
||||
return discordLinks.unlink(account) ? {ok: "Discord unlinked."} : {error: `${name} has no Discord linked.`};
|
||||
}
|
||||
// their bio, which they otherwise write on the account page; empty
|
||||
// takes it off.
|
||||
@@ -572,6 +570,15 @@ const act = (account, body) => {
|
||||
case "clearDen":
|
||||
actions.clearDen(account);
|
||||
return {ok: `Everything in ${name}'s den went back to their inventory.`};
|
||||
case "clearWallPosts": {
|
||||
const {posts, replies, walls} = actions.clearWallPosts(account);
|
||||
if (!posts) {
|
||||
return {error: `${name} has no posts on any Jammer Wall.`};
|
||||
}
|
||||
const text = `${posts} wall ${posts === 1 ? "post" : "posts"} by ${name} removed from ${walls} ${walls === 1 ? "wall" : "walls"}`
|
||||
+ `${replies ? ` (with ${replies} ${replies === 1 ? "reply" : "replies"} to them)` : ""}.`;
|
||||
return {ok: text, detail: `${posts} posts, ${replies} replies, ${walls} walls`};
|
||||
}
|
||||
case "gems": {
|
||||
const amount = wholeNumber(body.amount, -MAX_GEMS, MAX_GEMS);
|
||||
if (amount === null) {
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ const PERMISSIONS = {
|
||||
"player.summon": "bring a player to the room you are in (!summon)",
|
||||
"staff.invisible": "go unseen in rooms, as the game's moderators could (!invisible)",
|
||||
"player.ban": "ban, unban and change a ban's reason",
|
||||
"player.names": "reject or accept a name, clear a bio",
|
||||
"player.names": "reject or accept a name, clear a bio, remove a player's Jammer Wall posts",
|
||||
"address.ban": "ban the address a player last signed in from",
|
||||
"items.approve": "approve or turn away the items and pictures players make, when the admin has asked for that",
|
||||
"items.create": "make new items from the game's art, change and delete them, lock items out of the item finder and take items from players (!item, !lock, !unlock, !locked, !take)",
|
||||
|
||||
+47
-3
@@ -146,6 +146,11 @@ const MAX_USER_VARS = 2000;
|
||||
const MAX_FILTER_WORDS = 100; // a player's own words for their chat filter
|
||||
const MAX_FILTER_WORD = 30;
|
||||
const LOGIN_BANNED = -15; // MainFrame.MSG_ID_LOGIN_BANNED
|
||||
// MainFrame.MSG_ID_LOGIN_ACCT_MAINT: its popup (GamePlay.onWorldLogIn) shows
|
||||
// localization string 11198, which lib/defpacks.js makes the "update your
|
||||
// client" message. the official servers' account maintenance never happens
|
||||
// here.
|
||||
const LOGIN_OUTDATED = -12;
|
||||
|
||||
const THEME_PATH_PREFIX = "theme_"; // lib/http.js looks for this
|
||||
const chatLines = limits.limiter(config.chatLinesPerWindow, config.chatWindowMs);
|
||||
@@ -183,6 +188,26 @@ const sees = (viewer, subject) => (!subject.invisible || roles.isActiveStaff(vie
|
||||
const watchers = session => others(session).filter(other => sees(other, session));
|
||||
const TYPING_EVERY_MS = 2000; // "typing" passed on at most this often per player (xty)
|
||||
|
||||
// tags ("@name") in chat and on Jammer Walls (xmn): the longest player's
|
||||
// name that the text after an "@" starts with, ending where a word does
|
||||
// ("@John Smith hi" is John Smith if there is one, else John; "@Bobby" is
|
||||
// never Bob). {length, name} or null.
|
||||
const MAX_MENTION_TEXT = 40;
|
||||
const MAX_MENTIONS = 10; // per question
|
||||
const mentionLookups = limits.limiter(120, 60000); // questions a minute, per player
|
||||
const mentionOf = text => {
|
||||
for (let length = Math.min(text.length, MAX_MENTION_TEXT); length > 0; length--) {
|
||||
if (length < text.length && /[A-Za-z0-9]/.test(text[length])) {
|
||||
continue;
|
||||
}
|
||||
const name = accounts.nameOf(text.slice(0, length));
|
||||
if (name) {
|
||||
return {length, name};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const decodeEntities = text => text
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
@@ -304,9 +329,12 @@ const login = (session, msg) => {
|
||||
loginFailed(session, LOGIN_BANNED, "Banned");
|
||||
return;
|
||||
}
|
||||
if (config.requireDevice && devices.knownFor(account).lastAt < Math.floor(Date.now() / 1000) - 90 * 86400) {
|
||||
console.log(`[world] login rejected for "${logText(account.username)}": no device ids`);
|
||||
loginFailed(session, 0, "Update the client");
|
||||
// a launcher that sent no device ids (before 1.3.0): signed in at
|
||||
// /authenticate, refused here, where the game's popup can say why.
|
||||
if (config.requireDevice && (devices.launcherOutdated(msg.cdata("pword"))
|
||||
|| devices.knownFor(account).lastAt < Math.floor(Date.now() / 1000) - 90 * 86400)) {
|
||||
console.log(`[world] login rejected for "${logText(account.username)}": client outdated (no device ids)`);
|
||||
loginFailed(session, LOGIN_OUTDATED, "Client outdated");
|
||||
return;
|
||||
}
|
||||
// its username was rejected (lib/moderation.js): a new one first, which
|
||||
@@ -912,6 +940,22 @@ const handlers = {
|
||||
}
|
||||
},
|
||||
|
||||
// the patched client's tags (AJClient.resolveMentions): xmn [id, the text
|
||||
// after each "@", ...] -> "xmn" [.., .., id, then for each text: how many
|
||||
// of its characters are a player's name (0 for none), the name as it is
|
||||
// spelled, 1 if they are online]. what a text is not a name of stays text.
|
||||
xmn(session, roomId, [id, ...texts]) {
|
||||
if (!mentionLookups.allow(session.account.id)) {
|
||||
return;
|
||||
}
|
||||
const reply = [];
|
||||
for (const text of texts.slice(0, MAX_MENTIONS)) {
|
||||
const found = mentionOf(String(text));
|
||||
reply.push(found ? found.length : 0, found ? found.name : "", found && findOnline(found.name) ? 1 : 0);
|
||||
}
|
||||
session.sendXt("xmn", -1, Number.isInteger(Number(id)) ? Number(id) : 0, ...reply);
|
||||
},
|
||||
|
||||
// the patched client's staff window: going invisible, or being seen again.
|
||||
xiv(session) {
|
||||
if (session.invisible || roles.can(session.account, "staff.invisible")) {
|
||||
|
||||
Reference in new issue
Block a user