mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[8126] Improvemets in player/pet/charter name checks.
* Implement new config options for minimal player/pet/charter name length (2 by default) * Better error reporting at problems in names. * Add check from max pet/charter name length (same as for player names at client side)
This commit is contained in:
parent
60fe792866
commit
715470a898
12 changed files with 114 additions and 48 deletions
|
|
@ -246,16 +246,17 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
|
|||
// prevent character creating with invalid name
|
||||
if (!normalizePlayerName(name))
|
||||
{
|
||||
data << (uint8)CHAR_NAME_INVALID_CHARACTER;
|
||||
data << (uint8)CHAR_NAME_NO_NAME;
|
||||
SendPacket( &data );
|
||||
sLog.outError("Account:[%d] but tried to Create character with empty [name] ",GetAccountId());
|
||||
return;
|
||||
}
|
||||
|
||||
// check name limitations
|
||||
if(!ObjectMgr::IsValidName(name,true))
|
||||
uint8 res = ObjectMgr::CheckPlayerName(name,true);
|
||||
if (res != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
data << (uint8)CHAR_NAME_INVALID_CHARACTER;
|
||||
data << uint8(res);
|
||||
SendPacket( &data );
|
||||
return;
|
||||
}
|
||||
|
|
@ -975,10 +976,11 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recv_data)
|
|||
return;
|
||||
}
|
||||
|
||||
if(!ObjectMgr::IsValidName(newname, true))
|
||||
uint8 res = ObjectMgr::CheckPlayerName(newname,true);
|
||||
if (res != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||
data << uint8(CHAR_NAME_INVALID_CHARACTER);
|
||||
data << uint8(res);
|
||||
SendPacket( &data );
|
||||
return;
|
||||
}
|
||||
|
|
@ -1248,10 +1250,11 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data)
|
|||
return;
|
||||
}
|
||||
|
||||
if(!ObjectMgr::IsValidName(newname,true))
|
||||
uint8 res = ObjectMgr::CheckPlayerName(newname,true);
|
||||
if (res != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
|
||||
data << uint8(CHAR_NAME_INVALID_CHARACTER);
|
||||
data << uint8(res);
|
||||
SendPacket( &data );
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5634,7 +5634,7 @@ bool ChatHandler::HandlePDumpLoadCommand(const char *args)
|
|||
return false;
|
||||
}
|
||||
|
||||
if(!ObjectMgr::IsValidName(name,true))
|
||||
if (ObjectMgr::CheckPlayerName(name,true) != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
|
||||
SetSentErrorMessage(true);
|
||||
|
|
|
|||
|
|
@ -6645,18 +6645,24 @@ bool isValidString(std::wstring wstr, uint32 strictMask, bool numericOrSpace, bo
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ObjectMgr::IsValidName( const std::string& name, bool create )
|
||||
uint8 ObjectMgr::CheckPlayerName( const std::string& name, bool create )
|
||||
{
|
||||
std::wstring wname;
|
||||
if(!Utf8toWStr(name,wname))
|
||||
return false;
|
||||
return CHAR_NAME_INVALID_CHARACTER;
|
||||
|
||||
if(wname.size() < 1 || wname.size() > MAX_PLAYER_NAME)
|
||||
return false;
|
||||
if(wname.size() > MAX_PLAYER_NAME)
|
||||
return CHAR_NAME_TOO_LONG;
|
||||
|
||||
uint32 minName = sWorld.getConfig(CONFIG_MIN_PLAYER_NAME);
|
||||
if(wname.size() < minName)
|
||||
return CHAR_NAME_TOO_SHORT;
|
||||
|
||||
uint32 strictMask = sWorld.getConfig(CONFIG_STRICT_PLAYER_NAMES);
|
||||
if(!isValidString(wname,strictMask,false,create))
|
||||
return CHAR_NAME_MIXED_LANGUAGES;
|
||||
|
||||
return isValidString(wname,strictMask,false,create);
|
||||
return CHAR_NAME_SUCCESS;
|
||||
}
|
||||
|
||||
bool ObjectMgr::IsValidCharterName( const std::string& name )
|
||||
|
|
@ -6665,7 +6671,11 @@ bool ObjectMgr::IsValidCharterName( const std::string& name )
|
|||
if(!Utf8toWStr(name,wname))
|
||||
return false;
|
||||
|
||||
if(wname.size() < 1)
|
||||
if(wname.size() > MAX_CHARTER_NAME)
|
||||
return false;
|
||||
|
||||
uint32 minName = sWorld.getConfig(CONFIG_MIN_CHARTER_NAME);
|
||||
if(wname.size() < minName)
|
||||
return false;
|
||||
|
||||
uint32 strictMask = sWorld.getConfig(CONFIG_STRICT_CHARTER_NAMES);
|
||||
|
|
@ -6673,18 +6683,24 @@ bool ObjectMgr::IsValidCharterName( const std::string& name )
|
|||
return isValidString(wname,strictMask,true);
|
||||
}
|
||||
|
||||
bool ObjectMgr::IsValidPetName( const std::string& name )
|
||||
PetNameInvalidReason ObjectMgr::CheckPetName( const std::string& name )
|
||||
{
|
||||
std::wstring wname;
|
||||
if(!Utf8toWStr(name,wname))
|
||||
return false;
|
||||
return PET_NAME_INVALID;
|
||||
|
||||
if(wname.size() < 1)
|
||||
return false;
|
||||
if(wname.size() > MAX_PET_NAME)
|
||||
return PET_NAME_TOO_LONG;
|
||||
|
||||
uint32 minName = sWorld.getConfig(CONFIG_MIN_PET_NAME);
|
||||
if(wname.size() < minName)
|
||||
return PET_NAME_TOO_SHORT;
|
||||
|
||||
uint32 strictMask = sWorld.getConfig(CONFIG_STRICT_PET_NAMES);
|
||||
if(!isValidString(wname,strictMask,false))
|
||||
return PET_NAME_MIXED_LANGUAGES;
|
||||
|
||||
return isValidString(wname,strictMask,false);
|
||||
return PET_NAME_SUCCESS;
|
||||
}
|
||||
|
||||
int ObjectMgr::GetIndexForLocale( LocaleConstant loc )
|
||||
|
|
|
|||
|
|
@ -281,6 +281,8 @@ SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
|
|||
|
||||
#define MAX_PLAYER_NAME 12 // max allowed by client name length
|
||||
#define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
|
||||
#define MAX_PET_NAME 12 // max allowed by client name length
|
||||
#define MAX_CHARTER_NAME 24 // max allowed by client name length
|
||||
|
||||
bool normalizePlayerName(std::string& name);
|
||||
|
||||
|
|
@ -693,9 +695,9 @@ class ObjectMgr
|
|||
bool IsReservedName(const std::string& name) const;
|
||||
|
||||
// name with valid structure and symbols
|
||||
static bool IsValidName( const std::string& name, bool create = false );
|
||||
static uint8 CheckPlayerName( const std::string& name, bool create = false );
|
||||
static PetNameInvalidReason CheckPetName( const std::string& name );
|
||||
static bool IsValidCharterName( const std::string& name );
|
||||
static bool IsValidPetName( const std::string& name );
|
||||
|
||||
static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,9 @@ enum PetTalk
|
|||
|
||||
enum PetNameInvalidReason
|
||||
{
|
||||
// custom, not send
|
||||
PET_NAME_SUCCESS = 0,
|
||||
|
||||
PET_NAME_INVALID = 1,
|
||||
PET_NAME_NO_NAME = 2,
|
||||
PET_NAME_TOO_SHORT = 3,
|
||||
|
|
|
|||
|
|
@ -401,9 +401,10 @@ void WorldSession::HandlePetRename( WorldPacket & recv_data )
|
|||
pet->GetOwnerGUID() != _player->GetGUID() || !pet->GetCharmInfo() )
|
||||
return;
|
||||
|
||||
if(!ObjectMgr::IsValidPetName(name))
|
||||
PetNameInvalidReason res = ObjectMgr::CheckPetName(name);
|
||||
if(res != PET_NAME_SUCCESS)
|
||||
{
|
||||
SendPetNameInvalid(PET_NAME_INVALID, name, NULL);
|
||||
SendPetNameInvalid(res, name, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14043,7 +14043,8 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
|
|||
m_name = fields[3].GetCppString();
|
||||
|
||||
// check name limitations
|
||||
if(!ObjectMgr::IsValidName(m_name) || (GetSession()->GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(m_name)))
|
||||
if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS ||
|
||||
GetSession()->GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(m_name))
|
||||
{
|
||||
delete result;
|
||||
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid ='%u'", uint32(AT_LOGIN_RENAME),guid);
|
||||
|
|
|
|||
|
|
@ -430,7 +430,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
|
|||
if (!normalizePlayerName(name))
|
||||
name = "";
|
||||
|
||||
if(ObjectMgr::IsValidName(name,true))
|
||||
if (ObjectMgr::CheckPlayerName(name,true) == CHAR_NAME_SUCCESS)
|
||||
{
|
||||
CharacterDatabase.escape_string(name); // for safe, we use name only for sql quearies anyway
|
||||
result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE name = '%s'", name.c_str());
|
||||
|
|
@ -440,7 +440,8 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
|
|||
delete result;
|
||||
}
|
||||
}
|
||||
else name = "";
|
||||
else
|
||||
name = "";
|
||||
|
||||
// name encoded or empty
|
||||
|
||||
|
|
|
|||
|
|
@ -624,6 +624,27 @@ void World::LoadConfigSettings(bool reload)
|
|||
m_configs[CONFIG_STRICT_CHARTER_NAMES] = sConfig.GetIntDefault ("StrictCharterNames", 0);
|
||||
m_configs[CONFIG_STRICT_PET_NAMES] = sConfig.GetIntDefault ("StrictPetNames", 0);
|
||||
|
||||
m_configs[CONFIG_MIN_PLAYER_NAME] = sConfig.GetIntDefault ("MinPlayerName", 2);
|
||||
if(m_configs[CONFIG_MIN_PLAYER_NAME] < 1 || m_configs[CONFIG_MIN_PLAYER_NAME] > MAX_PLAYER_NAME)
|
||||
{
|
||||
sLog.outError("MinPlayerName (%i) must be in range 1..%u. Set to 2.",m_configs[CONFIG_MIN_PLAYER_NAME],MAX_PLAYER_NAME);
|
||||
m_configs[CONFIG_MIN_PLAYER_NAME] = 2;
|
||||
}
|
||||
|
||||
m_configs[CONFIG_MIN_CHARTER_NAME] = sConfig.GetIntDefault ("MinCharterName", 2);
|
||||
if(m_configs[CONFIG_MIN_CHARTER_NAME] < 1 || m_configs[CONFIG_MIN_CHARTER_NAME] > MAX_CHARTER_NAME)
|
||||
{
|
||||
sLog.outError("MinCharterName (%i) must be in range 1..%u. Set to 2.",m_configs[CONFIG_MIN_CHARTER_NAME],MAX_CHARTER_NAME);
|
||||
m_configs[CONFIG_MIN_CHARTER_NAME] = 2;
|
||||
}
|
||||
|
||||
m_configs[CONFIG_MIN_PET_NAME] = sConfig.GetIntDefault ("MinPetName", 2);
|
||||
if(m_configs[CONFIG_MIN_PET_NAME] < 1 || m_configs[CONFIG_MIN_PET_NAME] > MAX_PET_NAME)
|
||||
{
|
||||
sLog.outError("MinPetName (%i) must be in range 1..%u. Set to 2.",m_configs[CONFIG_MIN_PET_NAME],MAX_PET_NAME);
|
||||
m_configs[CONFIG_MIN_PET_NAME] = 2;
|
||||
}
|
||||
|
||||
m_configs[CONFIG_CHARACTERS_CREATING_DISABLED] = sConfig.GetIntDefault ("CharactersCreatingDisabled", 0);
|
||||
|
||||
m_configs[CONFIG_CHARACTERS_PER_REALM] = sConfig.GetIntDefault("CharactersPerRealm", 10);
|
||||
|
|
|
|||
|
|
@ -107,6 +107,9 @@ enum WorldConfigs
|
|||
CONFIG_STRICT_PLAYER_NAMES,
|
||||
CONFIG_STRICT_CHARTER_NAMES,
|
||||
CONFIG_STRICT_PET_NAMES,
|
||||
CONFIG_MIN_PLAYER_NAME,
|
||||
CONFIG_MIN_CHARTER_NAME,
|
||||
CONFIG_MIN_PET_NAME,
|
||||
CONFIG_CHARACTERS_CREATING_DISABLED,
|
||||
CONFIG_CHARACTERS_PER_ACCOUNT,
|
||||
CONFIG_CHARACTERS_PER_REALM,
|
||||
|
|
|
|||
|
|
@ -396,6 +396,18 @@ LogColors = ""
|
|||
# (included in client by default, with active official localization or custom localization fonts in clientdir/Fonts).
|
||||
# 3 basic latin characters + server timezone specific
|
||||
#
|
||||
# MinPlayerName
|
||||
# Minimal name length (1..12)
|
||||
# Default: 2
|
||||
#
|
||||
# MinCharterName
|
||||
# Minimal name length (1..24)
|
||||
# Default: 2
|
||||
#
|
||||
# MinPetName
|
||||
# Minimal name length (1..12)
|
||||
# Default: 2
|
||||
#
|
||||
# CharactersCreatingDisabled
|
||||
# Disable characters creating for specific team or any (non-player accounts not affected)
|
||||
# Default: 0 - enabled
|
||||
|
|
@ -579,6 +591,9 @@ DeclinedNames = 0
|
|||
StrictPlayerNames = 0
|
||||
StrictCharterNames = 0
|
||||
StrictPetNames = 0
|
||||
MinPlayerName = 2
|
||||
MinCharterName = 2
|
||||
MinPetName = 2
|
||||
CharactersCreatingDisabled = 0
|
||||
CharactersPerAccount = 50
|
||||
CharactersPerRealm = 10
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "8125"
|
||||
#define REVISION_NR "8126"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue