Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
Emupedia-Bot committed Sep 4, 2024
1 parent 5d662f2 commit 3cdac3e
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions servers/agarv2/src/protocols/LegacyProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ class LegacyProtocol extends Protocol {
return true;
}

filterName(name) {
let newname = name || ''

for (let i = 0, l = this.settings.chatFilteredPhrases.length; i < l; i++) {
if (newname.toLowerCase().indexOf(this.settings.chatFilteredPhrases[i].toLowerCase()) !== -1) {
newname = newname.replace(new RegExp(this.settings.chatFilteredPhrases[i], 'gi'), '')
}
}

if (newname === '') {
return 'An unnamed cell'
}

return newname
}

/**
* @param {Reader} reader
*/
Expand All @@ -65,15 +81,16 @@ class LegacyProtocol extends Protocol {
this.key = reader.readUInt32();
this.connection.createPlayer();

const chatName = readZTString(reader, this.protocol)
this.connection.player.chatName = chatName ? chatName : this.connection.player.chatName;
const chatName = this.filterName(readZTString(reader, this.protocol))
this.connection.player.chatName = chatName ? chatName : this.connection.player.chatName

return;
}

switch (messageId) {
case 0:
this.connection.spawningName = readZTString(reader, this.protocol);
const spawningName = this.filterName(readZTString(reader, this.protocol))
this.connection.spawningName = spawningName ? spawningName : this.connection.spawningName
break;
case 1:
this.connection.requestingSpectate = true;
Expand Down Expand Up @@ -159,8 +176,8 @@ class LegacyProtocol extends Protocol {

reader.skip(skipLen);
const message = readZTString(reader, this.protocol);
this.logger.inform(`[${this.connection.remoteAddress}][${this.connection.verifyScore}][${this.connection.player.id ? this.connection.player.id : 0}][${this.connection.player.cellSkin ? this.connection.player.cellSkin.split('|').slice(-1) : ''}][${this.connection.player.cellSkin ? this.connection.player.cellSkin.split('|')[0] : ''}] <${this.connection.player.chatName}>: '${message}'`);
this.connection.onChatMessage(message);
this.logger.inform(`[${this.connection.remoteAddress}][${this.connection.verifyScore}][${this.connection.player.id ? this.connection.player.id : 0}][${this.connection.player.cellSkin ? this.connection.player.cellSkin.split('|').slice(-1) : ''}][${this.connection.player.cellSkin ? this.connection.player.cellSkin.split('|')[0] : ''}] <${this.connection.player.chatName}>: '${message}'`);
break;
case 254:
if (this.connection.hasPlayer && this.connection.player.hasWorld) {
Expand Down

0 comments on commit 3cdac3e

Please sign in to comment.