diff --git a/Source/Game/Chat/Channels/Channel.cs b/Source/Game/Chat/Channels/Channel.cs index 5eafc0778..5d420a148 100644 --- a/Source/Game/Chat/Channels/Channel.cs +++ b/Source/Game/Chat/Channels/Channel.cs @@ -172,7 +172,7 @@ namespace Game.Chat } } - public void JoinChannel(Player player, string pass) + public void JoinChannel(Player player, string pass = "") { ObjectGuid guid = player.GetGUID(); if (IsOn(guid)) @@ -193,7 +193,7 @@ namespace Game.Chat return; } - if (!string.IsNullOrEmpty(_channelPassword) && pass != _channelPassword) + if (!CheckPassword(pass)) { var builder = new ChannelNameBuilder(this, new WrongPasswordAppend()); SendToOne(builder, guid); @@ -892,11 +892,11 @@ namespace Game.Chat public bool IsLFG() { return GetFlags().HasAnyFlag(ChannelFlags.Lfg); } bool IsAnnounce() { return _announceEnabled; } - void SetAnnounce(bool nannounce) { _announceEnabled = nannounce; } - - string GetPassword() { return _channelPassword; } - void SetPassword(string npassword) { _channelPassword = npassword; } + void SetAnnounce(bool announce) { _announceEnabled = announce; } + public void SetPassword(string npassword) { _channelPassword = npassword; } + public bool CheckPassword(string password) { return _channelPassword.IsEmpty() || (_channelPassword == password); } + public uint GetNumPlayers() { return (uint)_playersStore.Count; } public ChannelFlags GetFlags() { return _channelFlags; } diff --git a/Source/Game/Chat/Channels/ChannelManager.cs b/Source/Game/Chat/Channels/ChannelManager.cs index bd5e237c6..98fc5a0d2 100644 --- a/Source/Game/Chat/Channels/ChannelManager.cs +++ b/Source/Game/Chat/Channels/ChannelManager.cs @@ -67,31 +67,33 @@ namespace Game.Chat return null; } - public Channel GetJoinChannel(uint channelId, string name, AreaTableRecord zoneEntry = null) + public Channel GetSystemChannel(uint channelId, AreaTableRecord zoneEntry = null) { - if (channelId != 0) // builtin - { - ObjectGuid channelGuid = CreateBuiltinChannelGuid(channelId, zoneEntry); - var channel = _channels.LookupByKey(channelGuid); - if (channel != null) - return channel; + ObjectGuid channelGuid = CreateBuiltinChannelGuid(channelId, zoneEntry); + var currentChannel = _channels.LookupByKey(channelGuid); + if (currentChannel != null) + return currentChannel; - Channel newChannel = new(channelGuid, channelId, _team, zoneEntry); - _channels[channelGuid] = newChannel; - return newChannel; - } - else // custom - { - var channel = _customChannels.LookupByKey(name.ToLower()); - if (channel != null) - return channel; - - Channel newChannel = new(CreateCustomChannelGuid(), name, _team); - _customChannels[name.ToLower()] = newChannel; - return newChannel; - } + Channel newChannel = new Channel(channelGuid, channelId, _team, zoneEntry); + _channels[channelGuid] = newChannel; + return newChannel; } + public Channel CreateCustomChannel(string name) + { + if (_customChannels.ContainsKey(name.ToLower())) + return null; + + Channel newChannel = new(CreateCustomChannelGuid(), name, _team); + _customChannels[name.ToLower()] = newChannel; + return newChannel; + } + + public Channel GetCustomChannel(string name) + { + return _customChannels.LookupByKey(name.ToLower()); + } + public Channel GetChannel(uint channelId, string name, Player player, bool notify = true, AreaTableRecord zoneEntry = null) { Channel result = null; diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 750c3729b..fa095136f 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -2636,7 +2636,7 @@ namespace Game.Entities if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.CityOnly) && usedChannel != null) continue; // Already on the channel, as city channel names are not changing - joinChannel = cMgr.GetJoinChannel(channelEntry.Id, "", current_zone); + joinChannel = cMgr.GetSystemChannel(channelEntry.Id, current_zone); if (usedChannel != null) { if (joinChannel != usedChannel) @@ -2649,13 +2649,13 @@ namespace Game.Entities } } else - joinChannel = cMgr.GetJoinChannel(channelEntry.Id, ""); + joinChannel = cMgr.GetSystemChannel(channelEntry.Id); } else removeChannel = usedChannel; if (joinChannel != null) - joinChannel.JoinChannel(this, ""); // Changed Channel: ... or Joined Channel: ... + joinChannel.JoinChannel(this); // Changed Channel: ... or Joined Channel: ... if (removeChannel != null) { diff --git a/Source/Game/Handlers/ChannelHandler.cs b/Source/Game/Handlers/ChannelHandler.cs index 4527289e4..219ded875 100644 --- a/Source/Game/Handlers/ChannelHandler.cs +++ b/Source/Game/Handlers/ChannelHandler.cs @@ -41,7 +41,7 @@ namespace Game return; } - if (string.IsNullOrEmpty(packet.ChannelName)) + if (packet.ChannelName.IsEmpty()) return; if (packet.ChannelName.IsNumber()) @@ -50,9 +50,29 @@ namespace Game ChannelManager cMgr = ChannelManager.ForTeam(GetPlayer().GetTeam()); if (cMgr != null) { - Channel channel = cMgr.GetJoinChannel((uint)packet.ChatChannelId, packet.ChannelName, zone); - if (channel != null) - channel.JoinChannel(GetPlayer(), packet.Password); + if (packet.ChatChannelId != 0) + { + // system channel + Channel channel = cMgr.GetSystemChannel((uint)packet.ChatChannelId, zone); + if (channel != null) + channel.JoinChannel(GetPlayer()); + } + else + { + // custom channel + Channel channel = cMgr.GetCustomChannel(packet.ChannelName); + if (channel != null) + channel.JoinChannel(GetPlayer(), packet.Password); + else + { + channel = cMgr.CreateCustomChannel(packet.ChannelName); + if (channel != null) + { + channel.SetPassword(packet.Password); + channel.JoinChannel(GetPlayer(), packet.Password); + } + } + } } }