diff options
author | Treeston <treeston.mmoc@gmail.com> | 2019-07-16 13:17:45 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2021-12-16 21:20:38 +0100 |
commit | bd7aae928e699adba63c0a14661cffeb5fdf8b3b (patch) | |
tree | 0f793535c511387b101866769ffe13bacf9a0a98 /src | |
parent | 9fa5c714096a9755a3a7ada45c8d5e6a54f18950 (diff) |
Core/Chat: Properly reload saved channel settings from DB after 8c16f31.
(cherry picked from commit 2c1b87ca298bce37405329b3af0b5e375f4e53ef)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Chat/Channels/Channel.cpp | 56 | ||||
-rw-r--r-- | src/server/game/Chat/Channels/Channel.h | 2 | ||||
-rw-r--r-- | src/server/game/Chat/Channels/ChannelMgr.cpp | 38 | ||||
-rw-r--r-- | src/server/game/Chat/Channels/ChannelMgr.h | 2 |
4 files changed, 50 insertions, 48 deletions
diff --git a/src/server/game/Chat/Channels/Channel.cpp b/src/server/game/Chat/Channels/Channel.cpp index ac60980b713..7d29cf7014d 100644 --- a/src/server/game/Chat/Channels/Channel.cpp +++ b/src/server/game/Chat/Channels/Channel.cpp @@ -58,10 +58,10 @@ Channel::Channel(ObjectGuid const& guid, uint32 channelId, uint32 team /*= 0*/, _channelFlags |= CHANNEL_FLAG_NOT_LFG; } -Channel::Channel(ObjectGuid const& guid, std::string const& name, uint32 team /*= 0*/) : +Channel::Channel(ObjectGuid const& guid, std::string const& name, uint32 team /*= 0*/, std::string const& banList) : _announceEnabled(true), _ownershipEnabled(true), - _persistentChannel(false), + _persistentChannel(sWorld->getBoolConfig(CONFIG_PRESERVE_CUSTOM_CHANNELS)), _isOwnerInvisible(false), _channelFlags(CHANNEL_FLAG_CUSTOM), _channelId(0), @@ -70,48 +70,18 @@ Channel::Channel(ObjectGuid const& guid, std::string const& name, uint32 team /* _channelName(name), _zoneEntry(nullptr) { - // If storing custom channels in the db is enabled either load or save the channel - if (sWorld->getBoolConfig(CONFIG_PRESERVE_CUSTOM_CHANNELS)) + Tokenizer tokens(banList, ' '); + for (auto const& token : tokens) { - CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHANNEL); - stmt->setString(0, _channelName); - stmt->setUInt32(1, _channelTeam); - if (PreparedQueryResult result = CharacterDatabase.Query(stmt)) // load - { - Field* fields = result->Fetch(); - _channelName = fields[0].GetString(); // re-get channel name. MySQL table collation is case insensitive - _announceEnabled = fields[1].GetBool(); - _ownershipEnabled = fields[2].GetBool(); - _channelPassword = fields[3].GetString(); - std::string bannedList = fields[4].GetString(); - - if (!bannedList.empty()) - { - Tokenizer tokens(bannedList, ' '); - for (auto const& token : tokens) - { - // legacy db content might not have 0x prefix, account for that - std::string bannedGuidStr(memcmp(token, "0x", 2) ? token + 2 : token); - ObjectGuid bannedGuid; - bannedGuid.SetRawValue(uint64(strtoull(bannedGuidStr.substr(0, 16).c_str(), nullptr, 16)), uint64(strtoull(bannedGuidStr.substr(16).c_str(), nullptr, 16))); - if (!bannedGuid.IsEmpty()) - { - TC_LOG_DEBUG("chat.system", "Channel (%s) loaded player %s into bannedStore", _channelName.c_str(), bannedGuid.ToString().c_str()); - _bannedStore.insert(bannedGuid); - } - } - } - } - else // save - { - stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHANNEL); - stmt->setString(0, _channelName); - stmt->setUInt32(1, _channelTeam); - CharacterDatabase.Execute(stmt); - TC_LOG_DEBUG("chat.system", "Channel (%s) saved in database", _channelName.c_str()); - } - - _persistentChannel = true; + // legacy db content might not have 0x prefix, account for that + std::string bannedGuidStr(memcmp(token, "0x", 2) ? token + 2 : token); + ObjectGuid banned; + banned.SetRawValue(uint64(strtoull(bannedGuidStr.substr(0, 16).c_str(), nullptr, 16)), uint64(strtoull(bannedGuidStr.substr(16).c_str(), nullptr, 16))); + if (!banned) + continue; + + TC_LOG_DEBUG("chat.system", "Channel(%s) loaded player %s into bannedStore", name.c_str(), banned.ToString().c_str()); + _bannedStore.insert(banned); } } diff --git a/src/server/game/Chat/Channels/Channel.h b/src/server/game/Chat/Channels/Channel.h index 616da00ed36..30802964a9d 100644 --- a/src/server/game/Chat/Channels/Channel.h +++ b/src/server/game/Chat/Channels/Channel.h @@ -172,7 +172,7 @@ class TC_GAME_API Channel public: Channel(ObjectGuid const& guid, uint32 channelId, uint32 team = 0, AreaTableEntry const* zoneEntry = nullptr); // built-in channel ctor - Channel(ObjectGuid const& guid, std::string const& name, uint32 team = 0); // custom player channel ctor + Channel(ObjectGuid const& guid, std::string const& name, uint32 team = 0, std::string const& banList = ""); // custom player channel ctor static void GetChannelName(std::string& channelName, uint32 channelId, LocaleConstant locale, AreaTableEntry const* zoneEntry); std::string GetName(LocaleConstant locale = DEFAULT_LOCALE) const; diff --git a/src/server/game/Chat/Channels/ChannelMgr.cpp b/src/server/game/Chat/Channels/ChannelMgr.cpp index 3f68a1cd964..41e47d5a470 100644 --- a/src/server/game/Chat/Channels/ChannelMgr.cpp +++ b/src/server/game/Chat/Channels/ChannelMgr.cpp @@ -107,11 +107,21 @@ Channel* ChannelMgr::CreateCustomChannel(std::string const& name) return nullptr; Channel* newChannel = new Channel(CreateCustomChannelGuid(), name, _team); + + if (sWorld->getBoolConfig(CONFIG_PRESERVE_CUSTOM_CHANNELS)) + { + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHANNEL); + stmt->setString(0, name); + stmt->setUInt32(1, _team); + CharacterDatabase.Execute(stmt); + TC_LOG_DEBUG("chat.system", "Channel(%s) saved in database", name.c_str()); + } + c = newChannel; return newChannel; } -Channel* ChannelMgr::GetCustomChannel(std::string const& name) const +Channel* ChannelMgr::GetCustomChannel(std::string const& name) { std::wstring channelName; if (!Utf8toWStr(name, channelName)) @@ -121,8 +131,30 @@ Channel* ChannelMgr::GetCustomChannel(std::string const& name) const auto itr = _customChannels.find(channelName); if (itr != _customChannels.end()) return itr->second; - else - return nullptr; + else if (sWorld->getBoolConfig(CONFIG_PRESERVE_CUSTOM_CHANNELS)) + { + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHANNEL); + stmt->setString(0, name); + stmt->setUInt32(1, _team); + if (PreparedQueryResult result = CharacterDatabase.Query(stmt)) + { + Field* fields = result->Fetch(); + std::string dbName = fields[0].GetString(); // may be different - channel names are case insensitive + bool dbAnnounce = fields[1].GetBool(); + bool dbOwnership = fields[2].GetBool(); + std::string dbPass = fields[3].GetString(); + std::string dbBanned = fields[4].GetString(); + + Channel* channel = new Channel(CreateCustomChannelGuid(), dbName, _team, dbBanned); + channel->SetAnnounce(dbAnnounce); + channel->SetOwnership(dbOwnership); + channel->SetPassword(dbPass); + _customChannels.emplace(channelName, channel); + return channel; + } + } + + 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 e523dd1c04e..ed2f986c940 100644 --- a/src/server/game/Chat/Channels/ChannelMgr.h +++ b/src/server/game/Chat/Channels/ChannelMgr.h @@ -42,7 +42,7 @@ class TC_GAME_API ChannelMgr Channel* GetSystemChannel(uint32 channelId, AreaTableEntry const* zoneEntry = nullptr); Channel* CreateCustomChannel(std::string const& name); - Channel* GetCustomChannel(std::string const& name) const; + Channel* GetCustomChannel(std::string const& name); 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); |