mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 13:16:23 +00:00
refactor(Core/ObjectMgr): Handle Profanity & Reserved Names in load (#19259)
* refactor(Core/ObjectMgr): Handle Profanity & Reserved Names in load * closes https://github.com/azerothcore/azerothcore-wotlk/issues/18556 * Update ObjectMgr.cpp * Update ObjectMgr.cpp * I swear I am not drunk * We already check all of these * fix build * Forgot we dont send the responsecode in senderrormessage * last commit I swear
This commit is contained in:
@@ -281,7 +281,7 @@ bool ArenaTeam::LoadMembersFromDB(QueryResult result)
|
||||
|
||||
bool ArenaTeam::SetName(std::string const& name)
|
||||
{
|
||||
if (TeamName == name || name.empty() || name.length() > 24 || sObjectMgr->IsReservedName(name) || sObjectMgr->IsProfanityName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
if (TeamName == name || name.empty() || name.length() > 24 || !ObjectMgr::IsValidCharterName(name))
|
||||
return false;
|
||||
|
||||
TeamName = name;
|
||||
|
||||
@@ -4980,8 +4980,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
m_name = fields[2].Get<std::string>();
|
||||
|
||||
// check name limitations
|
||||
if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS ||
|
||||
(AccountMgr::IsPlayerAccount(GetSession()->GetSecurity()) && (sObjectMgr->IsReservedName(m_name) || sObjectMgr->IsProfanityName(m_name))))
|
||||
if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS || AccountMgr::IsPlayerAccount(GetSession()->GetSecurity()))
|
||||
{
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
|
||||
stmt->SetData(0, uint16(AT_LOGIN_RENAME));
|
||||
|
||||
@@ -203,62 +203,6 @@ std::string ScriptInfo::GetDebugInfo() const
|
||||
return std::string(sz);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name ReservedNames
|
||||
* @brief Checks NamesReserved.dbc for reserved names
|
||||
*
|
||||
* @param name Name to check for match in NamesReserved.dbc
|
||||
* @return true/false
|
||||
*/
|
||||
bool ReservedNames(std::wstring& name)
|
||||
{
|
||||
for (NamesReservedEntry const* reservedStore : sNamesReservedStore)
|
||||
{
|
||||
std::wstring PatternString;
|
||||
|
||||
Utf8toWStr(reservedStore->Pattern, PatternString);
|
||||
|
||||
boost::algorithm::replace_all(PatternString, "\\<", "");
|
||||
boost::algorithm::replace_all(PatternString, "\\>", "");
|
||||
|
||||
int stringCompare = name.compare(PatternString);
|
||||
if (stringCompare == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @name ProfanityNames
|
||||
* @brief Checks NamesProfanity.dbc for reserved names
|
||||
*
|
||||
* @param name Name to check for match in NamesProfanity.dbc
|
||||
* @return true/false
|
||||
*/
|
||||
bool ProfanityNames(std::wstring& name)
|
||||
{
|
||||
for (NamesProfanityEntry const* profanityStore : sNamesProfanityStore)
|
||||
{
|
||||
std::wstring PatternString;
|
||||
|
||||
Utf8toWStr(profanityStore->Pattern, PatternString);
|
||||
|
||||
boost::algorithm::replace_all(PatternString, "\\<", "");
|
||||
boost::algorithm::replace_all(PatternString, "\\>", "");
|
||||
|
||||
int stringCompare = name.compare(PatternString);
|
||||
if (stringCompare == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool normalizePlayerName(std::string& name)
|
||||
{
|
||||
if (name.empty())
|
||||
@@ -8141,7 +8085,7 @@ void ObjectMgr::LoadCreatureQuestEnders()
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadReservedPlayersNames()
|
||||
void ObjectMgr::LoadReservedPlayerNamesDB()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
@@ -8151,8 +8095,7 @@ void ObjectMgr::LoadReservedPlayersNames()
|
||||
|
||||
if (!result)
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 reserved player names. DB table `reserved_name` is empty!");
|
||||
LOG_INFO("server.loading", " ");
|
||||
LOG_WARN("server.loading", ">> Loaded 0 reserved names. DB table `reserved_name` is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8177,7 +8120,36 @@ void ObjectMgr::LoadReservedPlayersNames()
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} reserved player names in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", ">> Loaded {} reserved names from DB in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadReservedPlayerNamesDBC()
|
||||
{
|
||||
if (!sWorld->getBoolConfig(CONFIG_STRICT_NAMES_RESERVED))
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 reserved names from DBC. Config option disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
for (NamesReservedEntry const* reservedStore : sNamesReservedStore)
|
||||
{
|
||||
std::wstring wstr;
|
||||
|
||||
Utf8toWStr(reservedStore->Pattern, wstr);
|
||||
|
||||
// DBC does not have clean entries, remove the junk.
|
||||
boost::algorithm::replace_all(wstr, "\\<", "");
|
||||
boost::algorithm::replace_all(wstr, "\\>", "");
|
||||
|
||||
_reservedNamesStore.insert(wstr);
|
||||
count++;
|
||||
}
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} reserved names from DBC in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", " ");
|
||||
}
|
||||
|
||||
@@ -8216,7 +8188,7 @@ void ObjectMgr::AddReservedPlayerName(std::string const& name)
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadProfanityPlayersNames()
|
||||
void ObjectMgr::LoadProfanityNamesFromDB()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
@@ -8226,8 +8198,7 @@ void ObjectMgr::LoadProfanityPlayersNames()
|
||||
|
||||
if (!result)
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 profanity player names. DB table `profanity_name` is empty!");
|
||||
LOG_INFO("server.loading", " ");
|
||||
LOG_WARN("server.loading", ">> Loaded 0 profanity names. DB table `profanity_name` is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8252,7 +8223,36 @@ void ObjectMgr::LoadProfanityPlayersNames()
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} profanity player names in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", ">> Loaded {} profanity names from DB in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadProfanityNamesFromDBC()
|
||||
{
|
||||
if (!sWorld->getBoolConfig(CONFIG_STRICT_NAMES_PROFANITY))
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 profanity names from DBC. Config option disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
for (NamesProfanityEntry const* profanityStore : sNamesProfanityStore)
|
||||
{
|
||||
std::wstring wstr;
|
||||
|
||||
Utf8toWStr(profanityStore->Pattern, wstr);
|
||||
|
||||
// DBC does not have clean entries, remove the junk.
|
||||
boost::algorithm::replace_all(wstr, "\\<", "");
|
||||
boost::algorithm::replace_all(wstr, "\\>", "");
|
||||
|
||||
_profanityNamesStore.insert(wstr);
|
||||
count++;
|
||||
}
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} profanity names from DBC in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", " ");
|
||||
}
|
||||
|
||||
@@ -8392,34 +8392,13 @@ uint8 ObjectMgr::CheckPlayerName(std::string_view name, bool create)
|
||||
if (wname[i] == wname[i - 1] && wname[i] == wname[i - 2])
|
||||
return CHAR_NAME_THREE_CONSECUTIVE;
|
||||
|
||||
// Check Reserved Name from Database
|
||||
// Check Reserved Name
|
||||
if (sObjectMgr->IsReservedName(name))
|
||||
{
|
||||
return CHAR_NAME_RESERVED;
|
||||
}
|
||||
|
||||
// Check Profanity Name
|
||||
if (sObjectMgr->IsProfanityName(name))
|
||||
{
|
||||
return CHAR_NAME_PROFANE;
|
||||
}
|
||||
|
||||
// Check for Reserved Name from DBC
|
||||
if (sWorld->getBoolConfig(CONFIG_STRICT_NAMES_RESERVED))
|
||||
{
|
||||
if (ReservedNames(wname))
|
||||
{
|
||||
return CHAR_NAME_RESERVED;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for Profanity
|
||||
if (sWorld->getBoolConfig(CONFIG_STRICT_NAMES_PROFANITY))
|
||||
{
|
||||
if (ProfanityNames(wname))
|
||||
{
|
||||
return CHAR_NAME_PROFANE;
|
||||
}
|
||||
}
|
||||
|
||||
return CHAR_NAME_SUCCESS;
|
||||
}
|
||||
@@ -8437,23 +8416,13 @@ bool ObjectMgr::IsValidCharterName(std::string_view name)
|
||||
if (wname.size() < minName)
|
||||
return false;
|
||||
|
||||
// Check for Reserved Name from DBC
|
||||
if (sWorld->getBoolConfig(CONFIG_STRICT_NAMES_RESERVED))
|
||||
{
|
||||
if (ReservedNames(wname))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Check Reserved Name
|
||||
if (sObjectMgr->IsReservedName(name))
|
||||
return false;
|
||||
|
||||
// Check for Profanity
|
||||
if (sWorld->getBoolConfig(CONFIG_STRICT_NAMES_PROFANITY))
|
||||
{
|
||||
if (ProfanityNames(wname))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Check Profanity Name
|
||||
if (sObjectMgr->IsProfanityName(name))
|
||||
return false;
|
||||
|
||||
uint32 strictMask = sWorld->getIntConfig(CONFIG_STRICT_CHARTER_NAMES);
|
||||
|
||||
@@ -8491,23 +8460,13 @@ PetNameInvalidReason ObjectMgr::CheckPetName(std::string_view name)
|
||||
if (!isValidString(wname, strictMask, false))
|
||||
return PET_NAME_MIXED_LANGUAGES;
|
||||
|
||||
// Check for Reserved Name from DBC
|
||||
if (sWorld->getBoolConfig(CONFIG_STRICT_NAMES_RESERVED))
|
||||
{
|
||||
if (ReservedNames(wname))
|
||||
{
|
||||
return PET_NAME_RESERVED;
|
||||
}
|
||||
}
|
||||
// Check Reserved Name
|
||||
if (sObjectMgr->IsReservedName(name))
|
||||
return PET_NAME_RESERVED;
|
||||
|
||||
// Check for Profanity
|
||||
if (sWorld->getBoolConfig(CONFIG_STRICT_NAMES_PROFANITY))
|
||||
{
|
||||
if (ProfanityNames(wname))
|
||||
{
|
||||
return PET_NAME_PROFANE;
|
||||
}
|
||||
}
|
||||
// Check Profanity Name
|
||||
if (sObjectMgr->IsProfanityName(name))
|
||||
return PET_NAME_PROFANE;
|
||||
|
||||
return PET_NAME_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -691,8 +691,6 @@ SkillRangeType GetSkillRangeType(SkillRaceClassInfoEntry const* rcEntry);
|
||||
#define MAX_CHARTER_NAME 24 // max allowed by client name length
|
||||
#define MAX_CHANNEL_NAME 50 // pussywizard
|
||||
|
||||
bool ReservedNames(std::wstring& name);
|
||||
bool ProfanityNames(std::wstring& name);
|
||||
bool normalizePlayerName(std::string& name);
|
||||
|
||||
struct LanguageDesc
|
||||
@@ -1334,12 +1332,14 @@ public:
|
||||
uint32 AddCreData(uint32 entry, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay = 0);
|
||||
|
||||
// reserved names
|
||||
void LoadReservedPlayersNames();
|
||||
void LoadReservedPlayerNamesDB();
|
||||
void LoadReservedPlayerNamesDBC();
|
||||
[[nodiscard]] bool IsReservedName(std::string_view name) const;
|
||||
void AddReservedPlayerName(std::string const& name);
|
||||
|
||||
// profanity names
|
||||
void LoadProfanityPlayersNames();
|
||||
void LoadProfanityNamesFromDB();
|
||||
void LoadProfanityNamesFromDBC();
|
||||
[[nodiscard]] bool IsProfanityName(std::string_view name) const;
|
||||
void AddProfanityPlayerName(std::string const& name);
|
||||
|
||||
@@ -1508,7 +1508,7 @@ private:
|
||||
|
||||
//character profanity names
|
||||
typedef std::set<std::wstring> ProfanityNamesContainer;
|
||||
ReservedNamesContainer _profanityNamesStore;
|
||||
ProfanityNamesContainer _profanityNamesStore;
|
||||
|
||||
GameTeleContainer _gameTeleStore;
|
||||
|
||||
|
||||
@@ -1187,7 +1187,7 @@ void Guild::OnPlayerStatusChange(Player* player, uint32 flag, bool state)
|
||||
|
||||
bool Guild::SetName(std::string_view const& name)
|
||||
{
|
||||
if (m_name == name || name.empty() || name.length() > 24 || sObjectMgr->IsReservedName(name) || sObjectMgr->IsProfanityName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
if (m_name == name || name.empty() || name.length() > 24 || !ObjectMgr::IsValidCharterName(name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -856,18 +856,6 @@ void WorldSession::HandlePetRename(WorldPacket& recvData)
|
||||
return;
|
||||
}
|
||||
|
||||
if (sObjectMgr->IsReservedName(name))
|
||||
{
|
||||
SendPetNameInvalid(PET_NAME_RESERVED, name, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sObjectMgr->IsProfanityName(name))
|
||||
{
|
||||
SendPetNameInvalid(PET_NAME_PROFANE, name, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
pet->SetName(name);
|
||||
|
||||
Unit* owner = pet->GetOwner();
|
||||
|
||||
@@ -136,7 +136,7 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket& recvData)
|
||||
return;
|
||||
}
|
||||
|
||||
if (sObjectMgr->IsReservedName(name) || sObjectMgr->IsProfanityName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
if (!ObjectMgr::IsValidCharterName(name))
|
||||
{
|
||||
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, name);
|
||||
return;
|
||||
@@ -149,7 +149,7 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket& recvData)
|
||||
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
|
||||
return;
|
||||
}
|
||||
if (sObjectMgr->IsReservedName(name) || sObjectMgr->IsProfanityName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
if (!ObjectMgr::IsValidCharterName(name))
|
||||
{
|
||||
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_INVALID);
|
||||
return;
|
||||
@@ -350,7 +350,7 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket& recvData)
|
||||
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, newName);
|
||||
return;
|
||||
}
|
||||
if (sObjectMgr->IsReservedName(newName) || sObjectMgr->IsProfanityName(newName) || !ObjectMgr::IsValidCharterName(newName))
|
||||
if (!ObjectMgr::IsValidCharterName(newName))
|
||||
{
|
||||
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, newName);
|
||||
return;
|
||||
@@ -363,7 +363,7 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket& recvData)
|
||||
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
|
||||
return;
|
||||
}
|
||||
if (sObjectMgr->IsReservedName(newName) || sObjectMgr->IsProfanityName(newName) || !ObjectMgr::IsValidCharterName(newName))
|
||||
if (!ObjectMgr::IsValidCharterName(newName))
|
||||
{
|
||||
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_INVALID);
|
||||
return;
|
||||
|
||||
@@ -1916,10 +1916,12 @@ void World::SetInitialWorldSettings()
|
||||
sGroupMgr->LoadGroups();
|
||||
|
||||
LOG_INFO("server.loading", "Loading Reserved Names...");
|
||||
sObjectMgr->LoadReservedPlayersNames();
|
||||
sObjectMgr->LoadReservedPlayerNamesDB();
|
||||
sObjectMgr->LoadReservedPlayerNamesDBC(); // Needs to be after LoadReservedPlayerNamesDB()
|
||||
|
||||
LOG_INFO("server.loading", "Loading Profanity Names...");
|
||||
sObjectMgr->LoadProfanityPlayersNames();
|
||||
sObjectMgr->LoadProfanityNamesFromDB();
|
||||
sObjectMgr->LoadProfanityNamesFromDBC(); // Needs to be after LoadProfanityNamesFromDB()
|
||||
|
||||
LOG_INFO("server.loading", "Loading GameObjects for Quests...");
|
||||
sObjectMgr->LoadGameObjectForQuests();
|
||||
|
||||
@@ -347,21 +347,22 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ObjectMgr::CheckPlayerName(newName, true) != CHAR_NAME_SUCCESS)
|
||||
ResponseCodes res = ResponseCodes(ObjectMgr::CheckPlayerName(newName, true));
|
||||
if (res != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
handler->SendErrorMessage(LANG_BAD_VALUE);
|
||||
return false;
|
||||
}
|
||||
switch (res)
|
||||
{
|
||||
case CHAR_NAME_RESERVED:
|
||||
handler->SendErrorMessage(LANG_RESERVED_NAME);
|
||||
break;
|
||||
case CHAR_NAME_PROFANE:
|
||||
handler->SendErrorMessage(LANG_PROFANITY_NAME);
|
||||
break;
|
||||
default:
|
||||
handler->SendErrorMessage(LANG_BAD_VALUE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sObjectMgr->IsReservedName(newName))
|
||||
{
|
||||
handler->SendErrorMessage(LANG_RESERVED_NAME);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sObjectMgr->IsProfanityName(newName))
|
||||
{
|
||||
handler->SendErrorMessage(LANG_PROFANITY_NAME);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sObjectMgr->IsReservedName(guildName) || sObjectMgr->IsProfanityName(guildName) || !sObjectMgr->IsValidCharterName(guildName))
|
||||
if (!sObjectMgr->IsValidCharterName(guildName))
|
||||
{
|
||||
handler->SendErrorMessage(LANG_BAD_VALUE);
|
||||
return false;
|
||||
|
||||
@@ -780,17 +780,19 @@ public:
|
||||
|
||||
static bool HandleReloadReservedNameCommand(ChatHandler* handler)
|
||||
{
|
||||
LOG_INFO("server.loading", "Re-Loading `reserved_player` Table!");
|
||||
sObjectMgr->LoadReservedPlayersNames();
|
||||
handler->SendGlobalGMSysMessage("DB table `reserved_name` reloaded.");
|
||||
LOG_INFO("server.loading", "Re-Loading Reserved Names!");
|
||||
sObjectMgr->LoadReservedPlayerNamesDB();
|
||||
sObjectMgr->LoadReservedPlayerNamesDBC(); // Needed because we clear the store in LoadReservedPlayerNamesDB()
|
||||
handler->SendGlobalGMSysMessage("Reserved Names reloaded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleReloadProfanityNameCommand(ChatHandler* handler)
|
||||
{
|
||||
LOG_INFO("server.loading", "Re-Loading `profanity_player` Table!");
|
||||
sObjectMgr->LoadProfanityPlayersNames();
|
||||
handler->SendGlobalGMSysMessage("DB table `profanity_player` reloaded.");
|
||||
LOG_INFO("server.loading", "Re-Loading Profanity Names!");
|
||||
sObjectMgr->LoadProfanityNamesFromDB();
|
||||
sObjectMgr->LoadProfanityNamesFromDBC(); // Needed because we clear the store in LoadProfanityNamesFromDB()
|
||||
handler->SendGlobalGMSysMessage("Profanity Names reloaded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user