diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Chat/Channels/Channel.cpp | 48 | ||||
-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, 46 insertions, 44 deletions
diff --git a/src/server/game/Chat/Channels/Channel.cpp b/src/server/game/Chat/Channels/Channel.cpp index 37bb0ad6732..d9fa3fc054b 100644 --- a/src/server/game/Chat/Channels/Channel.cpp +++ b/src/server/game/Chat/Channels/Channel.cpp @@ -58,10 +58,10 @@ Channel::Channel(uint32 channelId, uint32 team /*= 0*/, AreaTableEntry const* zo _channelFlags |= CHANNEL_FLAG_NOT_LFG; } -Channel::Channel(std::string const& name, uint32 team /*= 0*/) : +Channel::Channel(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), @@ -71,45 +71,15 @@ Channel::Channel(std::string const& name, uint32 team /*= 0*/) : _channelPassword(), _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) { - PreparedStatement *stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHANNEL); - stmt->setString(0, name); - 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 db_BannedList = fields[4].GetString(); - - if (!db_BannedList.empty()) - { - Tokenizer tokens(db_BannedList, ' '); - for (auto const& token : tokens) - { - ObjectGuid banned_guid(uint64(atoull(token))); - if (banned_guid) - { - TC_LOG_DEBUG("chat.system", "Channel(%s) loaded player %s into bannedStore", name.c_str(), banned_guid.ToString().c_str()); - _bannedStore.insert(banned_guid); - } - } - } - } - else // save - { - stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHANNEL); - stmt->setString(0, name); - stmt->setUInt32(1, _channelTeam); - CharacterDatabase.Execute(stmt); - TC_LOG_DEBUG("chat.system", "Channel(%s) saved in database", name.c_str()); - } + ObjectGuid banned(uint64(atoull(token))); + if (!banned) + continue; - _persistentChannel = true; + 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 1f9f7fb402c..534b595ae21 100644 --- a/src/server/game/Chat/Channels/Channel.h +++ b/src/server/game/Chat/Channels/Channel.h @@ -152,7 +152,7 @@ class TC_GAME_API Channel public: Channel(uint32 channelId, uint32 team = 0, AreaTableEntry const* zoneEntry = nullptr); // built-in channel ctor - Channel(std::string const& name, uint32 team = 0); // custom player channel ctor + Channel(std::string const& name, uint32 team, 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 95de940d824..9eac248ff7b 100644 --- a/src/server/game/Chat/Channels/ChannelMgr.cpp +++ b/src/server/game/Chat/Channels/ChannelMgr.cpp @@ -103,11 +103,21 @@ Channel* ChannelMgr::CreateCustomChannel(std::string const& name) return nullptr; Channel* newChannel = new Channel(name, _team); + + if (sWorld->getBoolConfig(CONFIG_PRESERVE_CUSTOM_CHANNELS)) + { + PreparedStatement* 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)) @@ -117,8 +127,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)) + { + PreparedStatement* 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(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 pkt /*= 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 0c55d605c02..d34e34ae47b 100644 --- a/src/server/game/Chat/Channels/ChannelMgr.h +++ b/src/server/game/Chat/Channels/ChannelMgr.h @@ -43,7 +43,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 pkt = true, AreaTableEntry const* zoneEntry = nullptr) const; void LeftChannel(std::string const& name); void LeftChannel(uint32 channelId, AreaTableEntry const* zoneEntry); |