Skip to content

Commit

Permalink
refactor(Core/ObjectMgr): Handle Profanity & Reserved Names in load (a…
Browse files Browse the repository at this point in the history
…zerothcore#19259)

* refactor(Core/ObjectMgr): Handle Profanity & Reserved Names in load

* closes azerothcore#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
  • Loading branch information
Kitzunu authored Jul 2, 2024
1 parent f96d4c8 commit 0a8175e
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 166 deletions.
2 changes: 1 addition & 1 deletion src/server/game/Battlegrounds/ArenaTeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/server/game/Entities/Player/PlayerStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
197 changes: 78 additions & 119 deletions src/server/game/Globals/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -8141,7 +8085,7 @@ void ObjectMgr::LoadCreatureQuestEnders()
}
}

void ObjectMgr::LoadReservedPlayersNames()
void ObjectMgr::LoadReservedPlayerNamesDB()
{
uint32 oldMSTime = getMSTime();

Expand All @@ -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;
}

Expand All @@ -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", " ");
}

Expand Down Expand Up @@ -8216,7 +8188,7 @@ void ObjectMgr::AddReservedPlayerName(std::string const& name)
}
}

void ObjectMgr::LoadProfanityPlayersNames()
void ObjectMgr::LoadProfanityNamesFromDB()
{
uint32 oldMSTime = getMSTime();

Expand All @@ -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;
}

Expand All @@ -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", " ");
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/server/game/Globals/ObjectMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1334,12 +1332,14 @@ class ObjectMgr
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);

Expand Down Expand Up @@ -1508,7 +1508,7 @@ class ObjectMgr

//character profanity names
typedef std::set<std::wstring> ProfanityNamesContainer;
ReservedNamesContainer _profanityNamesStore;
ProfanityNamesContainer _profanityNamesStore;

GameTeleContainer _gameTeleStore;

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Guilds/Guild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 0 additions & 12 deletions src/server/game/Handlers/PetHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/server/game/Handlers/PetitionsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 0a8175e

Please sign in to comment.