feat(filter): the chat filters cover animals' and pets' names

- server: a typed name the filter (lib/chat-filter.txt) stops is
  refused at xrn, with the game's warning and a line in the log; one
  saved before is cleared at login (the animal takes the username, the
  pet is "Pet"). the game's own word-id names are never looked at.
- client: LocalizationManager.translateAvatarName and translatePetName
  pass a typed name through the player's own filter
  (AJClient.filterName), wherever the game shows it. a name cannot be
  left out, so with "Hide the whole message" its words are starred.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
BurrowdevandClaude Opus 5.5 committed 2026-10-21 20:50:44 +03:00
1 parent 34db374527
commit 43ae95fbca
4 files changed
+1030 -3

No files matched your search

+20 -1
View File
@@ -144,6 +144,9 @@ const MAX_PATH_POINTS = 12;
// created that avatar.
const ACTION_NAME = /^:[A-Za-z][A-Za-z0-9]*:$/;
const TYPED_NAME = /^[A-Za-z0-9][A-Za-z0-9 '.-]{0,19}$/; // an animal's or pet's name typed by its owner
// a typed name the server's filter (lib/chat-filter.txt) stops. the game's
// own names are word ids ("123|456"), which it never does.
const nameFiltered = name => !String(name).includes("|") && Boolean(chatFilter.broken(String(name)));
const MAX_BLOCKED = 1000; // from the account page; the game's own button has no limit
const TYPED_CHAT_TYPES = ["0", "9"];
const MAX_CHAT_EXTRA = 100; // the field after a chat line's type
@@ -381,6 +384,17 @@ const login = (session, msg) => {
existing.close();
leaveWorld(existing);
}
// a name typed before the filter covered names, or one a newer rule
// catches: the animal takes the username, the pet is "Pet".
const filteredNames = [...account.avatars.filter(avatar => nameFiltered(avatar.name)),
...account.pets.filter(pet => nameFiltered(pet.name))];
if (filteredNames.length) {
for (const thing of filteredNames) {
console.log(`[filter] ${logText(account.username)}'s name "${logText(thing.name)}" cleared`);
thing.name = account.avatars.includes(thing) ? account.username : "Pet";
}
accounts.save(account);
}
session.account = account;
accounts.hold(account);
account.numLogins++;
@@ -1073,7 +1087,12 @@ const handlers = {
const thing = kind === "a" ? account.avatars.find(avatar => avatar.perUserAvId === Number(id))
: kind === "p" ? account.pets.find(pet => pet.inv === Number(id)) : null;
// typed words others read: not while silenced.
const ok = Boolean(thing) && TYPED_NAME.test(wanted) && !moderation.isSilenced(account);
const filtered = Boolean(thing) && TYPED_NAME.test(wanted) && nameFiltered(wanted);
const ok = Boolean(thing) && TYPED_NAME.test(wanted) && !filtered && !moderation.isSilenced(account);
if (filtered) {
console.log(`[filter] ${logText(session.name)} named ${kind === "a" ? "an animal" : "a pet"}: "${logText(wanted)}" (${logText(chatFilter.broken(wanted))})`);
chatFilter.warn(session);
}
if (ok) {
thing.name = wanted;
accounts.save(account);