Fix Database::ReserveName so that it no longer relies on a failed insert into the character_data table to return false; on character creation. Log message for Logs::World_Server added for the same

This commit is contained in:
Akkadius 2015-01-24 01:20:04 -06:00
parent 66008f4475
commit 443e3bf8a7

View File

@ -292,8 +292,17 @@ bool Database::SetAccountStatus(const char* name, int16 status) {
/* This initially creates the character during character create */ /* This initially creates the character during character create */
bool Database::ReserveName(uint32 account_id, char* name) { bool Database::ReserveName(uint32 account_id, char* name) {
std::string query = StringFormat("INSERT INTO `character_data` SET `account_id` = %i, `name` = '%s'", account_id, name); std::string query = StringFormat("SELECT `account_id`, `name` FROM `character_data` WHERE `name` = '%s'", name);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
for (auto row = results.begin(); row != results.end(); ++row) {
if (row[0] && atoi(row[0]) > 0){
Log.Out(Logs::General, Logs::World_Server, "Account: %i tried to request name: %s, but it is already taken...", account_id, name);
return false;
}
}
query = StringFormat("INSERT INTO `character_data` SET `account_id` = %i, `name` = '%s'", account_id, name);
results = QueryDatabase(query);
if (!results.Success() || results.ErrorMessage() != ""){ return false; } if (!results.Success() || results.ErrorMessage() != ""){ return false; }
return true; return true;
} }