Volatile chat buffer for channel-only chats implemented.

This commit is contained in:
rainbow napkin 2025-06-11 08:27:56 -04:00
parent 8821b5cff9
commit 366df357b8
4 changed files with 27 additions and 4 deletions

View file

@ -31,8 +31,8 @@ module.exports = class{
this.server = server;
//Initialize command preprocessor
this.commandPreprocessor = new commandPreprocessor(server, this)
//Define the chat buffer
this.chatBuffer = [];
//Max chat buffer size
this.chatBufferSize = 50;
}
defineListeners(socket){
@ -135,7 +135,19 @@ module.exports = class{
}
relayChatObject(chan, chat){
//Send out chat
this.server.io.in(chan).emit("chatMessage", chat);
const channel = this.server.activeChannels.get(chan);
//If chat buffer length is over mandated size
if(channel.chatBuffer.length >= this.chatBufferSize){
//Take out oldest chat
channel.chatBuffer.shift();
}
//Add buffer to chat
channel.chatBuffer.push(chat);
}
relayPrivateChat(socket, user, flair, highLevel, msg, type, links){
@ -147,7 +159,7 @@ module.exports = class{
}
relayGlobalChat(user, flair, highLevel, msg, type = 'chat', links){
this.relayGlobalChatObject("chatMessage", new chat(user, flair, highLevel, msg, type, links));
this.relayGlobalChatObject(new chat(user, flair, highLevel, msg, type, links));
}
relayGlobalChatObject(chat){