mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat: hardware bans, panel search and logs, jam-a-gram and wall post logs
- the client (1.3.0) sends one-way hashes of the device's ids at sign-in; the server keys them again with a secret of its own (data/device-key) and keeps them per account (lib/devices.js). a sign-in without them is refused with 426 (AJ_REQUIRE_DEVICE=0 lets it in), so 1.2 clients cannot sign in. - hardware bans: every device an account used in the last 90 days. any id but a network card blocks sign-in, sign-up and the game, on any account. a network card match, ids that look altered, or a device shared with a banned player raise hardware alerts instead. - both panels: hardware ban and lift, the account's hardware ids, search by hardware id, other accounts by device or address, a timeline (bans, staff actions, reports, alerts), and hardware bans and alerts in the bans tab. - jam-a-grams and wall posts go into the chat log, the filtered ones marked not sent. chat search filters by kind, by what the filter stopped, and from a time back; each player's page lists their jam-a-grams and wall posts, sent and received. - account search runs on the server and ranks exact names first, then names starting with the search; the admin panel no longer downloads every account. hidden tabs only refresh the waiting counts in the title. masterpieces can be searched by maker, approved ones too. reports can show the reported player's chat at the time. links follow the open tab and player. - admin actions on accounts go into the moderator log. - privacy policy covers hardware hashes and the new logs.
This commit is contained in:
1 parent
0e86592d40
commit
cf729d52dc
21 files changed
+1898
-131
No files matched your search
+68
-11
@@ -3,7 +3,8 @@
|
||||
const accounts = require("./accounts.js");
|
||||
const config = require("../config.js");
|
||||
|
||||
// what players typed: chat in a room, and whispers. kept for the moderator
|
||||
// what players typed: chat in a room, whispers, Jam-a-Grams and posts on
|
||||
// each other's Jammer Walls. kept for the moderator
|
||||
// panel (lib/modpanel.js), which is where a moderator reads what was said
|
||||
// before deciding anything; nothing else reads it. lines older than
|
||||
// config.chatLogDays are deleted, and an account's lines go when the
|
||||
@@ -26,6 +27,11 @@ const SCHEMA = `
|
||||
|
||||
const CHAT = "chat";
|
||||
const WHISPER = "whisper";
|
||||
const JAMAGRAM = "jamagram";
|
||||
const WALL = "wall";
|
||||
const KINDS = [CHAT, WHISPER, JAMAGRAM, WALL];
|
||||
// what the server's filter kept from being sent is kept with this in front.
|
||||
const NOT_SENT = "(not sent) ";
|
||||
const DAY_SECONDS = 86400;
|
||||
const MAX_TEXT = 600;
|
||||
const PAGE = 100;
|
||||
@@ -40,28 +46,69 @@ const prune = () => {
|
||||
|
||||
const load = () => {
|
||||
db().exec(SCHEMA);
|
||||
// lines the filter stopped are marked, and found by a small index of their own.
|
||||
if (!db().prepare("PRAGMA table_info(chat_log)").all().some(column => column.name === "stopped")) {
|
||||
db().exec("ALTER TABLE chat_log ADD COLUMN stopped INTEGER NOT NULL DEFAULT 0");
|
||||
db().prepare("UPDATE chat_log SET stopped = 1 WHERE substr(text, 1, ?) = ?").run(NOT_SENT.length, NOT_SENT);
|
||||
}
|
||||
db().exec("CREATE INDEX IF NOT EXISTS chat_log_stopped ON chat_log (at) WHERE stopped = 1");
|
||||
prune();
|
||||
setInterval(prune, DAY_SECONDS * 1000 / 4).unref();
|
||||
};
|
||||
|
||||
const stoppedFlag = text => (String(text).startsWith(NOT_SENT) ? 1 : 0);
|
||||
|
||||
// A line said in `room` (its name as the world knows it), or with `to` a
|
||||
// whisper to that player.
|
||||
const record = (account, room, text, to = "") => {
|
||||
if (config.chatLogDays <= 0) {
|
||||
return;
|
||||
}
|
||||
db().prepare("INSERT INTO chat_log (at, account_id, username, room, kind, to_name, text) VALUES (?, ?, ?, ?, ?, ?, ?)")
|
||||
.run(now(), account.id, account.username, String(room || ""), to ? WHISPER : CHAT, to, String(text).slice(0, MAX_TEXT));
|
||||
db().prepare("INSERT INTO chat_log (at, account_id, username, room, kind, to_name, text, stopped) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
.run(now(), account.id, account.username, String(room || ""), to ? WHISPER : CHAT, to, String(text).slice(0, MAX_TEXT), stoppedFlag(text));
|
||||
};
|
||||
|
||||
const row = line => ({id: line.id, at: line.at, username: line.username, room: line.room, whisperTo: line.kind === WHISPER ? line.to_name : "", text: line.text});
|
||||
// A Jam-a-Gram's words (`kind` JAMAGRAM), or a post on a Jammer Wall
|
||||
// (WALL): `to` is who it was sent to, or whose wall it is.
|
||||
const recordTo = (account, kind, to, text) => {
|
||||
if (config.chatLogDays <= 0 || !KINDS.includes(kind)) {
|
||||
return;
|
||||
}
|
||||
db().prepare("INSERT INTO chat_log (at, account_id, username, room, kind, to_name, text, stopped) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
.run(now(), account.id, account.username, "", kind, String(to || ""), String(text).slice(0, MAX_TEXT), stoppedFlag(text));
|
||||
};
|
||||
|
||||
const row = line => ({id: line.id, at: line.at, username: line.username, room: line.room, kind: line.kind, to: line.to_name,
|
||||
whisperTo: line.kind === WHISPER ? line.to_name : "", text: line.text});
|
||||
|
||||
// lines newest first, a page at a time: by who said them (or was whispered
|
||||
// to), by room, by words in them, and `before` an id for the next page.
|
||||
const search = ({username = "", room = "", text = "", before = 0}) => {
|
||||
// to, or sent to), by room, by words in them, by kind (one of KINDS, or
|
||||
// "notsent" for what the filter stopped), from `until` (seconds) back, and
|
||||
// `before` an id for the next page. `direction` narrows the username to
|
||||
// what they sent ("sent") or what was sent to them ("received").
|
||||
const search = ({username = "", room = "", text = "", kind = "", direction = "", until = 0, before = 0}) => {
|
||||
const where = [];
|
||||
const values = [];
|
||||
if (username) {
|
||||
if (KINDS.includes(kind)) {
|
||||
where.push("kind = ?");
|
||||
values.push(kind);
|
||||
}
|
||||
else if (kind === "notsent") {
|
||||
where.push("stopped = 1");
|
||||
}
|
||||
if (until > 0) {
|
||||
where.push("at <= ?");
|
||||
values.push(Math.floor(until));
|
||||
}
|
||||
if (username && direction === "sent") {
|
||||
where.push("username = ? COLLATE NOCASE");
|
||||
values.push(username);
|
||||
}
|
||||
else if (username && direction === "received") {
|
||||
where.push("to_name = ? COLLATE NOCASE");
|
||||
values.push(username);
|
||||
}
|
||||
else if (username) {
|
||||
where.push("(username = ? COLLATE NOCASE OR to_name = ? COLLATE NOCASE)");
|
||||
values.push(username, username);
|
||||
}
|
||||
@@ -87,9 +134,9 @@ const around = id => {
|
||||
if (!line) {
|
||||
return null;
|
||||
}
|
||||
const [same, values] = line.kind === WHISPER
|
||||
? ["kind = ? AND ((username = ? AND to_name = ?) OR (username = ? AND to_name = ?))", [WHISPER, line.username, line.to_name, line.to_name, line.username]]
|
||||
: ["kind = ? AND room = ?", [CHAT, line.room]];
|
||||
const [same, values] = line.kind === CHAT
|
||||
? ["kind = ? AND room = ?", [CHAT, line.room]]
|
||||
: ["kind = ? AND ((username = ? AND to_name = ?) OR (username = ? AND to_name = ?))", [line.kind, line.username, line.to_name, line.to_name, line.username]];
|
||||
const earlier = db().prepare(`SELECT * FROM chat_log WHERE ${same} AND id < ? ORDER BY id DESC LIMIT ?`).all(...values, line.id, AROUND).reverse();
|
||||
const later = db().prepare(`SELECT * FROM chat_log WHERE ${same} AND id > ? ORDER BY id LIMIT ?`).all(...values, line.id, AROUND);
|
||||
return {line: row(line), lines: [...earlier, line, ...later].map(row)};
|
||||
@@ -99,9 +146,19 @@ const around = id => {
|
||||
// of their data a player may ask for (lib/manage.js).
|
||||
const saidBy = account => db().prepare("SELECT * FROM chat_log WHERE account_id = ? ORDER BY id").all(account.id).map(row);
|
||||
|
||||
// how many of an account's lines the server's filter stopped, in the last
|
||||
// `days` days.
|
||||
const notSentCount = (account, days) => db().prepare("SELECT COUNT(*) AS n FROM chat_log WHERE account_id = ? AND at > ? AND stopped = 1")
|
||||
.get(account.id, now() - days * DAY_SECONDS).n;
|
||||
|
||||
// those the filter stopped most often in the last `days` days: [{username, count, last}].
|
||||
const mostStopped = (days, limit) => db().prepare(`SELECT username, COUNT(*) AS count, MAX(at) AS last FROM chat_log
|
||||
WHERE stopped = 1 AND at > ? GROUP BY account_id ORDER BY count DESC LIMIT ?`)
|
||||
.all(now() - days * DAY_SECONDS, limit).map(entry => ({username: entry.username, count: entry.count, last: entry.last}));
|
||||
|
||||
// an account being deleted: what it said goes with it.
|
||||
const forget = account => {
|
||||
db().prepare("DELETE FROM chat_log WHERE account_id = ?").run(account.id);
|
||||
};
|
||||
|
||||
module.exports = {load, record, search, around, saidBy, forget, PAGE};
|
||||
module.exports = {load, record, recordTo, search, around, saidBy, notSentCount, mostStopped, forget, PAGE, JAMAGRAM, WALL, NOT_SENT};
|
||||
Reference in new issue
Block a user