From de5b4841de6730cf05ebcb90a88bb15c7c470088 Mon Sep 17 00:00:00 2001 From: tgpethan Date: Wed, 2 Sep 2020 10:57:12 +0100 Subject: [PATCH] Implement private messages --- server/Packets/SendPrivateMessage.js | 20 ++++++++++++++++++++ server/serverHandler.js | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 server/Packets/SendPrivateMessage.js diff --git a/server/Packets/SendPrivateMessage.js b/server/Packets/SendPrivateMessage.js new file mode 100644 index 0000000..4d7ddaa --- /dev/null +++ b/server/Packets/SendPrivateMessage.js @@ -0,0 +1,20 @@ +const osu = require("osu-packet"), + getUserByUsername = require("../util/getUserByUsername.js"); + +module.exports = function(CurrentPacket, CurrentUser) { + const osuPacketWriter = new osu.Bancho.Writer; + + osuPacketWriter.ChannelJoinSuccess(CurrentUser.username); + + osuPacketWriter.SendMessage({ + sendingClient: CurrentUser.username, + message: CurrentPacket.data.message, + target: CurrentPacket.data.target, + senderId: CurrentUser.id + }); + + const userSentTo = getUserByUsername(CurrentPacket.data.target); + + // Write chat message to stream asociated with chat channel + return userSentTo.addActionToQueue(osuPacketWriter.toBuffer); +} \ No newline at end of file diff --git a/server/serverHandler.js b/server/serverHandler.js index d8076ea..7367e61 100644 --- a/server/serverHandler.js +++ b/server/serverHandler.js @@ -84,6 +84,7 @@ const ChangeAction = require("./Packets/ChangeAction.js"), SendPublicMessage = require("./Packets/SendPublicMessage.js"), Logout = require("./Packets/Logout.js"), Spectator = require("./Spectator.js"), + SendPrivateMessage = require("./Packets/SendPrivateMessage.js"), Multiplayer = require("./Multiplayer.js"), ChannelPart = require("./Packets/ChannelPart.js"), UserPresenceBundle = require("./Packets/UserPresenceBundle.js"), @@ -160,6 +161,10 @@ module.exports = function(req, res) { Spectator.stopSpectatingUser(userClass); break; + case packetIDs.client_sendPrivateMessage: + SendPrivateMessage(CurrentPacket, userClass); + break; + case packetIDs.client_joinLobby: Multiplayer.userEnterLobby(userClass); break;