From a00aba5825e69fa89002afec4f70a0db471f1d31 Mon Sep 17 00:00:00 2001 From: Holly Date: Sun, 10 Sep 2023 18:32:45 +0100 Subject: [PATCH] Allow users to join chat channels --- server/BanchoServer.ts | 4 ++-- server/objects/User.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server/BanchoServer.ts b/server/BanchoServer.ts index edabed5..5cfda62 100644 --- a/server/BanchoServer.ts +++ b/server/BanchoServer.ts @@ -234,11 +234,11 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_ChannelJoin: - //ChannelJoin(PacketUser, CurrentPacket.data); + PacketUser.joinChannel(CurrentPacket.data); break; case Packets.Client_ChannelPart: - //ChannelPart(PacketUser, CurrentPacket.data); + PacketUser.leaveChannel(CurrentPacket.data); break; case Packets.Client_SetAwayMessage: diff --git a/server/objects/User.ts b/server/objects/User.ts index 283605b..112e366 100644 --- a/server/objects/User.ts +++ b/server/objects/User.ts @@ -5,6 +5,7 @@ import DataStream from "./DataStream"; import StatusUpdate from "../packets/StatusUpdate"; import Shared from "../objects/Shared"; import Slot from "./Slot"; +import Channel from "./Channel"; const rankingModes = [ "pp_raw", @@ -144,4 +145,18 @@ export default class User { StatusUpdate(this, this.id); } } + + joinChannel(channelName:string) { + const channel = this.shared.chatManager.GetChannelByName(channelName); + if (channel instanceof Channel) { + channel.Join(this); + } + } + + leaveChannel(channelName:string) { + const channel = this.shared.chatManager.GetChannelByName(channelName); + if (channel instanceof Channel) { + channel.Leave(this); + } + } } \ No newline at end of file