Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- common/database.cpp | 42 +++++++++++++++++++++++++++++-------------
- 1 file changed, 29 insertions(+), 13 deletions(-)
- diff --git a/common/database.cpp b/common/database.cpp
- index d0e2f3c..04ea755 100644
- --- a/common/database.cpp
- +++ b/common/database.cpp
- @@ -2518,25 +2518,41 @@ bool Database::GetUnusedInstanceID(uint16 &instance_id)
- uint32 count = RuleI(Zone, ReservedInstances) + 1;
- uint32 max = 65535;
- -
- - if (RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM instance_list where id >= %i ORDER BY id", count), errbuf, &result)) {
- + if (RunQuery(query, MakeAnyLenString(&query, "SELECT IFNULL(MAX(id),%i)+1 FROM instance_list WHERE id > %i", count,count), errbuf, &result)) {
- safe_delete_array(query);
- - if (mysql_num_rows(result) != 0) {
- - while((row = mysql_fetch_row(result))) {
- - if(count < atoi(row[0])) {
- - instance_id = count;
- - mysql_free_result(result);
- - return true;
- - } else if(count > max) {
- - instance_id = 0;
- - mysql_free_result(result);
- - return false;
- + if (mysql_num_rows(result) != 1) {
- + row = mysql_fetch_row(result);
- + mysql_free_result(result);
- + if(atoi(row[0]) <= max) {
- + count = atoi(row[0]);
- + } else {
- + if (RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM instance_list where id >= %i ORDER BY id", count), errbuf, &result)) {
- + safe_delete_array(query);
- + if (mysql_num_rows(result) != 0) {
- + while((row = mysql_fetch_row(result))) {
- + if(count < atoi(row[0])) {
- + instance_id = count;
- + mysql_free_result(result);
- + return true;
- + } else if(count > max) {
- + instance_id = 0;
- + mysql_free_result(result);
- + return false;
- + } else {
- + count++;
- + }
- + }
- + } else {
- + mysql_free_result(result);
- + }
- } else {
- - count++;
- + safe_delete_array(query);
- }
- }
- } else {
- + instance_id = 0;
- mysql_free_result(result);
- + return false;
- }
- } else {
- safe_delete_array(query);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement