Binato/server/Packets/SendPublicMessage.js

53 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++) {
if (!CurrentPacket.data.target.includes("#")) break;
if (global.channels[i].channelName == CurrentPacket.data.target) {
isSendingChannelLocked = global.channels[i].locked;
break;
}
}
if (isSendingChannelLocked) {
if (CurrentPacket.data.message.includes("!")) {
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentPacket.data.target);
} else {
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: global.users[0].username,
message: "The channel you are currently trying to send to is locked, please come back later!",
target: CurrentPacket.data.target,
senderId: global.users[0].id
});
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
return;
}
2020-08-27 13:09:35 +01:00
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: CurrentUser.username,
message: CurrentPacket.data.message,
target: CurrentPacket.data.target,
senderId: CurrentUser.id
});
if (CurrentPacket.data.target == "#multiplayer") {
2021-01-26 12:26:46 +00:00
global.StreamsHandler.sendToStream(CurrentUser.currentMatch.matchStreamName, osuPacketWriter.toBuffer, CurrentUser.id);
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentUser.currentMatch.matchStreamName, true);
return;
}
2020-08-27 13:09:35 +01:00
// Check the stream that we're sending to even exists
if (!global.StreamsHandler.doesStreamExist(CurrentPacket.data.target)) return;
// Write chat message to stream asociated with chat channel
global.StreamsHandler.sendToStream(CurrentPacket.data.target, osuPacketWriter.toBuffer, CurrentUser.id);
2021-01-26 12:26:46 +00:00
if (CurrentPacket.data.target == "#osu")
global.addChatMessage(`${CurrentUser.username}: ${CurrentPacket.data.message}`);
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentPacket.data.target);
return;
2020-08-27 13:09:35 +01:00
}