mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Chat: Properly reload saved channel settings from DB after 8c16f31.
This commit is contained in:
@@ -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();
|
||||
ObjectGuid banned(uint64(atoull(token)));
|
||||
if (!banned)
|
||||
continue;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
_persistentChannel = true;
|
||||
TC_LOG_DEBUG("chat.system", "Channel(%s) loaded player %s into bannedStore", name.c_str(), banned.ToString().c_str());
|
||||
_bannedStore.insert(banned);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user