mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat: server chat filter for slurs and sexual talk, no secret valentines
- lib/chatfilter.js reads its rules from lib/chat-filter.txt (reloaded when it changes) and applies them to typed chat, jam-a-gram messages and jammer wall posts. players cannot turn it off. a blocked message reaches nobody, its sender sees the game's "inappropriate behavior" warning, and blocked chat is kept in the chat log marked not sent. - rules match words, prefixes and phrases, in order or anywhere, with "?" for any word and "!" for exceptions, and see through stand-in letters, drawn-out letters and spaced-out spelling. the example rules block sexual talk aimed at someone while letting plain swearing through; the slur section is left for the owner to fill in. - secret valentine jam-a-grams are off: the client sends a normal card without asking (buildVersion 56), and the server refuses a card asked for as a secret valentine.
This commit is contained in:
1 parent
aa455f52d0
commit
89fe4d2a28
8 files changed
+291
-6
No files matched your search
@@ -116,7 +116,7 @@ module.exports = {
|
||||
// 41: the game's text says "Burrow" where it said Animal Jam.
|
||||
// 48: the item giver (the item finder renamed) with previews and hex colours;
|
||||
// 49 and 50: its link to a colour picker.
|
||||
buildVersion: env.AJ_BUILD_VERSION || "55",
|
||||
buildVersion: env.AJ_BUILD_VERSION || "56",
|
||||
// what the official CDN is asked for; not ours to change.
|
||||
upstreamBuildVersion: "3",
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# The server's chat filter (lib/chatfilter.js): typed chat, Jam-a-Gram
|
||||
# messages and Jammer Wall posts. A message that breaks a rule here reaches
|
||||
# nobody, and its sender is told it was not sent. Players cannot turn this
|
||||
# off (unlike the client's own filter). It is read again when this file
|
||||
# changes: no restart needed.
|
||||
#
|
||||
# One rule to a line; lines starting with # are comments. Capitals do not
|
||||
# matter. Messages are read the way people dodge filters: digits and signs
|
||||
# standing in for letters (4ss, a$$, n00b), letters drawn out (fuuuck), and
|
||||
# words spelled out a letter at a time (f u c k, f.u.c.k).
|
||||
#
|
||||
# word that word on its own ("ass", not "class" or "assume")
|
||||
# word* any word starting with it ("fuck*": fucking, fucker)
|
||||
# *word* any word with it anywhere inside (for words that never
|
||||
# turn up inside innocent ones)
|
||||
# two words those words one after the other
|
||||
# a|b|c any one of them
|
||||
# a + b a, then b as the very next word
|
||||
# a .. b a, then b at most 4 words later ("send .. nudes" catches
|
||||
# "send me some nudes", but not "nudes, send")
|
||||
# a & b both somewhere in the same message, in any order
|
||||
# ? any one word (a name: "fuck + ? + ass" catches
|
||||
# "fuck johns ass")
|
||||
# !word in a | list: but not this word ("?|!it" is any word
|
||||
# but "it"). A slot of only these takes up no word:
|
||||
# "a + !up" is a, not followed by "up" (or ending there)
|
||||
#
|
||||
# These combine: "fuck|screw + you|u + in|up + the|your + ass" is one rule.
|
||||
# Apostrophes are dropped before matching, so write "ill" for "i'll".
|
||||
# Prefer + over .. and & : the looser the rule, the more ordinary messages it
|
||||
# catches by accident ("fuck .. you" would also catch "i dont give a fuck
|
||||
# about you").
|
||||
|
||||
# --- Slurs -------------------------------------------------------------------
|
||||
*nigger*
|
||||
*faggot*
|
||||
|
||||
# --- Sexual talk aimed at someone ---------------------------------------------
|
||||
# Aimed at anyone: these use ? for the person, so names are caught too.
|
||||
# "Not a person" words (it, this, up, off...) are left out with !, so
|
||||
# "gonna fuck this up" and "fuck it" go through.
|
||||
|
||||
# "fuck you in the ass", "ill fuck john in the ass", "bang her up the butt".
|
||||
fuck*|screw|bang|rape*|hump*|pound|breed .. in|up|on + the|your|ur|his|her|their|my|ma|yo|that + ass|butt|booty|pussy|dick|cock|hole|asshole|mouth|throat|vagina
|
||||
# "fuck johns ass", "fuck your pussy", "eat her pussy".
|
||||
fuck*|screw|bang|rape*|hump*|pound|breed|eat + ?|!the|!a|!this|!that + ass|butt|booty|pussy|dick|cock|tits|titties|boobs|hole|asshole|vagina|penis|clit
|
||||
# "fuck pussy", "suck dick", "eat pussy".
|
||||
fuck*|eat|suck*|lick* + pussy|dick|cock|tits|titties|boobs|clit|penis|vagina|nipples|dih
|
||||
# "fuck you hard", "ill bang john raw". Plain "fuck you" is an insult and stays.
|
||||
fuck*|screw|bang|rape*|hump*|pound|breed + ?|!this|!that|!it|!the|!a|!up|!off + hard|harder|raw|deep|senseless
|
||||
# Saying what you'll do to someone: "ill fuck you", "im gonna fuck john",
|
||||
# "i wanna bang her". Not "ill fuck him up" (a threat, not sex) or "gonna
|
||||
# fuck this level up".
|
||||
ill|imma|ima|gonna|gunna|wanna|lemme|let me|tryna|finna|want to|going to|i will|i want to|i would|id|lets + fuck|screw|bang|rape|hump|breed + ?|!up|!off|!around|!it|!this|!that|!with|!over|!everything|!everyone|!something|!shit|!myself|!yourself|!themselves|!the|!a|!all|!things|!stuff + !up|!off|!over|!shit
|
||||
# Asking to: "wanna fuck?", "lets bang". Not "wanna fuck around".
|
||||
wanna|want to|lets|can we|do you want to + fuck|bang|screw + !up|!off|!around|!with|!this|!that|!it|!over|!shit|!things|!everything
|
||||
# Asking for or offering sex acts: "suck my dick", "lick johns pussy",
|
||||
# "grab her ass".
|
||||
suck*|lick*|blow|ride|touch|rub|finger*|jerk|stroke|grab|squeeze + ?|!the|!a|!some|!these|!those|!all + dick|cock|pussy|tits|titties|boobs|balls|ass|butt|booty|nipples|clit|penis|vagina|dih
|
||||
# Asking for pictures: "send me some nudes", "show me ur tits".
|
||||
send|show|see|sending|post .. nudes|noods|nude|naked|tits|titties|boobs|pussy|dick|cock|nipples|penis|vagina
|
||||
# Asking for sex: "wanna have sex", "lets cyber", "sex with john".
|
||||
wanna|want to|lets|can we|have|having|do you want to + sex|cyber|cybersex|seks|secks
|
||||
sex|cyber|cybersex + with + ?
|
||||
sext|sexting|cybersex
|
||||
# "cum on you", "cum inside her", "nut in ur mouth".
|
||||
cum|cumming|jizz + on|in|inside|all over + ?
|
||||
nut|nutting + on|in|inside|all over + you|u|ur|your|my|me|her|his|him|them
|
||||
# Sex acts and porn words that have no everyday use in this game.
|
||||
blowjob*|handjob*|rimjob*|deepthroat*|cumshot*|creampie*|gangbang*|threesome*|orgasm*|masturbat*|jerk off|jack off|jerking off|jacking off
|
||||
porn*|hentai|rule34|r34|onlyfans|nudes|noods|dildo*|vibrator*|horny|hornie|erection|boner
|
||||
# Roleplay asks: "wanna erp", "dm me for erp".
|
||||
erp & wanna|want|lets|dm|pm|anyone
|
||||
@@ -0,0 +1,174 @@
|
||||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
// the server's own filter for what players write to each other: typed chat,
|
||||
// Jam-a-Gram messages and Jammer Wall posts. unlike the chat filter in the
|
||||
// client (the player's to set, or turn off), this one cannot be turned off,
|
||||
// and what it catches reaches nobody. it is meant to be narrow: slurs, and
|
||||
// sexual talk aimed at someone, never swearing as such ("fuck" is fine,
|
||||
// "i'll fuck you in the ass" is not). the rules are lib/chat-filter.txt,
|
||||
// read again when it changes; the file says how they are written.
|
||||
|
||||
const RULES_FILE = path.join(__dirname, "chat-filter.txt");
|
||||
// for "a .. b": how many words may come between the two ("a + b": none)
|
||||
const MAX_GAP = 4;
|
||||
// letters written as digits or signs, as the client's filter reads them
|
||||
// (AJClient.filterText), plus "@" and "$".
|
||||
const STAND_INS = {0: "o", 1: "i", 3: "e", 4: "a", 5: "s", 7: "t", "@": "a", $: "s"};
|
||||
|
||||
// A letter drawn out three times or more ("fuuuck") is read as the word
|
||||
// with every run of letters made one, and compared that way: a word written
|
||||
// plainly is compared as it is ("ass" is not "as").
|
||||
const squash = word => word.replace(/(.)\1+/g, "$1");
|
||||
const stretched = word => /(.)\1\1/.test(word);
|
||||
|
||||
// the words of a message as compared: small letters, apostrophes dropped
|
||||
// ("i'll" is "ill"), stand-ins read as the letters they are, split at
|
||||
// anything else. a word that is only digits is a number and goes. three or
|
||||
// more single letters in a row ("f u c k", "f.u.c.k") are read as one word.
|
||||
const wordsOf = text => {
|
||||
const words = String(text).toLowerCase().replace(/['\u2019`]/g, "")
|
||||
.split(/[^a-z0-9@$]+/).filter(word => word && !/^\d+$/.test(word))
|
||||
.map(word => word.replace(/[0-9@$]/g, sign => STAND_INS[sign] || "")).filter(Boolean);
|
||||
const joined = [];
|
||||
for (let i = 0; i < words.length;) {
|
||||
let end = i;
|
||||
while (end < words.length && words[end].length === 1) {
|
||||
end++;
|
||||
}
|
||||
if (end - i >= 3) {
|
||||
joined.push(words.slice(i, end).join(""));
|
||||
i = end;
|
||||
}
|
||||
else {
|
||||
joined.push(words[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return joined;
|
||||
};
|
||||
|
||||
// one word of a rule: {text, start, inside, any}. "word" is that word,
|
||||
// "word*" any word starting with it, "*word*" any word with it anywhere
|
||||
// inside, "?" any word at all.
|
||||
const patternOf = token => {
|
||||
if (token === "?") {
|
||||
return {any: true};
|
||||
}
|
||||
const inside = token.length > 2 && token.startsWith("*") && token.endsWith("*");
|
||||
const start = !inside && token.endsWith("*");
|
||||
const text = token.replace(/^\*|\*$/g, "").toLowerCase().replace(/[0-9@$]/g, sign => STAND_INS[sign] || "").replace(/[^a-z]/g, "");
|
||||
return text ? {text, start, inside} : null;
|
||||
};
|
||||
|
||||
const fits = (word, pattern) => {
|
||||
if (pattern.any) {
|
||||
return true;
|
||||
}
|
||||
const forms = stretched(word) ? [word, squash(word)] : [word];
|
||||
const wanted = form => (form === word ? pattern.text : squash(pattern.text));
|
||||
return forms.some(form => (pattern.inside ? form.includes(wanted(form))
|
||||
: pattern.start ? form.startsWith(wanted(form)) : form === wanted(form)));
|
||||
};
|
||||
|
||||
// A rule: clauses joined by " & ", all of which must be found in the
|
||||
// message; a clause: slots in order, joined by " + " (the next word) or
|
||||
// " .. " (at most MAX_GAP words later), each slot {choices, gap}, its gap
|
||||
// being how far after the one before it may start; a slot's choices are
|
||||
// joined by "|", and a choice is one word, or words that follow each other.
|
||||
// a choice written "!word" is one the slot must not be: "?|!it" is any word
|
||||
// but "it". A slot of only those takes up no word: "a + !up" is "a", not
|
||||
// followed by "up" (or at the end of the message).
|
||||
const parse = line => line.split(/\s+&\s+/).map(clause => {
|
||||
const parts = clause.split(/\s+(\.\.|\+)\s+/);
|
||||
const slots = [];
|
||||
for (let i = 0; i < parts.length; i += 2) {
|
||||
const written = parts[i].split("|").map(choice => choice.trim());
|
||||
const wordsIn = list => list.map(choice => choice.split(/\s+/).map(patternOf)).filter(choice => choice.length > 0 && choice.every(Boolean));
|
||||
const choices = wordsIn(written.filter(choice => !choice.startsWith("!")));
|
||||
const not = wordsIn(written.filter(choice => choice.startsWith("!")).map(choice => choice.slice(1)));
|
||||
slots.push({choices, not, gap: parts[i - 1] === "+" ? 0 : MAX_GAP});
|
||||
}
|
||||
return slots;
|
||||
});
|
||||
|
||||
// where in `words` a slot's choice starts at `at`: the index after it, or -1.
|
||||
const startsWith = (words, at, choice) => at + choice.length <= words.length && choice.every((pattern, i) => fits(words[at + i], pattern));
|
||||
const slotAt = (words, at, slot) => {
|
||||
if (slot.not.some(choice => startsWith(words, at, choice))) {
|
||||
return -1;
|
||||
}
|
||||
for (const choice of slot.choices) {
|
||||
if (startsWith(words, at, choice)) {
|
||||
return at + choice.length;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
const clauseFrom = (words, slots, from, to) => {
|
||||
if (slots.length === 0) {
|
||||
return true;
|
||||
}
|
||||
if (slots[0].choices.length === 0) {
|
||||
return !slots[0].not.some(choice => startsWith(words, from, choice)) && clauseFrom(words, slots.slice(1), from, from + (slots.length > 1 ? slots[1].gap : 0));
|
||||
}
|
||||
for (let at = from; at <= Math.min(to, words.length - 1); at++) {
|
||||
const end = slotAt(words, at, slots[0]);
|
||||
if (end !== -1 && clauseFrom(words, slots.slice(1), end, end + (slots.length > 1 ? slots[1].gap : 0))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
let kept = {mtime: -1, rules: []};
|
||||
const rules = () => {
|
||||
let mtime = 0;
|
||||
try {
|
||||
mtime = fs.statSync(RULES_FILE).mtimeMs;
|
||||
}
|
||||
catch (err) {
|
||||
return [];
|
||||
}
|
||||
if (kept.mtime !== mtime) {
|
||||
const lines = fs.readFileSync(RULES_FILE, "utf8").split(/\r?\n/).map(line => line.trim()).filter(line => line && !line.startsWith("#"));
|
||||
const parsed = [];
|
||||
for (const line of lines) {
|
||||
const clauses = parse(line);
|
||||
if (clauses.every(clause => clause.length > 0 && clause.every(slot => slot.choices.length > 0 || slot.not.length > 0) && clause[0].choices.length > 0)) {
|
||||
parsed.push({line, clauses});
|
||||
}
|
||||
else {
|
||||
console.log(`[filter] lib/chat-filter.txt: a rule that could not be read was left out: ${line}`);
|
||||
}
|
||||
}
|
||||
kept = {mtime, rules: parsed};
|
||||
console.log(`[filter] ${parsed.length} rules`);
|
||||
}
|
||||
return kept.rules;
|
||||
};
|
||||
|
||||
// the rule a message breaks (its line in the file), or null.
|
||||
const broken = text => {
|
||||
const words = wordsOf(text);
|
||||
if (words.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const rule = rules().find(candidate => candidate.clauses.every(clause => clauseFrom(words, clause, 0, words.length - 1)));
|
||||
return rule ? rule.line : null;
|
||||
};
|
||||
|
||||
// the game's own warning screen, over the game, for ten seconds
|
||||
// (FacilitatorXtCommManager, "fw" of facilitatorDisciplineResponse). its
|
||||
// kind picks the picture and the words: 3 "Personal Information", 5
|
||||
// "Bullying", 11 "Scamming", 0 a short "Inappropriate Chat", and this one
|
||||
// "Inappropriate Behavior" with the game's own text ("It looks like the
|
||||
// conversation you're having isn't appropriate..."). it also lets go of
|
||||
// the sender's chat bubble that waits for the line.
|
||||
const WARNING_BEHAVIOR = 4;
|
||||
const warn = session => session.sendXt("fd", -1, "fw", WARNING_BEHAVIOR);
|
||||
|
||||
module.exports = {broken, warn, wordsOf};
|
||||
+17
-2
@@ -4,6 +4,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const accounts = require("./accounts.js");
|
||||
const achievements = require("./achievements.js");
|
||||
const chatFilter = require("./chatfilter.js");
|
||||
const defpacks = require("./defpacks.js");
|
||||
const dens = require("./dens.js");
|
||||
const limits = require("./limits.js");
|
||||
@@ -248,6 +249,21 @@ module.exports = ({findOnline, blocks}) => {
|
||||
reply(FAILED);
|
||||
return;
|
||||
}
|
||||
// secret valentines are off on this server: the patched client no
|
||||
// longer offers them, and a card asked for as one from an older copy
|
||||
// is not sent with its sender's name shown instead.
|
||||
if (isValentine === "1") {
|
||||
reply(FAILED);
|
||||
return;
|
||||
}
|
||||
// the server's filter (lib/chatfilter.js).
|
||||
const rule = chatFilter.broken(clean(message || ""));
|
||||
if (rule) {
|
||||
chatFilter.warn(session);
|
||||
console.log(`[filter] ${account.username} in a Jam-a-Gram to ${to.username}: "${clean(message || "")}" (${rule})`);
|
||||
reply(FAILED);
|
||||
return;
|
||||
}
|
||||
if (!mayReceiveFrom(to, account)) {
|
||||
reply(NOT_ACCEPTING);
|
||||
return;
|
||||
@@ -262,8 +278,7 @@ module.exports = ({findOnline, blocks}) => {
|
||||
reply(FAILED);
|
||||
return;
|
||||
}
|
||||
deliver(to, {from: account.username, fromId: account.id, card: Number(card), stamp: Number(stamp), msg: clean(message || ""), gift,
|
||||
...(isValentine === "1" ? {secret: true} : {})});
|
||||
deliver(to, {from: account.username, fromId: account.id, card: Number(card), stamp: Number(stamp), msg: clean(message || ""), gift});
|
||||
achievements.add(account, achievements.VARS.jamAGramsSent);
|
||||
if (gift) {
|
||||
achievements.add(account, achievements.VARS.giftsSent);
|
||||
|
||||
+12
-2
@@ -4,6 +4,7 @@ const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const accounts = require("./accounts.js");
|
||||
const chatFilter = require("./chatfilter.js");
|
||||
const masterpieces = require("./masterpieces.js");
|
||||
const limits = require("./limits.js");
|
||||
const {isUint} = require("./player.js");
|
||||
@@ -72,7 +73,7 @@ const flat = value => scalar(value) || (typeof value === "object" && !Array.isAr
|
||||
const plainParam = value => flat(value) || (Array.isArray(value) && value.length <= MAX_PARAM_ENTRIES && value.every(flat));
|
||||
const whole = value => (Number.isInteger(Number(value)) ? Number(value) : 0);
|
||||
|
||||
module.exports = ({blocks}) => {
|
||||
module.exports = ({blocks, findOnline}) => {
|
||||
const tokens = new Map(); // token -> {viewer: account id, owner: account id, expires}
|
||||
|
||||
const mayOpen = (owner, viewer) => {
|
||||
@@ -150,7 +151,16 @@ module.exports = ({blocks}) => {
|
||||
const put = (owner, viewer, body) => {
|
||||
const colours = Array.isArray(body.ac) ? body.ac.slice(0, 3).map(String) : [];
|
||||
const message = clean(body.m === undefined ? "" : body.m);
|
||||
if (!message || isSilenced(viewer) || !colours.every(isUint) || !postsPerTenMinutes.allow(viewer.id)) {
|
||||
// the server's filter (lib/chatfilter.js) too.
|
||||
const rule = message ? chatFilter.broken(message) : null;
|
||||
if (rule) {
|
||||
console.log(`[filter] ${viewer.username} on ${owner.username}'s wall: "${message}" (${rule})`);
|
||||
const session = findOnline(viewer.username);
|
||||
if (session) {
|
||||
chatFilter.warn(session);
|
||||
}
|
||||
}
|
||||
if (!message || rule || isSilenced(viewer) || !colours.every(isUint) || !postsPerTenMinutes.allow(viewer.id)) {
|
||||
// PlayerWallGui.onMessageSent: cs -1 = "could not be posted"
|
||||
return {PUT: {s: false, cs: -1}};
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ const avatarHandlers = require("./avatars.js");
|
||||
const badges = require("./badges.js");
|
||||
const bans = require("./bans.js");
|
||||
const chatlog = require("./chatlog.js");
|
||||
const chatFilter = require("./chatfilter.js");
|
||||
const buddyModule = require("./buddies.js");
|
||||
const dens = require("./dens.js");
|
||||
const disguises = require("./disguises.js");
|
||||
@@ -1345,6 +1346,17 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
fields[0] = said;
|
||||
// the server's filter (lib/chatfilter.js): the line reaches
|
||||
// nobody, the sender sees the game's warning screen, and it is
|
||||
// kept in the chat log for the moderators, marked as not sent.
|
||||
const rule = chatFilter.broken(said);
|
||||
if (rule) {
|
||||
session.sendXt("uc", session.room.id, session.id, -1, 5);
|
||||
chatFilter.warn(session);
|
||||
chatlog.record(session.account, session.room.name, `(not sent) ${said}`);
|
||||
console.log(`[filter] ${session.name} in ${session.room.name}: "${said}" (${rule})`);
|
||||
return;
|
||||
}
|
||||
session.recentChat.push(`${new Date().toISOString().slice(11, 19)} ${said}`);
|
||||
session.recentChat = session.recentChat.slice(-RECENT_CHAT_LINES);
|
||||
chatlog.record(session.account, session.room.name, said);
|
||||
|
||||
@@ -737,7 +737,8 @@ package gui
|
||||
return;
|
||||
}
|
||||
gMainFrame.stage.focus = null;
|
||||
loadValentinesPopup();
|
||||
// Burrow: no secret valentines, so no popup asking which to send
|
||||
sendECard(param1);
|
||||
}
|
||||
|
||||
private function sendMailBtnOverHandler(param1:MouseEvent) : void
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user