mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-05 02:52:25 +00:00
Modified ZippZipp's bot name fix from the forums. Limited bot name length to fix a crash. Added Filter check too if you use the Name Filter.
This commit is contained in:
parent
e5f979665d
commit
95243fd6ce
42
zone/bot.cpp
42
zone/bot.cpp
@ -2327,30 +2327,22 @@ bool Bot::IsValidName() {
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bot::IsBotNameAvailable(std::string* errorMessage) {
|
bool Bot::IsBotNameAvailable(char *botName, std::string* errorMessage) {
|
||||||
|
if (botName == "" || strlen(botName) > 15 || !database.CheckNameFilter(botName) || !database.CheckUsedName(botName)) {
|
||||||
|
return false; //Check if Botname is Empty / Check if Botname larger than 15 char / Valid to Player standards / Not used by a player!
|
||||||
|
}
|
||||||
|
|
||||||
if(!this->GetCleanName())
|
std::string query = StringFormat("SELECT id FROM vwBotCharacterMobs WHERE name LIKE '%s'", botName);
|
||||||
return false;
|
auto results = database.QueryDatabase(query);
|
||||||
|
|
||||||
std::string query = StringFormat("SELECT COUNT(id) FROM vwBotCharacterMobs "
|
|
||||||
"WHERE name LIKE '%s'", this->GetCleanName());
|
|
||||||
auto results = database.QueryDatabase(query);
|
|
||||||
if(!results.Success()) {
|
if(!results.Success()) {
|
||||||
*errorMessage = std::string(results.ErrorMessage());
|
*errorMessage = std::string(results.ErrorMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (results.RowCount()) { //Name already in use!
|
||||||
uint32 existingNameCount = 0;
|
|
||||||
|
|
||||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
|
||||||
existingNameCount = atoi(row[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(existingNameCount != 0)
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
|
||||||
|
return true; //We made it with a valid name!
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bot::Save() {
|
bool Bot::Save() {
|
||||||
@ -11330,6 +11322,11 @@ void Bot::ProcessBotCommands(Client *c, const Seperator *sep) {
|
|||||||
if(!strcasecmp(sep->arg[5], "female"))
|
if(!strcasecmp(sep->arg[5], "female"))
|
||||||
gender = 1;
|
gender = 1;
|
||||||
|
|
||||||
|
if(!IsBotNameAvailable(sep->arg[2],&TempErrorMessage)) {
|
||||||
|
c->Message(0, "The name %s is already being used or is invalid. Please choose a different name.", sep->arg[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
NPCType DefaultNPCTypeStruct = CreateDefaultNPCTypeStructForBot(std::string(sep->arg[2]), std::string(), c->GetLevel(), atoi(sep->arg[4]), atoi(sep->arg[3]), gender);
|
NPCType DefaultNPCTypeStruct = CreateDefaultNPCTypeStructForBot(std::string(sep->arg[2]), std::string(), c->GetLevel(), atoi(sep->arg[4]), atoi(sep->arg[3]), gender);
|
||||||
Bot* NewBot = new Bot(DefaultNPCTypeStruct, c);
|
Bot* NewBot = new Bot(DefaultNPCTypeStruct, c);
|
||||||
|
|
||||||
@ -11344,11 +11341,6 @@ void Bot::ProcessBotCommands(Client *c, const Seperator *sep) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!NewBot->IsBotNameAvailable(&TempErrorMessage)) {
|
|
||||||
c->Message(0, "The name %s is already being used. Please choose a different name.", NewBot->GetCleanName());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!TempErrorMessage.empty()) {
|
if(!TempErrorMessage.empty()) {
|
||||||
c->Message(13, "Database Error: %s", TempErrorMessage.c_str());
|
c->Message(13, "Database Error: %s", TempErrorMessage.c_str());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -154,7 +154,7 @@ public:
|
|||||||
// Class Methods
|
// Class Methods
|
||||||
bool IsValidRaceClassCombo();
|
bool IsValidRaceClassCombo();
|
||||||
bool IsValidName();
|
bool IsValidName();
|
||||||
bool IsBotNameAvailable(std::string* errorMessage);
|
static bool IsBotNameAvailable(char *botName, std::string* errorMessage);
|
||||||
bool DeleteBot(std::string* errorMessage);
|
bool DeleteBot(std::string* errorMessage);
|
||||||
void Spawn(Client* botCharacterOwner, std::string* errorMessage);
|
void Spawn(Client* botCharacterOwner, std::string* errorMessage);
|
||||||
virtual void SetLevel(uint8 in_level, bool command = false);
|
virtual void SetLevel(uint8 in_level, bool command = false);
|
||||||
|
|||||||
@ -2071,6 +2071,11 @@ bool QuestManager::createBot(const char *name, const char *lastname, uint8 level
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Bot::IsBotNameAvailable((char*)name,&TempErrorMessage)) {
|
||||||
|
initiator->Message(0, "The name %s is already being used or is invalid. Please choose a different name.", (char*)name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
NPCType DefaultNPCTypeStruct = Bot::CreateDefaultNPCTypeStructForBot(name, lastname, level, race, botclass, gender);
|
NPCType DefaultNPCTypeStruct = Bot::CreateDefaultNPCTypeStructForBot(name, lastname, level, race, botclass, gender);
|
||||||
Bot* NewBot = new Bot(DefaultNPCTypeStruct, initiator);
|
Bot* NewBot = new Bot(DefaultNPCTypeStruct, initiator);
|
||||||
|
|
||||||
@ -2086,11 +2091,6 @@ bool QuestManager::createBot(const char *name, const char *lastname, uint8 level
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!NewBot->IsBotNameAvailable(&TempErrorMessage)) {
|
|
||||||
initiator->Message(0, "The name %s is already being used. Please choose a different name.", NewBot->GetCleanName());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!TempErrorMessage.empty()) {
|
if(!TempErrorMessage.empty()) {
|
||||||
initiator->Message(13, "Database Error: %s", TempErrorMessage.c_str());
|
initiator->Message(13, "Database Error: %s", TempErrorMessage.c_str());
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user