aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Chat
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2019-07-13 17:44:41 +0200
committerShauren <shauren.trinity@gmail.com>2021-12-16 00:37:01 +0100
commitea753efb9370455979c8af8ebaafa734b77d6052 (patch)
treef34607eef7b093e44510dca18b441146a52e58e3 /src/server/game/Chat
parent71b2f8c6ab26ef7683100fdf288813e87f6bbf73 (diff)
Core/Chat: Rewrite some custom channel handling. Channel creation now properly saves passwords. Closes #23589.
(cherry picked from commit 8c16f318fe072709fc40c61987570dba8f5b6483)
Diffstat (limited to 'src/server/game/Chat')
-rw-r--r--src/server/game/Chat/Channels/Channel.cpp2
-rw-r--r--src/server/game/Chat/Channels/Channel.h8
-rw-r--r--src/server/game/Chat/Channels/ChannelMgr.cpp60
-rw-r--r--src/server/game/Chat/Channels/ChannelMgr.h4
4 files changed, 44 insertions, 30 deletions
diff --git a/src/server/game/Chat/Channels/Channel.cpp b/src/server/game/Chat/Channels/Channel.cpp
index 08994da8cbe..ac60980b713 100644
--- a/src/server/game/Chat/Channels/Channel.cpp
+++ b/src/server/game/Chat/Channels/Channel.cpp
@@ -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);
diff --git a/src/server/game/Chat/Channels/Channel.h b/src/server/game/Chat/Channels/Channel.h
index 9a8399054c2..616da00ed36 100644
--- a/src/server/game/Chat/Channels/Channel.h
+++ b/src/server/game/Chat/Channels/Channel.h
@@ -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);
diff --git a/src/server/game/Chat/Channels/ChannelMgr.cpp b/src/server/game/Chat/Channels/ChannelMgr.cpp
index c572ee48704..3f68a1cd964 100644
--- a/src/server/game/Chat/Channels/ChannelMgr.cpp
+++ b/src/server/game/Chat/Channels/ChannelMgr.cpp
@@ -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;
+}
- 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* ChannelMgr::CreateCustomChannel(std::string const& name)
+{
+ std::wstring channelName;
+ if (!Utf8toWStr(name, channelName))
+ return nullptr;
- wstrToLower(channelName);
+ wstrToLower(channelName);
- auto itr = _customChannels.find(channelName);
- if (itr != _customChannels.end())
- return itr->second;
+ Channel*& c = _customChannels[channelName];
+ if (c)
+ return nullptr;
- Channel* newChannel = new Channel(CreateCustomChannelGuid(), name, _team);
- _customChannels[channelName] = newChannel;
- return newChannel;
- }
+ 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
diff --git a/src/server/game/Chat/Channels/ChannelMgr.h b/src/server/game/Chat/Channels/ChannelMgr.h
index 796a1bd0d6e..e523dd1c04e 100644
--- a/src/server/game/Chat/Channels/ChannelMgr.h
+++ b/src/server/game/Chat/Channels/ChannelMgr.h
@@ -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);