mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-19 06:29:50 -04:00
Core/Chat: Rewrite some custom channel handling. Channel creation now properly saves passwords. Closes #23589.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -162,10 +162,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 _playersStore.size(); }
|
||||
|
||||
@@ -174,7 +174,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);
|
||||
|
||||
void KickOrBan(Player const* player, std::string const& badname, bool ban);
|
||||
|
||||
@@ -72,40 +72,53 @@ Channel* ChannelMgr::GetChannelForPlayerByNamePart(std::string const& namePart,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Channel* ChannelMgr::GetJoinChannel(uint32 channelId, std::string const& name, AreaTableEntry const* zoneEntry /*= nullptr*/)
|
||||
Channel* ChannelMgr::GetSystemChannel(uint32 channelId, AreaTableEntry const* zoneEntry)
|
||||
{
|
||||
if (channelId) // builtin
|
||||
{
|
||||
ChatChannelsEntry const* channelEntry = sChatChannelsStore.AssertEntry(channelId);
|
||||
uint32 zoneId = zoneEntry ? zoneEntry->ID : 0;
|
||||
if (channelEntry->flags & (CHANNEL_DBC_FLAG_GLOBAL | CHANNEL_DBC_FLAG_CITY_ONLY))
|
||||
zoneId = 0;
|
||||
ChatChannelsEntry const* channelEntry = sChatChannelsStore.AssertEntry(channelId);
|
||||
uint32 zoneId = zoneEntry ? zoneEntry->ID : 0;
|
||||
if (channelEntry->flags & (CHANNEL_DBC_FLAG_GLOBAL | CHANNEL_DBC_FLAG_CITY_ONLY))
|
||||
zoneId = 0;
|
||||
|
||||
std::pair<uint32, uint32> key = std::make_pair(channelId, zoneId);
|
||||
std::pair<uint32, uint32> key = std::make_pair(channelId, zoneId);
|
||||
|
||||
auto itr = _channels.find(key);
|
||||
if (itr != _channels.end())
|
||||
return itr->second;
|
||||
auto itr = _channels.find(key);
|
||||
if (itr != _channels.end())
|
||||
return itr->second;
|
||||
|
||||
Channel* newChannel = new Channel(channelId, _team, zoneEntry);
|
||||
_channels[key] = newChannel;
|
||||
return newChannel;
|
||||
}
|
||||
else // custom
|
||||
{
|
||||
std::wstring channelName;
|
||||
if (!Utf8toWStr(name, channelName))
|
||||
return nullptr;
|
||||
Channel* newChannel = new Channel(channelId, _team, zoneEntry);
|
||||
_channels[key] = newChannel;
|
||||
return newChannel;
|
||||
}
|
||||
|
||||
wstrToLower(channelName);
|
||||
auto itr = _customChannels.find(channelName);
|
||||
if (itr != _customChannels.end())
|
||||
return itr->second;
|
||||
Channel* ChannelMgr::CreateCustomChannel(std::string const& name)
|
||||
{
|
||||
std::wstring channelName;
|
||||
if (!Utf8toWStr(name, channelName))
|
||||
return nullptr;
|
||||
|
||||
Channel* newChannel = new Channel(name, _team);
|
||||
_customChannels[channelName] = newChannel;
|
||||
return newChannel;
|
||||
}
|
||||
wstrToLower(channelName);
|
||||
|
||||
Channel*& c = _customChannels[channelName];
|
||||
if (c)
|
||||
return nullptr;
|
||||
|
||||
Channel* newChannel = new Channel(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 pkt /*= true*/, AreaTableEntry const* zoneEntry /*= nullptr*/) const
|
||||
|
||||
@@ -41,7 +41,9 @@ class TC_GAME_API ChannelMgr
|
||||
static ChannelMgr* forTeam(uint32 team);
|
||||
static Channel* GetChannelForPlayerByNamePart(std::string const& namePart, 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 pkt = true, AreaTableEntry const* zoneEntry = nullptr) const;
|
||||
void LeftChannel(std::string const& name);
|
||||
void LeftChannel(uint32 channelId, AreaTableEntry const* zoneEntry);
|
||||
|
||||
@@ -5099,7 +5099,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->ChannelID, std::string(), current_zone);
|
||||
joinChannel = cMgr->GetSystemChannel(channelEntry->ChannelID, current_zone);
|
||||
if (usedChannel)
|
||||
{
|
||||
if (joinChannel != usedChannel)
|
||||
@@ -5112,13 +5112,13 @@ void Player::UpdateLocalChannels(uint32 newZone)
|
||||
}
|
||||
}
|
||||
else
|
||||
joinChannel = cMgr->GetJoinChannel(channelEntry->ChannelID, std::string());
|
||||
joinChannel = cMgr->GetSystemChannel(channelEntry->ChannelID);
|
||||
}
|
||||
else
|
||||
removeChannel = usedChannel;
|
||||
|
||||
if (joinChannel)
|
||||
joinChannel->JoinChannel(this, ""); // Changed Channel: ... or Joined Channel: ...
|
||||
joinChannel->JoinChannel(this); // Changed Channel: ... or Joined Channel: ...
|
||||
|
||||
if (removeChannel)
|
||||
{
|
||||
|
||||
@@ -68,8 +68,23 @@ void WorldSession::HandleJoinChannel(WorldPacket& recvPacket)
|
||||
return;
|
||||
|
||||
if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam()))
|
||||
if (Channel* channel = cMgr->GetJoinChannel(channelId, channelName, zone))
|
||||
channel->JoinChannel(GetPlayer(), password);
|
||||
{
|
||||
if (channelId)
|
||||
{ // system channel
|
||||
if (Channel* channel = cMgr->GetSystemChannel(channelId, zone))
|
||||
channel->JoinChannel(GetPlayer());
|
||||
}
|
||||
else
|
||||
{ // custom channel
|
||||
if (Channel* channel = cMgr->GetCustomChannel(channelName))
|
||||
channel->JoinChannel(GetPlayer(), password);
|
||||
else if (Channel* channel = cMgr->CreateCustomChannel(channelName))
|
||||
{
|
||||
channel->SetPassword(password);
|
||||
channel->JoinChannel(GetPlayer(), password);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WorldSession::HandleLeaveChannel(WorldPacket& recvPacket)
|
||||
|
||||
Reference in New Issue
Block a user