[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:
VladimirMangos 2009-07-05 19:58:26 +04:00
parent 60fe792866
commit 715470a898
12 changed files with 114 additions and 48 deletions

View file

@ -244,30 +244,31 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
}
// prevent character creating with invalid name
if(!normalizePlayerName(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;
}
if(GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(name))
if (GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(name))
{
data << (uint8)CHAR_NAME_RESERVED;
SendPacket( &data );
return;
}
if(objmgr.GetPlayerGUIDByName(name))
if (objmgr.GetPlayerGUIDByName(name))
{
data << (uint8)CHAR_CREATE_NAME_IN_USE;
SendPacket( &data );
@ -275,7 +276,7 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
}
QueryResult *resultacct = loginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
if ( resultacct )
if (resultacct)
{
Field *fields=resultacct->Fetch();
uint32 acctcharcount = fields[0].GetUInt32();
@ -967,7 +968,7 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recv_data)
recv_data >> newname;
// prevent character rename to invalid name
if(!normalizePlayerName(newname))
if (!normalizePlayerName(newname))
{
WorldPacket data(SMSG_CHAR_RENAME, 1);
data << uint8(CHAR_NAME_NO_NAME);
@ -975,16 +976,17 @@ 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;
}
// check name limitations
if(GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(newname))
if (GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(newname))
{
WorldPacket data(SMSG_CHAR_RENAME, 1);
data << uint8(CHAR_NAME_RESERVED);
@ -1240,7 +1242,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data)
}
// prevent character rename to invalid name
if(!normalizePlayerName(newname))
if (!normalizePlayerName(newname))
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(CHAR_NAME_NO_NAME);
@ -1248,16 +1250,17 @@ 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;
}
// check name limitations
if(GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(newname))
if (GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(newname))
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(CHAR_NAME_RESERVED);
@ -1266,9 +1269,9 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data)
}
// character with this name already exist
if(uint64 newguid = objmgr.GetPlayerGUIDByName(newname))
if (uint64 newguid = objmgr.GetPlayerGUIDByName(newname))
{
if(newguid != guid)
if (newguid != guid)
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(CHAR_CREATE_NAME_IN_USE);

View file

@ -5623,18 +5623,18 @@ bool ChatHandler::HandlePDumpLoadCommand(const char *args)
char* name_str = strtok(NULL, " ");
std::string name;
if(name_str)
if (name_str)
{
name = name_str;
// normalize the name if specified and check if it exists
if(!normalizePlayerName(name))
if (!normalizePlayerName(name))
{
PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
SetSentErrorMessage(true);
return false;
}
if(!ObjectMgr::IsValidName(name,true))
if (ObjectMgr::CheckPlayerName(name,true) != CHAR_NAME_SUCCESS)
{
PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
SetSentErrorMessage(true);
@ -5646,17 +5646,17 @@ bool ChatHandler::HandlePDumpLoadCommand(const char *args)
uint32 guid = 0;
if(guid_str)
if (guid_str)
{
guid = atoi(guid_str);
if(!guid)
if (!guid)
{
PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
SetSentErrorMessage(true);
return false;
}
if(objmgr.GetPlayerAccountIdByGUID(guid))
if (objmgr.GetPlayerAccountIdByGUID(guid))
{
PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
SetSentErrorMessage(true);

View file

@ -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);
return isValidString(wname,strictMask,false,create);
if(!isValidString(wname,strictMask,false,create))
return CHAR_NAME_MIXED_LANGUAGES;
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 )

View file

@ -279,8 +279,10 @@ enum SkillRangeType
SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
#define MAX_PLAYER_NAME 12 // max allowed by client name length
#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);

View file

@ -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,

View file

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

View file

@ -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);

View file

@ -393,7 +393,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
{
QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", account);
uint8 charcount = 0;
if ( result )
if (result)
{
Field *fields=result->Fetch();
charcount = fields[0].GetUInt8();
@ -405,7 +405,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
}
FILE *fin = fopen(file.c_str(), "r");
if(!fin)
if (!fin)
return DUMP_FILE_OPEN_ERROR;
QueryResult * result = NULL;
@ -413,7 +413,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
// make sure the same guid doesn't already exist and is safe to use
bool incHighest = true;
if(guid != 0 && guid < objmgr.m_hiCharGuid)
if (guid != 0 && guid < objmgr.m_hiCharGuid)
{
result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE guid = '%d'", guid);
if (result)
@ -427,10 +427,10 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
guid = objmgr.m_hiCharGuid;
// normalize the name if specified and check if it exists
if(!normalizePlayerName(name))
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

View file

@ -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);

View file

@ -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,

View file

@ -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

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "8125"
#define REVISION_NR "8126"
#endif // __REVISION_NR_H__