Core/Chat: Properly reload saved channel settings from DB after 8c16f31.

(cherry picked from commit 2c1b87ca29)
This commit is contained in:
Treeston
2019-07-16 13:17:45 +02:00
committed by Shauren
parent 9fa5c71409
commit bd7aae928e
4 changed files with 49 additions and 47 deletions

View File

@@ -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();
// 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;
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;
TC_LOG_DEBUG("chat.system", "Channel(%s) loaded player %s into bannedStore", name.c_str(), banned.ToString().c_str());
_bannedStore.insert(banned);
}
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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);