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

(cherry picked from commit 8c16f318fe)
This commit is contained in:
Treeston
2019-07-13 17:44:41 +02:00
committed by Shauren
parent 71b2f8c6ab
commit ea753efb93
6 changed files with 64 additions and 35 deletions

View File

@@ -204,7 +204,7 @@ void Channel::JoinChannel(Player* player, std::string const& pass)
return;
}
if (!_channelPassword.empty() && pass != _channelPassword)
if (!CheckPassword(pass))
{
WrongPasswordAppend appender;
ChannelNameBuilder<WrongPasswordAppend> builder(this, appender);

View File

@@ -185,10 +185,10 @@ class TC_GAME_API Channel
bool IsLFG() const { return (GetFlags() & CHANNEL_FLAG_LFG) != 0; }
bool IsAnnounce() const { return _announceEnabled; }
void SetAnnounce(bool nannounce) { _announceEnabled = nannounce; }
void SetAnnounce(bool announce) { _announceEnabled = announce; }
std::string const& GetPassword() const { return _channelPassword; }
void SetPassword(std::string const& npassword) { _channelPassword = npassword; }
void SetPassword(std::string const& password) { _channelPassword = password; }
bool CheckPassword(std::string const& password) const { return _channelPassword.empty() || (_channelPassword == password); }
uint32 GetNumPlayers() const { return uint32(_playersStore.size()); }
@@ -197,7 +197,7 @@ class TC_GAME_API Channel
AreaTableEntry const* GetZoneEntry() const { return _zoneEntry; }
void JoinChannel(Player* player, std::string const& pass);
void JoinChannel(Player* player, std::string const& pass = "");
void LeaveChannel(Player* player, bool send = true, bool suspend = false);
void KickOrBan(Player const* player, std::string const& badname, bool ban);

View File

@@ -82,35 +82,47 @@ Channel* ChannelMgr::GetChannelForPlayerByGuid(ObjectGuid channelGuid, Player* p
return nullptr;
}
Channel* ChannelMgr::GetJoinChannel(uint32 channelId, std::string const& name, AreaTableEntry const* zoneEntry /*= nullptr*/)
Channel* ChannelMgr::GetSystemChannel(uint32 channelId, AreaTableEntry const* zoneEntry /* = nullptr */)
{
if (channelId) // builtin
{
ObjectGuid channelGuid = CreateBuiltinChannelGuid(channelId, zoneEntry);
auto itr = _channels.find(channelGuid);
if (itr != _channels.end())
return itr->second;
ObjectGuid channelGuid = CreateBuiltinChannelGuid(channelId, zoneEntry);
auto itr = _channels.find(channelGuid);
if (itr != _channels.end())
return itr->second;
Channel* newChannel = new Channel(channelGuid, channelId, _team, zoneEntry);
_channels[channelGuid] = newChannel;
return newChannel;
}
else // custom
{
std::wstring channelName;
if (!Utf8toWStr(name, channelName))
return nullptr;
Channel* newChannel = new Channel(channelGuid, channelId, _team, zoneEntry);
_channels[channelGuid] = newChannel;
return newChannel;
}
wstrToLower(channelName);
Channel* ChannelMgr::CreateCustomChannel(std::string const& name)
{
std::wstring channelName;
if (!Utf8toWStr(name, channelName))
return nullptr;
auto itr = _customChannels.find(channelName);
if (itr != _customChannels.end())
return itr->second;
wstrToLower(channelName);
Channel* newChannel = new Channel(CreateCustomChannelGuid(), name, _team);
_customChannels[channelName] = newChannel;
return newChannel;
}
Channel*& c = _customChannels[channelName];
if (c)
return nullptr;
Channel* newChannel = new Channel(CreateCustomChannelGuid(), name, _team);
c = newChannel;
return newChannel;
}
Channel* ChannelMgr::GetCustomChannel(std::string const& name) const
{
std::wstring channelName;
if (!Utf8toWStr(name, channelName))
return nullptr;
wstrToLower(channelName);
auto itr = _customChannels.find(channelName);
if (itr != _customChannels.end())
return itr->second;
else
return nullptr;
}
Channel* ChannelMgr::GetChannel(uint32 channelId, std::string const& name, Player* player, bool notify /*= true*/, AreaTableEntry const* zoneEntry /*= nullptr*/) const

View File

@@ -40,7 +40,9 @@ class TC_GAME_API ChannelMgr
static Channel* GetChannelForPlayerByNamePart(std::string const& namePart, Player* playerSearcher);
static Channel* GetChannelForPlayerByGuid(ObjectGuid channelGuid, Player* playerSearcher);
Channel* GetJoinChannel(uint32 channelId, std::string const& name, AreaTableEntry const* zoneEntry = nullptr);
Channel* GetSystemChannel(uint32 channelId, AreaTableEntry const* zoneEntry = nullptr);
Channel* CreateCustomChannel(std::string const& name);
Channel* GetCustomChannel(std::string const& name) const;
Channel* GetChannel(uint32 channelId, std::string const& name, Player* player, bool notify = true, AreaTableEntry const* zoneEntry = nullptr) const;
void LeftChannel(std::string const& name);
void LeftChannel(uint32 channelId, AreaTableEntry const* zoneEntry);

View File

@@ -4889,7 +4889,7 @@ void Player::UpdateLocalChannels(uint32 newZone)
if (channelEntry->Flags & CHANNEL_DBC_FLAG_CITY_ONLY && usedChannel)
continue; // Already on the channel, as city channel names are not changing
joinChannel = cMgr->GetJoinChannel(channelEntry->ID, std::string(), current_zone);
joinChannel = cMgr->GetSystemChannel(channelEntry->ID, current_zone);
if (usedChannel)
{
if (joinChannel != usedChannel)
@@ -4902,13 +4902,13 @@ void Player::UpdateLocalChannels(uint32 newZone)
}
}
else
joinChannel = cMgr->GetJoinChannel(channelEntry->ID, std::string());
joinChannel = cMgr->GetSystemChannel(channelEntry->ID);
}
else
removeChannel = usedChannel;
if (joinChannel)
joinChannel->JoinChannel(this, ""); // Changed Channel: ... or Joined Channel: ...
joinChannel->JoinChannel(this); // Changed Channel: ... or Joined Channel: ...
if (removeChannel)
{

View File

@@ -58,8 +58,23 @@ void WorldSession::HandleJoinChannel(WorldPackets::Channel::JoinChannel& packet)
return;
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
if (Channel* channel = cMgr->GetJoinChannel(packet.ChatChannelId, packet.ChannelName, zone))
channel->JoinChannel(GetPlayer(), packet.Password);
{
if (packet.ChatChannelId)
{ // system channel
if (Channel* channel = cMgr->GetSystemChannel(packet.ChatChannelId, zone))
channel->JoinChannel(GetPlayer());
}
else
{ // custom channel
if (Channel* channel = cMgr->GetCustomChannel(packet.ChannelName))
channel->JoinChannel(GetPlayer(), packet.Password);
else if (Channel* channel = cMgr->CreateCustomChannel(packet.ChannelName))
{
channel->SetPassword(packet.Password);
channel->JoinChannel(GetPlayer(), packet.Password);
}
}
}
}
void WorldSession::HandleLeaveChannel(WorldPackets::Channel::LeaveChannel& packet)