Core/Players: Implemented serverside validation of reserved/profane names
Closes #15357 New library dependency: Boost.Regex (cherry picked from commit b564c10b13effed63c7b7dae25117e2e0a2c64e4)
This commit is contained in:
1 parent
60da7c6552
commit
1de03cf107
13 files changed
+103
-18
No files matched your search
@@ -29,7 +29,7 @@ if(WIN32)
|
||||
add_definitions(-D_WIN32_WINNT=${ver})
|
||||
endif()
|
||||
|
||||
find_package(Boost 1.49 REQUIRED system filesystem thread program_options iostreams)
|
||||
find_package(Boost 1.49 REQUIRED system filesystem thread program_options iostreams regex)
|
||||
add_definitions(-DBOOST_DATE_TIME_NO_LIB)
|
||||
add_definitions(-DBOOST_REGEX_NO_LIB)
|
||||
add_definitions(-DBOOST_CHRONO_NO_LIB)
|
||||
|
||||
+3
-2
@@ -116,10 +116,11 @@ enum LocaleConstant
|
||||
LOCALE_zhTW = 5,
|
||||
LOCALE_esES = 6,
|
||||
LOCALE_esMX = 7,
|
||||
LOCALE_ruRU = 8
|
||||
LOCALE_ruRU = 8,
|
||||
|
||||
TOTAL_LOCALES
|
||||
};
|
||||
|
||||
const uint8 TOTAL_LOCALES = 9;
|
||||
#define DEFAULT_LOCALE LOCALE_enUS
|
||||
|
||||
#define MAX_LOCALES 8
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "Timer.h"
|
||||
#include "ObjectDefines.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include <map>
|
||||
|
||||
typedef std::map<uint16, uint32> AreaFlagByAreaID;
|
||||
@@ -140,6 +141,12 @@ MapDifficultyMap sMapDifficultyMap;
|
||||
|
||||
DBCStorage <MovieEntry> sMovieStore(MovieEntryfmt);
|
||||
|
||||
DBCStorage<NamesProfanityEntry> sNamesProfanityStore(NamesProfanityEntryfmt);
|
||||
DBCStorage<NamesReservedEntry> sNamesReservedStore(NamesReservedEntryfmt);
|
||||
typedef std::array<std::vector<boost::regex>, TOTAL_LOCALES> NameValidationRegexContainer;
|
||||
NameValidationRegexContainer NamesProfaneValidators;
|
||||
NameValidationRegexContainer NamesReservedValidators;
|
||||
|
||||
DBCStorage <OverrideSpellDataEntry> sOverrideSpellDataStore(OverrideSpellDatafmt);
|
||||
|
||||
DBCStorage <PowerDisplayEntry> sPowerDisplayStore(PowerDisplayfmt);
|
||||
@@ -401,6 +408,37 @@ void LoadDBCStores(const std::string& dataPath)
|
||||
|
||||
LoadDBC(availableDbcLocales, bad_dbc_files, sMovieStore, dbcPath, "Movie.dbc");
|
||||
|
||||
LoadDBC(availableDbcLocales, bad_dbc_files, sNamesProfanityStore, dbcPath, "NamesProfanity.dbc");
|
||||
LoadDBC(availableDbcLocales, bad_dbc_files, sNamesReservedStore, dbcPath, "NamesReserved.dbc");
|
||||
for (uint32 i = 0; i < sNamesProfanityStore.GetNumRows(); ++i)
|
||||
{
|
||||
NamesProfanityEntry const* namesProfanity = sNamesProfanityStore.LookupEntry(i);
|
||||
if (!namesProfanity)
|
||||
continue;
|
||||
|
||||
ASSERT(namesProfanity->Language < TOTAL_LOCALES || namesProfanity->Language == -1);
|
||||
if (namesProfanity->Language != -1)
|
||||
NamesProfaneValidators[namesProfanity->Language].emplace_back(namesProfanity->Name, boost::regex::perl | boost::regex::icase | boost::regex::optimize);
|
||||
else
|
||||
for (uint32 i = 0; i < TOTAL_LOCALES; ++i)
|
||||
NamesProfaneValidators[i].emplace_back(namesProfanity->Name, boost::regex::perl | boost::regex::icase | boost::regex::optimize);
|
||||
}
|
||||
|
||||
for (uint32 i = 0; i < sNamesReservedStore.GetNumRows(); ++i)
|
||||
{
|
||||
NamesReservedEntry const* namesReserved = sNamesReservedStore.LookupEntry(i);
|
||||
if (!namesReserved)
|
||||
continue;
|
||||
|
||||
ASSERT(namesReserved->Language < TOTAL_LOCALES || namesReserved->Language == -1);
|
||||
if (namesReserved->Language != -1)
|
||||
NamesReservedValidators[namesReserved->Language].emplace_back(namesReserved->Name, boost::regex::perl | boost::regex::icase | boost::regex::optimize);
|
||||
else
|
||||
for (uint32 i = 0; i < TOTAL_LOCALES; ++i)
|
||||
NamesReservedValidators[i].emplace_back(namesReserved->Name, boost::regex::perl | boost::regex::icase | boost::regex::optimize);
|
||||
}
|
||||
|
||||
|
||||
LoadDBC(availableDbcLocales, bad_dbc_files, sOverrideSpellDataStore, dbcPath, "OverrideSpellData.dbc");
|
||||
|
||||
LoadDBC(availableDbcLocales, bad_dbc_files, sPowerDisplayStore, dbcPath, "PowerDisplay.dbc");
|
||||
@@ -1005,3 +1043,20 @@ SkillRaceClassInfoEntry const* GetSkillRaceClassInfo(uint32 skill, uint8 race, u
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ResponseCodes ValidateName(std::string const& name, LocaleConstant locale)
|
||||
{
|
||||
if (locale >= TOTAL_LOCALES)
|
||||
return RESPONSE_FAILURE;
|
||||
|
||||
for (boost::regex const& regex : NamesProfaneValidators[locale])
|
||||
if (boost::regex_search(name, regex))
|
||||
return CHAR_NAME_PROFANE;
|
||||
|
||||
// regexes at TOTAL_LOCALES are loaded from NamesReserved which is not locale specific
|
||||
for (boost::regex const& regex : NamesReservedValidators[locale])
|
||||
if (boost::regex_search(name, regex))
|
||||
return CHAR_NAME_RESERVED;
|
||||
|
||||
return CHAR_NAME_SUCCESS;
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "Common.h"
|
||||
#include "DBCStore.h"
|
||||
#include "DBCStructure.h"
|
||||
#include "SharedDefines.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
@@ -79,6 +80,8 @@ typedef std::unordered_multimap<uint32, SkillRaceClassInfoEntry const*> SkillRac
|
||||
typedef std::pair<SkillRaceClassInfoMap::iterator, SkillRaceClassInfoMap::iterator> SkillRaceClassInfoBounds;
|
||||
SkillRaceClassInfoEntry const* GetSkillRaceClassInfo(uint32 skill, uint8 race, uint8 class_);
|
||||
|
||||
ResponseCodes ValidateName(std::string const& name, LocaleConstant locale);
|
||||
|
||||
extern DBCStorage <AchievementEntry> sAchievementStore;
|
||||
extern DBCStorage <AchievementCriteriaEntry> sAchievementCriteriaStore;
|
||||
extern DBCStorage <AreaTableEntry> sAreaStore;// recommend access using functions
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "Common.h"
|
||||
#include "DBCEnums.h"
|
||||
#include "Define.h"
|
||||
#include "Util.h"
|
||||
|
||||
// Structures using to access raw DBC data and required packing to portability
|
||||
@@ -1405,6 +1404,20 @@ struct MovieEntry
|
||||
//uint32 unk2; // 2 always 100
|
||||
};
|
||||
|
||||
struct NamesProfanityEntry
|
||||
{
|
||||
//uint32 ID; // 0
|
||||
char const* Name; // 1
|
||||
int32 Language; // 2
|
||||
};
|
||||
|
||||
struct NamesReservedEntry
|
||||
{
|
||||
//uint32 ID; // 0
|
||||
char const* Name; // 1
|
||||
int32 Language; // 2
|
||||
};
|
||||
|
||||
#define MAX_OVERRIDE_SPELL 10
|
||||
|
||||
struct OverrideSpellDataEntry
|
||||
|
||||
@@ -88,6 +88,8 @@ char const MailTemplateEntryfmt[] = "nxxxxxxxxxxxxxxxxxssssssssssssssssx";
|
||||
char const MapEntryfmt[] = "nxiixssssssssssssssssxixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxixiffxiii";
|
||||
char const MapDifficultyEntryfmt[] = "diisxxxxxxxxxxxxxxxxiix";
|
||||
char const MovieEntryfmt[] = "nxx";
|
||||
char const NamesProfanityEntryfmt[] = "dsi";
|
||||
char const NamesReservedEntryfmt[] = "dsi";
|
||||
char const OverrideSpellDatafmt[] = "niiiiiiiiiix";
|
||||
char const QuestFactionRewardfmt[] = "niiiiiiiiii";
|
||||
char const QuestSortEntryfmt[] = "nxxxxxxxxxxxxxxxxx";
|
||||
|
||||
@@ -17117,7 +17117,7 @@ bool Player::LoadFromDB(ObjectGuid guid, SQLQueryHolder *holder)
|
||||
m_name = fields[2].GetString();
|
||||
|
||||
// check name limitations
|
||||
if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS ||
|
||||
if (ObjectMgr::CheckPlayerName(m_name, GetSession()->GetSessionDbcLocale()) != CHAR_NAME_SUCCESS ||
|
||||
(!GetSession()->HasPermission(rbac::RBAC_PERM_SKIP_CHECK_CHARACTER_CREATION_RESERVEDNAME) &&
|
||||
sObjectMgr->IsReservedName(m_name)))
|
||||
{
|
||||
|
||||
@@ -7562,7 +7562,7 @@ bool isValidString(const std::wstring& wstr, uint32 strictMask, bool numericOrSp
|
||||
return false;
|
||||
}
|
||||
|
||||
ResponseCodes ObjectMgr::CheckPlayerName(const std::string& name, bool create)
|
||||
ResponseCodes ObjectMgr::CheckPlayerName(std::string const& name, LocaleConstant locale, bool create /*= false*/)
|
||||
{
|
||||
std::wstring wname;
|
||||
if (!Utf8toWStr(name, wname))
|
||||
@@ -7584,7 +7584,7 @@ ResponseCodes ObjectMgr::CheckPlayerName(const std::string& name, bool create)
|
||||
if (wname[i] == wname[i-1] && wname[i] == wname[i-2])
|
||||
return CHAR_NAME_THREE_CONSECUTIVE;
|
||||
|
||||
return CHAR_NAME_SUCCESS;
|
||||
return ValidateName(name, locale);
|
||||
}
|
||||
|
||||
bool ObjectMgr::IsValidCharterName(const std::string& name)
|
||||
@@ -7605,7 +7605,7 @@ bool ObjectMgr::IsValidCharterName(const std::string& name)
|
||||
return isValidString(wname, strictMask, true);
|
||||
}
|
||||
|
||||
PetNameInvalidReason ObjectMgr::CheckPetName(const std::string& name)
|
||||
PetNameInvalidReason ObjectMgr::CheckPetName(const std::string& name, LocaleConstant locale)
|
||||
{
|
||||
std::wstring wname;
|
||||
if (!Utf8toWStr(name, wname))
|
||||
@@ -7622,6 +7622,17 @@ PetNameInvalidReason ObjectMgr::CheckPetName(const std::string& name)
|
||||
if (!isValidString(wname, strictMask, false))
|
||||
return PET_NAME_MIXED_LANGUAGES;
|
||||
|
||||
switch (ValidateName(name, locale))
|
||||
{
|
||||
case CHAR_NAME_PROFANE:
|
||||
return PET_NAME_PROFANE;
|
||||
case CHAR_NAME_RESERVED:
|
||||
return PET_NAME_RESERVED;
|
||||
case RESPONSE_FAILURE:
|
||||
return PET_NAME_INVALID;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return PET_NAME_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -1230,8 +1230,8 @@ class ObjectMgr
|
||||
bool IsReservedName(std::string const& name) const;
|
||||
|
||||
// name with valid structure and symbols
|
||||
static ResponseCodes CheckPlayerName(std::string const& name, bool create = false);
|
||||
static PetNameInvalidReason CheckPetName(std::string const& name);
|
||||
static ResponseCodes CheckPlayerName(std::string const& name, LocaleConstant locale, bool create = false);
|
||||
static PetNameInvalidReason CheckPetName(std::string const& name, LocaleConstant locale);
|
||||
static bool IsValidCharterName(std::string const& name);
|
||||
|
||||
static bool CheckDeclinedNames(const std::wstring& w_ownname, DeclinedName const& names);
|
||||
|
||||
@@ -363,7 +363,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket& recvData)
|
||||
}
|
||||
|
||||
// check name limitations
|
||||
ResponseCodes res = ObjectMgr::CheckPlayerName(createInfo.Name, true);
|
||||
ResponseCodes res = ObjectMgr::CheckPlayerName(createInfo.Name, GetSessionDbcLocale(), true);
|
||||
if (res != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
SendCharCreate(res);
|
||||
@@ -1095,7 +1095,7 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recvData)
|
||||
return;
|
||||
}
|
||||
|
||||
ResponseCodes res = ObjectMgr::CheckPlayerName(renameInfo.Name, true);
|
||||
ResponseCodes res = ObjectMgr::CheckPlayerName(renameInfo.Name, GetSessionDbcLocale(), true);
|
||||
if (res != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
SendCharRename(res, renameInfo);
|
||||
@@ -1394,7 +1394,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recvData)
|
||||
return;
|
||||
}
|
||||
|
||||
ResponseCodes res = ObjectMgr::CheckPlayerName(customizeInfo.Name, true);
|
||||
ResponseCodes res = ObjectMgr::CheckPlayerName(customizeInfo.Name, GetSessionDbcLocale(), true);
|
||||
if (res != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
SendCharCustomize(res, customizeInfo);
|
||||
@@ -1652,7 +1652,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
|
||||
return;
|
||||
}
|
||||
|
||||
ResponseCodes res = ObjectMgr::CheckPlayerName(factionChangeInfo.Name, true);
|
||||
ResponseCodes res = ObjectMgr::CheckPlayerName(factionChangeInfo.Name, GetSessionDbcLocale(), true);
|
||||
if (res != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
SendCharFactionChange(res, factionChangeInfo);
|
||||
|
||||
@@ -600,7 +600,7 @@ void WorldSession::HandlePetRename(WorldPacket& recvData)
|
||||
pet->GetOwnerGUID() != _player->GetGUID() || !pet->GetCharmInfo())
|
||||
return;
|
||||
|
||||
PetNameInvalidReason res = ObjectMgr::CheckPetName(name);
|
||||
PetNameInvalidReason res = ObjectMgr::CheckPetName(name, GetSessionDbcLocale());
|
||||
if (res != PET_NAME_SUCCESS)
|
||||
{
|
||||
SendPetNameInvalid(res, name, NULL);
|
||||
|
||||
@@ -426,7 +426,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s
|
||||
if (!normalizePlayerName(name))
|
||||
name.clear();
|
||||
|
||||
if (ObjectMgr::CheckPlayerName(name, true) == CHAR_NAME_SUCCESS)
|
||||
if (ObjectMgr::CheckPlayerName(name, sWorld->GetDefaultDbcLocale(), true) == CHAR_NAME_SUCCESS)
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME);
|
||||
stmt->setString(0, name);
|
||||
|
||||
@@ -335,7 +335,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ObjectMgr::CheckPlayerName(newName, true) != CHAR_NAME_SUCCESS)
|
||||
if (ObjectMgr::CheckPlayerName(newName, target ? target->GetSession()->GetSessionDbcLocale() : sWorld->GetDefaultDbcLocale(), true) != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
handler->SendSysMessage(LANG_BAD_VALUE);
|
||||
handler->SetSentErrorMessage(true);
|
||||
@@ -895,7 +895,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ObjectMgr::CheckPlayerName(name, true) != CHAR_NAME_SUCCESS)
|
||||
if (ObjectMgr::CheckPlayerName(name, sWorld->GetDefaultDbcLocale(), true) != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
|
||||
handler->SetSentErrorMessage(true);
|
||||
|
||||
Reference in new issue
Block a user