Binato/server/Packets/SendPublicMessage.js

51 lines
2.1 KiB
JavaScript
Raw Normal View History

const osu = require("osu-packet"),
botCommandHandler = require("../BotCommandHandler.js");
2020-08-27 13:09:35 +01:00
module.exports = function(CurrentPacket, CurrentUser) {
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") {
global.StreamsHandler.sendToStream(global.matches[CurrentUser.currentMatch][0], osuPacketWriter.toBuffer, CurrentUser.id);
botCommandHandler(CurrentUser, CurrentPacket.data.message, global.matches[CurrentUser.currentMatch][0], 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);
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentPacket.data.target);
return;
2020-08-27 13:09:35 +01:00
}