mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-28 06:25:55 +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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user