Core/Chat: Rewrite some custom channel handling. Channel creation now properly saves passwords.

Port From (https://github.com/TrinityCore/TrinityCore/commit/ea753efb9370455979c8af8ebaafa734b77d6052)
This commit is contained in:
hondacrx
2021-12-27 17:23:39 -05:00
parent 855c9611e0
commit 12f472cee1
4 changed files with 56 additions and 34 deletions
+6 -6
View File
@@ -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; }
+23 -21
View File
@@ -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;
+3 -3
View File
@@ -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)
{
+24 -4
View File
@@ -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);
}
}
}
}
}