mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 17:51:28 +00:00
IsBotNameValid converted to QueryDatabase
This commit is contained in:
parent
118c2a9db9
commit
9eb3907d45
36
zone/bot.cpp
36
zone/bot.cpp
@ -2339,35 +2339,29 @@ bool Bot::IsValidName() {
|
||||
}
|
||||
|
||||
bool Bot::IsBotNameAvailable(std::string* errorMessage) {
|
||||
bool Result = false;
|
||||
|
||||
if(this->GetCleanName()) {
|
||||
char* Query = 0;
|
||||
char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE];
|
||||
MYSQL_RES* DatasetResult;
|
||||
MYSQL_ROW DataRow;
|
||||
if(!this->GetCleanName())
|
||||
return false;
|
||||
|
||||
if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT COUNT(id) FROM vwBotCharacterMobs WHERE name LIKE '%s'", this->GetCleanName()), TempErrorMessageBuffer, &DatasetResult)) {
|
||||
*errorMessage = std::string(TempErrorMessageBuffer);
|
||||
std::string query = StringFormat("SELECT COUNT(id) FROM vwBotCharacterMobs "
|
||||
"WHERE name LIKE '%s'", this->GetCleanName());
|
||||
auto results = database.QueryDatabase(query);
|
||||
if(!results.Success()) {
|
||||
*errorMessage = std::string(results.ErrorMessage());
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
uint32 ExistingNameCount = 0;
|
||||
|
||||
while(DataRow = mysql_fetch_row(DatasetResult)) {
|
||||
ExistingNameCount = atoi(DataRow[0]);
|
||||
uint32 existingNameCount = 0;
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
existingNameCount = atoi(row[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
if(ExistingNameCount == 0)
|
||||
Result = true;
|
||||
if(existingNameCount != 0)
|
||||
return false;
|
||||
|
||||
mysql_free_result(DatasetResult);
|
||||
}
|
||||
|
||||
safe_delete(Query);
|
||||
}
|
||||
|
||||
return Result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Bot::Save() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user