Binato/server/Packets/SendPublicMessage.js

56 lines
2.3 KiB
JavaScript
Raw Normal View History

const osu = require("osu-packet"),
botCommandHandler = require("../BotCommandHandler.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++) {
2021-09-24 01:39:46 +01:00
if (!CurrentPacket.target.includes("#")) break;
if (global.channels[i].channelName == CurrentPacket.target) {
isSendingChannelLocked = global.channels[i].locked;
break;
}
}
if (isSendingChannelLocked) {
2021-09-24 01:39:46 +01:00
if (CurrentPacket.message.includes("!")) {
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
} else {
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
2021-05-15 00:24:39 +01:00
sendingClient: global.users["bot"].username,
2021-02-06 01:20:32 +00:00
message: "The channel you are currently trying to send to is locked, please check back later!",
2021-09-24 01:39:46 +01:00
target: CurrentPacket.target,
2021-05-15 00:24:39 +01:00
senderId: global.users["bot"].id
});
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
return;
}
2021-09-24 01:39:46 +01:00
global.consoleHelper.printChat(`${CurrentUser.username} in ${CurrentPacket.target} sent: ${CurrentPacket.message}`);
2020-08-27 13:09:35 +01:00
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: CurrentUser.username,
2021-09-24 01:39:46 +01:00
message: CurrentPacket.message,
target: CurrentPacket.target,
2020-08-27 13:09:35 +01:00
senderId: CurrentUser.id
});
2021-09-24 01:39:46 +01:00
if (CurrentPacket.target == "#multiplayer") {
global.StreamsHandler.sendToStream(CurrentUser.currentMatch.matchChatStreamName, osuPacketWriter.toBuffer, CurrentUser.uuid);
2021-09-24 01:39:46 +01:00
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
2021-09-24 01:39:46 +01:00
if (!global.StreamsHandler.doesStreamExist(CurrentPacket.target)) return;
2020-08-27 13:09:35 +01:00
// Write chat message to stream asociated with chat channel
2021-09-24 01:39:46 +01:00
global.StreamsHandler.sendToStream(CurrentPacket.target, osuPacketWriter.toBuffer, CurrentUser.uuid);
if (CurrentPacket.target == "#osu")
global.addChatMessage(`${CurrentUser.username}: ${CurrentPacket.message}`);
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
return;
2020-08-27 13:09:35 +01:00
}