From 443e3bf8a76eb5b048125256449644ab5a42d43d Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 24 Jan 2015 01:20:04 -0600 Subject: [PATCH] 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 --- common/database.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/database.cpp b/common/database.cpp index 02f735737..eab564ff4 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -292,8 +292,17 @@ bool Database::SetAccountStatus(const char* name, int16 status) { /* This initially creates the character during character create */ 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); + 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; } return true; }