add word filter

This commit is contained in:
Elijah R 2024-07-12 15:58:40 -04:00
parent dab1b26429
commit 1d19098ca7
3 changed files with 9 additions and 0 deletions

View file

@ -14,6 +14,7 @@ charlimit = 100
agentsDir = "agents/" agentsDir = "agents/"
maxConnectionsPerIP = 2 maxConnectionsPerIP = 2
adminPasswordHash = "f52fbd32b2b3b86ff88ef6c490628285f482af15ddcb29541f94bcf526a3f6c7" adminPasswordHash = "f52fbd32b2b3b86ff88ef6c490628285f482af15ddcb29541f94bcf526a3f6c7"
bannedWords = []
[chat.ratelimits] [chat.ratelimits]
chat = {seconds = 10, limit = 8} chat = {seconds = 10, limit = 8}

View file

@ -103,6 +103,10 @@ export class Client extends EventEmitter {
return; return;
} }
let username = htmlentities.encode(joinMsg.data.username); let username = htmlentities.encode(joinMsg.data.username);
if (this.room.config.bannedWords.some(w => username.indexOf(w) !== -1)) {
this.socket.close();
return;
}
if (this.room.clients.some(u => u.username === username)) { if (this.room.clients.some(u => u.username === username)) {
let i = 1; let i = 1;
let uo = username; let uo = username;
@ -125,6 +129,9 @@ export class Client extends EventEmitter {
return; return;
} }
if (talkMsg.data.msg.length > this.room.config.charlimit) return; if (talkMsg.data.msg.length > this.room.config.charlimit) return;
if (this.room.config.bannedWords.some(w => talkMsg.data.msg.indexOf(w) !== -1)) {
return;
}
this.emit('talk', talkMsg.data.msg); this.emit('talk', talkMsg.data.msg);
break; break;
} }

View file

@ -24,6 +24,7 @@ export interface ChatConfig {
agentsDir: string; agentsDir: string;
maxConnectionsPerIP: number; maxConnectionsPerIP: number;
adminPasswordHash: string; adminPasswordHash: string;
bannedWords: string[];
ratelimits: { ratelimits: {
chat: RateLimitConfig; chat: RateLimitConfig;
} }