diff options
author | Kitzunu <24550914+Kitzunu@users.noreply.github.com> | 2024-07-03 00:23:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-03 00:23:32 +0200 |
commit | 0a8175ef037732aa25a908687a2c3a019ba5eb55 (patch) | |
tree | 741fa31f2d6a43ee068b24d0f0cf72faf3fe6481 /src/server/game/Globals/ObjectMgr.cpp | |
parent | f96d4c86706ac1befca0719d1cc99f8f82863ac0 (diff) |
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
Diffstat (limited to 'src/server/game/Globals/ObjectMgr.cpp')
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 197 |
1 files changed, 78 insertions, 119 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 1cd00cfde3..cd00e46b3e 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -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; } |