Binato/server/Packets/SendPublicMessage.js

58 lines
2.1 KiB
JavaScript
Raw Normal View History

const osu = require("osu-packet"),
botCommandHandler = require("../BotCommandHandler.js"),
2022-08-26 12:52:00 +01:00
consoleHelper = require("../../consoleHelper.js"),
Streams = require("../Streams.js");
2020-08-27 13:09:35 +01:00
2021-01-26 12:26:46 +00:00
module.exports = function(CurrentUser, CurrentPacket) {
let isSendingChannelLocked = false;
for (let i = 0; i < global.channels.length; i++) {
if (!CurrentPacket.target.includes("#")) break;
if (global.channels[i].channelName == CurrentPacket.target) {
isSendingChannelLocked = global.channels[i].locked;
break;
}
}
if (isSendingChannelLocked) {
if (CurrentPacket.message.includes("!")) {
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
} else {
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: global.botUser.username,
message: "The channel you are currently trying to send to is locked, please check back later!",
target: CurrentPacket.target,
senderId: global.botUser.id
});
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
return;
}
consoleHelper.printChat(`${CurrentUser.username} in ${CurrentPacket.target} sent: ${CurrentPacket.message}`);
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: CurrentUser.username,
message: CurrentPacket.message,
target: CurrentPacket.target,
senderId: CurrentUser.id
});
2020-08-27 13:09:35 +01:00
if (CurrentPacket.target == "#multiplayer") {
2022-08-26 12:52:00 +01:00
Streams.sendToStream(CurrentUser.currentMatch.matchChatStreamName, osuPacketWriter.toBuffer, CurrentUser.uuid);
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentUser.currentMatch.matchChatStreamName, true);
return;
}
2020-08-27 13:09:35 +01:00
// Check the stream that we're sending to even exists
2022-08-26 12:52:00 +01:00
if (!Streams.exists(CurrentPacket.target)) return;
2020-08-27 13:09:35 +01:00
// Write chat message to stream asociated with chat channel
2022-08-26 12:52:00 +01:00
Streams.sendToStream(CurrentPacket.target, osuPacketWriter.toBuffer, CurrentUser.uuid);
if (CurrentPacket.target == "#osu")
global.addChatMessage(`${CurrentUser.username}: ${CurrentPacket.message.replaceAll("<", "&lt;").replaceAll(">", "&gt;")}`);
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
return;
2020-08-27 13:09:35 +01:00
}