mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-28 16:16:27 +00:00
feat(Core/Character): Implement profanity_name (#15156)
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) || !ObjectMgr::IsValidCharterName(name))
|
||||
if (TeamName == name || name.empty() || name.length() > 24 || sObjectMgr->IsReservedName(name) || sObjectMgr->IsProfanityName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
return false;
|
||||
|
||||
TeamName = name;
|
||||
|
||||
@@ -4990,7 +4990,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
|
||||
// check name limitations
|
||||
if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS ||
|
||||
(AccountMgr::IsPlayerAccount(GetSession()->GetSecurity()) && sObjectMgr->IsReservedName(m_name)))
|
||||
(AccountMgr::IsPlayerAccount(GetSession()->GetSecurity()) && (sObjectMgr->IsReservedName(m_name) || sObjectMgr->IsProfanityName(m_name))))
|
||||
{
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
|
||||
stmt->SetData(0, uint16(AT_LOGIN_RENAME));
|
||||
|
||||
@@ -8204,6 +8204,81 @@ void ObjectMgr::AddReservedPlayerName(std::string const& name)
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadProfanityPlayersNames()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
_profanityNamesStore.clear(); // need for reload case
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT name FROM profanity_name");
|
||||
|
||||
if (!result)
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 profanity player names. DB table `profanity_name` is empty!");
|
||||
LOG_INFO("server.loading", " ");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
Field* fields;
|
||||
do
|
||||
{
|
||||
fields = result->Fetch();
|
||||
std::string name = fields[0].Get<std::string>();
|
||||
|
||||
std::wstring wstr;
|
||||
if (!Utf8toWStr (name, wstr))
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `profanity_name` have invalid name: {}", name);
|
||||
continue;
|
||||
}
|
||||
|
||||
wstrToLower(wstr);
|
||||
|
||||
_profanityNamesStore.insert(wstr);
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} profanity player names in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", " ");
|
||||
}
|
||||
|
||||
bool ObjectMgr::IsProfanityName(std::string_view name) const
|
||||
{
|
||||
// pussywizard
|
||||
if (name.size() >= 2 && (name[name.size() - 2] == 'G' || name[name.size() - 2] == 'g') && (name[name.size() - 1] == 'M' || name[name.size() - 1] == 'm'))
|
||||
return true;
|
||||
|
||||
std::wstring wstr;
|
||||
if (!Utf8toWStr (name, wstr))
|
||||
return false;
|
||||
|
||||
wstrToLower(wstr);
|
||||
|
||||
return _profanityNamesStore.find(wstr) != _profanityNamesStore.end();
|
||||
}
|
||||
|
||||
void ObjectMgr::AddProfanityPlayerName(std::string const& name)
|
||||
{
|
||||
if (!IsProfanityName(name))
|
||||
{
|
||||
std::wstring wstr;
|
||||
if (!Utf8toWStr(name, wstr))
|
||||
{
|
||||
LOG_ERROR("server", "Could not add invalid name to profanity player names: {}", name);
|
||||
return;
|
||||
}
|
||||
wstrToLower(wstr);
|
||||
|
||||
_profanityNamesStore.insert(wstr);
|
||||
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PROFANITY_PLAYER_NAME);
|
||||
stmt->SetData(0, name);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
enum LanguageType
|
||||
{
|
||||
LT_BASIC_LATIN = 0x0000,
|
||||
@@ -8311,6 +8386,11 @@ uint8 ObjectMgr::CheckPlayerName(std::string_view name, bool create)
|
||||
return CHAR_NAME_RESERVED;
|
||||
}
|
||||
|
||||
if (sObjectMgr->IsProfanityName(name))
|
||||
{
|
||||
return CHAR_NAME_PROFANE;
|
||||
}
|
||||
|
||||
// Check for Reserved Name from DBC
|
||||
if (sWorld->getBoolConfig(CONFIG_STRICT_NAMES_RESERVED))
|
||||
{
|
||||
|
||||
@@ -1337,6 +1337,11 @@ public:
|
||||
[[nodiscard]] bool IsReservedName(std::string_view name) const;
|
||||
void AddReservedPlayerName(std::string const& name);
|
||||
|
||||
// profanity names
|
||||
void LoadProfanityPlayersNames();
|
||||
[[nodiscard]] bool IsProfanityName(std::string_view name) const;
|
||||
void AddProfanityPlayerName(std::string const& name);
|
||||
|
||||
// name with valid structure and symbols
|
||||
static uint8 CheckPlayerName(std::string_view name, bool create = false);
|
||||
static PetNameInvalidReason CheckPetName(std::string_view name);
|
||||
@@ -1506,6 +1511,10 @@ private:
|
||||
typedef std::set<std::wstring> ReservedNamesContainer;
|
||||
ReservedNamesContainer _reservedNamesStore;
|
||||
|
||||
//character profanity names
|
||||
typedef std::set<std::wstring> ProfanityNamesContainer;
|
||||
ReservedNamesContainer _profanityNamesStore;
|
||||
|
||||
GameTeleContainer _gameTeleStore;
|
||||
|
||||
ScriptNameContainer _scriptNamesStore;
|
||||
|
||||
@@ -1184,7 +1184,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) || !ObjectMgr::IsValidCharterName(name))
|
||||
if (m_name == name || name.empty() || name.length() > 24 || sObjectMgr->IsReservedName(name) || sObjectMgr->IsProfanityName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -861,6 +861,12 @@ void WorldSession::HandlePetRename(WorldPacket& recvData)
|
||||
return;
|
||||
}
|
||||
|
||||
if (sObjectMgr->IsProfanityName(name))
|
||||
{
|
||||
SendPetNameInvalid(PET_NAME_PROFANE, name, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
pet->SetName(name);
|
||||
|
||||
Unit* owner = pet->GetOwner();
|
||||
|
||||
@@ -137,7 +137,7 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket& recvData)
|
||||
return;
|
||||
}
|
||||
|
||||
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
if (sObjectMgr->IsReservedName(name) || sObjectMgr->IsProfanityName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
{
|
||||
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, name);
|
||||
return;
|
||||
@@ -150,7 +150,7 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket& recvData)
|
||||
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
|
||||
return;
|
||||
}
|
||||
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
if (sObjectMgr->IsReservedName(name) || sObjectMgr->IsProfanityName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
{
|
||||
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_INVALID);
|
||||
return;
|
||||
@@ -351,7 +351,7 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket& recvData)
|
||||
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, newName);
|
||||
return;
|
||||
}
|
||||
if (sObjectMgr->IsReservedName(newName) || !ObjectMgr::IsValidCharterName(newName))
|
||||
if (sObjectMgr->IsReservedName(newName) || sObjectMgr->IsProfanityName(newName) || !ObjectMgr::IsValidCharterName(newName))
|
||||
{
|
||||
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, newName);
|
||||
return;
|
||||
@@ -364,7 +364,7 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket& recvData)
|
||||
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
|
||||
return;
|
||||
}
|
||||
if (sObjectMgr->IsReservedName(newName) || !ObjectMgr::IsValidCharterName(newName))
|
||||
if (sObjectMgr->IsReservedName(newName) || sObjectMgr->IsProfanityName(newName) || !ObjectMgr::IsValidCharterName(newName))
|
||||
{
|
||||
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_INVALID);
|
||||
return;
|
||||
|
||||
@@ -218,7 +218,7 @@ enum AcoreStrings
|
||||
LANG_GRID_POSITION = 178,
|
||||
// 179-185 used in other client versions
|
||||
LANG_TRANSPORT_POSITION = 186,
|
||||
// 187
|
||||
LANG_PROFANITY_NAME = 187,
|
||||
LANG_2FA_SECRET_TOO_LONG = 188,
|
||||
LANG_2FA_SECRET_INVALID = 189,
|
||||
LANG_2FA_SECRET_SET_COMPLETE = 190,
|
||||
|
||||
@@ -1911,9 +1911,12 @@ void World::SetInitialWorldSettings()
|
||||
LOG_INFO("server.loading", "Loading Groups...");
|
||||
sGroupMgr->LoadGroups();
|
||||
|
||||
LOG_INFO("server.loading", "Loading ReservedNames...");
|
||||
LOG_INFO("server.loading", "Loading Reserved Names...");
|
||||
sObjectMgr->LoadReservedPlayersNames();
|
||||
|
||||
LOG_INFO("server.loading", "Loading Profanity Names...");
|
||||
sObjectMgr->LoadProfanityPlayersNames();
|
||||
|
||||
LOG_INFO("server.loading", "Loading GameObjects for Quests...");
|
||||
sObjectMgr->LoadGameObjectForQuests();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user