diff --git a/server/Packets/TourneyLeaveMatchChannel.js b/server/Packets/TourneyLeaveMatchChannel.js new file mode 100644 index 0000000..f1f3fd1 --- /dev/null +++ b/server/Packets/TourneyLeaveMatchChannel.js @@ -0,0 +1,30 @@ +const osu = require("osu-packet"); + +module.exports = function(CurrentUser, MatchID) { + const match = global.MultiplayerManager.getMatch(MatchID); + + if (match != null) { + + match.isTourneyMatch = false; + match.tourneyClientUsers = []; + + if (global.StreamsHandler.isUserInStream(match.matchStreamName, CurrentUser.uuid)) + return global.consoleHelper.printBancho(`Did not add user to channel ${match.matchStreamName} because they are already in it`); + + const osuPacketWriter = new osu.Bancho.Writer; + + osuPacketWriter.ChannelRevoked("#multiplayer"); + if (!global.StreamsHandler.isUserInStream(match.matchStreamName, CurrentUser.uuid)) + global.StreamsHandler.removeUserFromStream(match.matchStreamName, CurrentUser.uuid); + + CurrentUser.addActionToQueue(osuPacketWriter.toBuffer); + } else { + // Still provide feedback just in case + // TODO: Check if this has any effect, if not then remove this. + const osuPacketWriter = new osu.Bancho.Writer; + + osuPacketWriter.ChannelRevoked("#multiplayer"); + + CurrentUser.addActionToQueue(osuPacketWriter.toBuffer); + } +} \ No newline at end of file diff --git a/server/serverHandler.js b/server/serverHandler.js index 17fc1e6..9e6c039 100644 --- a/server/serverHandler.js +++ b/server/serverHandler.js @@ -114,7 +114,8 @@ const ChangeAction = require("./Packets/ChangeAction.js"), UserStatsRequest = require("./Packets/UserStatsRequest.js"), MultiplayerInvite = require("./Packets/MultiplayerInvite.js"), TourneyMatchSpecialInfo = require("./Packets/TourneyMatchSpecialInfo.js"), - TourneyMatchJoinChannel = require("./Packets/TourneyMatchSpecialInfo.js"); + TourneyMatchJoinChannel = require("./Packets/TourneyMatchSpecialInfo.js"), + TourneyMatchLeaveChannel = require("./Packets/TourneyLeaveMatchChannel.js"); // A class for managing everything multiplayer global.MultiplayerManager = new MultiplayerManager(); @@ -306,6 +307,10 @@ module.exports = function(req, res) { TourneyMatchJoinChannel(PacketUser, CurrentPacket.data); break; + case packetIDs.client_specialLeaveMatchChannel: + TourneyMatchLeaveChannel(PacketUser, CurrentPacket.data); + break; + case packetIDs.client_invite: MultiplayerInvite(PacketUser, CurrentPacket.data); break;