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:
Natedog2012
2015-05-28 11:45:07 -07:00
parent e5f979665d
commit 95243fd6ce
3 changed files with 23 additions and 31 deletions
+17 -25
View File
@@ -2327,30 +2327,22 @@ bool Bot::IsValidName() {
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())
return false;
std::string query = StringFormat("SELECT COUNT(id) FROM vwBotCharacterMobs "
"WHERE name LIKE '%s'", this->GetCleanName());
auto results = database.QueryDatabase(query);
std::string query = StringFormat("SELECT id FROM vwBotCharacterMobs WHERE name LIKE '%s'", botName);
auto results = database.QueryDatabase(query);
if(!results.Success()) {
*errorMessage = std::string(results.ErrorMessage());
*errorMessage = std::string(results.ErrorMessage());
return false;
}
uint32 existingNameCount = 0;
for (auto row = results.begin(); row != results.end(); ++row) {
existingNameCount = atoi(row[0]);
break;
}
if(existingNameCount != 0)
}
if (results.RowCount()) { //Name already in use!
return false;
return true;
}
return true; //We made it with a valid name!
}
bool Bot::Save() {
@@ -11330,6 +11322,11 @@ void Bot::ProcessBotCommands(Client *c, const Seperator *sep) {
if(!strcasecmp(sep->arg[5], "female"))
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);
Bot* NewBot = new Bot(DefaultNPCTypeStruct, c);
@@ -11344,11 +11341,6 @@ void Bot::ProcessBotCommands(Client *c, const Seperator *sep) {
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()) {
c->Message(13, "Database Error: %s", TempErrorMessage.c_str());
return;