aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/CharacterHandler.cpp37
-rw-r--r--src/game/Level3.cpp12
-rw-r--r--src/game/ObjectMgr.cpp40
-rw-r--r--src/game/ObjectMgr.h8
-rw-r--r--src/game/Pet.h3
-rw-r--r--src/game/PetHandler.cpp5
-rw-r--r--src/game/Player.cpp3
-rw-r--r--src/game/PlayerDump.cpp13
-rw-r--r--src/game/World.cpp21
-rw-r--r--src/game/World.h3
-rw-r--r--src/trinitycore/trinitycore.conf.dist15
11 files changed, 113 insertions, 47 deletions
diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp
index 01120643dd2..a5849b2aa98 100644
--- a/src/game/CharacterHandler.cpp
+++ b/src/game/CharacterHandler.cpp
@@ -249,30 +249,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 );
@@ -280,7 +281,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();
@@ -985,7 +986,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);
@@ -993,16 +994,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);
@@ -1258,7 +1260,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);
@@ -1266,16 +1268,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);
@@ -1284,9 +1287,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);
diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp
index a099aa8f66c..4fb765fa8a9 100644
--- a/src/game/Level3.cpp
+++ b/src/game/Level3.cpp
@@ -6481,18 +6481,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);
@@ -6504,17 +6504,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);
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index bff6975ae81..cbe113d6f6f 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -7071,18 +7071,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 strictMask = sWorld.getConfig(CONFIG_STRICT_PLAYER_NAMES);
+ uint32 minName = sWorld.getConfig(CONFIG_MIN_PLAYER_NAME);
+ if(wname.size() < minName)
+ return CHAR_NAME_TOO_SHORT;
- return isValidString(wname,strictMask,false,create);
+ uint32 strictMask = sWorld.getConfig(CONFIG_STRICT_PLAYER_NAMES);
+ if(!isValidString(wname,strictMask,false,create))
+ return CHAR_NAME_MIXED_LANGUAGES;
+
+ return CHAR_NAME_SUCCESS;
}
bool ObjectMgr::IsValidCharterName( const std::string& name )
@@ -7091,7 +7097,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);
@@ -7099,18 +7109,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 )
diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h
index 037ba4a78f2..4c83e584421 100644
--- a/src/game/ObjectMgr.h
+++ b/src/game/ObjectMgr.h
@@ -312,8 +312,10 @@ struct GM_Ticket
typedef std::list<GM_Ticket*> GmTicketList;
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);
@@ -759,9 +761,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);
diff --git a/src/game/Pet.h b/src/game/Pet.h
index 6ad47b63c6c..88287ce5dee 100644
--- a/src/game/Pet.h
+++ b/src/game/Pet.h
@@ -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,
diff --git a/src/game/PetHandler.cpp b/src/game/PetHandler.cpp
index 3d92caa406c..55f7fa42055 100644
--- a/src/game/PetHandler.cpp
+++ b/src/game/PetHandler.cpp
@@ -438,9 +438,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;
}
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index a3f784ac292..e74b324d749 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -14484,7 +14484,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);
diff --git a/src/game/PlayerDump.cpp b/src/game/PlayerDump.cpp
index 73939115211..d333961a6b1 100644
--- a/src/game/PlayerDump.cpp
+++ b/src/game/PlayerDump.cpp
@@ -395,7 +395,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();
@@ -407,7 +407,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;
@@ -415,7 +415,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)
@@ -429,10 +429,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());
@@ -442,7 +442,8 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
delete result;
}
}
- else name = "";
+ else
+ name = "";
// name encoded or empty
diff --git a/src/game/World.cpp b/src/game/World.cpp
index bd85fe30baa..2fa90e6c148 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -639,6 +639,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);
diff --git a/src/game/World.h b/src/game/World.h
index 4fbde8ccb71..f254782c4eb 100644
--- a/src/game/World.h
+++ b/src/game/World.h
@@ -112,6 +112,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,
diff --git a/src/trinitycore/trinitycore.conf.dist b/src/trinitycore/trinitycore.conf.dist
index c35a6efa952..e59206367da 100644
--- a/src/trinitycore/trinitycore.conf.dist
+++ b/src/trinitycore/trinitycore.conf.dist
@@ -536,6 +536,18 @@ ChatLogTimestamp = 0
# (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
@@ -729,6 +741,9 @@ StrictPlayerNames = 0
StrictCharterNames = 0
StrictPetNames = 0
MaxWhoListReturns = 49
+MinPlayerName = 2
+MinCharterName = 2
+MinPetName = 2
CharactersCreatingDisabled = 0
CharactersPerAccount = 50
CharactersPerRealm = 10