From f1bb019933fa8e4010905a3d082c1854e40f3e3b Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 16:46:17 -0700 Subject: [PATCH 01/67] SaveZoneCFG converted to QueryDatabase --- zone/zonedb.cpp | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 0d1653453..d2fd1f8e5 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -69,23 +69,26 @@ ZoneDatabase::~ZoneDatabase() { } } -bool ZoneDatabase::SaveZoneCFG(uint32 zoneid, uint16 instance_id, NewZone_Struct* zd){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - if (!RunQuery(query, MakeAnyLenString(&query, "update zone set underworld=%f,minclip=%f," - "maxclip=%f,fog_minclip=%f,fog_maxclip=%f,fog_blue=%i,fog_red=%i,fog_green=%i,sky=%i," - "ztype=%i,zone_exp_multiplier=%f,safe_x=%f,safe_y=%f,safe_z=%f " - "where zoneidnumber=%i and version=%i", - zd->underworld,zd->minclip, - zd->maxclip,zd->fog_minclip[0],zd->fog_maxclip[0],zd->fog_blue[0],zd->fog_red[0],zd->fog_green[0],zd->sky, - zd->ztype,zd->zone_exp_multiplier, - zd->safe_x,zd->safe_y,zd->safe_z, - zoneid, instance_id),errbuf)) { - LogFile->write(EQEMuLog::Error, "Error in SaveZoneCFG query %s: %s", query, errbuf); - safe_delete_array(query); - return false; +bool ZoneDatabase::SaveZoneCFG(uint32 zoneid, uint16 instance_id, NewZone_Struct* zd) { + + std::string query = StringFormat("UPDATE zone SET underworld = %f, minclip = %f, " + "maxclip = %f, fog_minclip = %f, fog_maxclip = %f, " + "fog_blue = %i, fog_red = %i, fog_green = %i, " + "sky = %i, ztype = %i, zone_exp_multiplier = %f, " + "safe_x = %f, safe_y = %f, safe_z = %f " + "WHERE zoneidnumber = %i AND version = %i", + zd->underworld, zd->minclip, + zd->maxclip, zd->fog_minclip[0], zd->fog_maxclip[0], + zd->fog_blue[0], zd->fog_red[0], zd->fog_green[0], + zd->sky, zd->ztype, zd->zone_exp_multiplier, + zd->safe_x, zd->safe_y, zd->safe_z, + zoneid, instance_id); + auto results = QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in SaveZoneCFG query %s: %s", query.c_str(), results.ErrorMessage().c_str()); + return false; } - safe_delete_array(query); + return true; } @@ -1211,7 +1214,7 @@ const NPCType* ZoneDatabase::GetNPCType (uint32 id) { tmpNPCType->armor_tint[0] |= (atoi(row[r++]) & 0xFF) << 8; tmpNPCType->armor_tint[0] |= (atoi(row[r++]) & 0xFF); tmpNPCType->armor_tint[0] |= (tmpNPCType->armor_tint[0]) ? (0xFF << 24) : 0; - + int i; if (armor_tint_id > 0) { @@ -1304,7 +1307,7 @@ const NPCType* ZoneDatabase::GetNPCType (uint32 id) { tmpNPCType->healscale = atoi(row[r++]); tmpNPCType->no_target_hotkey = atoi(row[r++]) == 1 ? true : false; tmpNPCType->raid_target = atoi(row[r++]) == 0 ? false : true; - + // If NPC with duplicate NPC id already in table, // free item we attempted to add. if (zone->npctable.find(tmpNPCType->npc_id) != zone->npctable.end()) @@ -1849,9 +1852,9 @@ void ZoneDatabase::SaveMercBuffs(Merc *merc) { CalculateCorruptionCounters(buffs[BuffCount].spellid) > 0 ? buffs[BuffCount].counters : 0, buffs[BuffCount].numhits, buffs[BuffCount].melee_rune, buffs[BuffCount].magic_rune, buffs[BuffCount].dot_rune, - buffs[BuffCount].caston_x, - IsPersistent, - buffs[BuffCount].caston_y, + buffs[BuffCount].caston_x, + IsPersistent, + buffs[BuffCount].caston_y, buffs[BuffCount].caston_z, buffs[BuffCount].ExtraDIChance), TempErrorMessageBuffer)) { errorMessage = std::string(TempErrorMessageBuffer); @@ -2931,7 +2934,7 @@ void ZoneDatabase::LoadPetInfo(Client *c) { pi = suspended; else continue; - + int slot = atoi(row[1]); if (slot < EmuConstants::EQUIPMENT_BEGIN || slot > EmuConstants::EQUIPMENT_END) continue; From 693dde04e34a9c415802a056e6e6ff93fbd836df Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:16:30 -0700 Subject: [PATCH 02/67] GetZoneCFG converted to QueryDatabase --- zone/zonedb.cpp | 182 +++++++++++++++++++++++------------------------- 1 file changed, 88 insertions(+), 94 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index d2fd1f8e5..cba20fdcc 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -93,103 +93,97 @@ bool ZoneDatabase::SaveZoneCFG(uint32 zoneid, uint16 instance_id, NewZone_Struct } bool ZoneDatabase::GetZoneCFG(uint32 zoneid, uint16 instance_id, NewZone_Struct *zone_data, bool &can_bind, bool &can_combat, bool &can_levitate, bool &can_castoutdoor, bool &is_city, bool &is_hotzone, bool &allow_mercs, uint8 &zone_type, int &ruleset, char **map_filename) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - int i=0; - int b=0; - bool good = false; + *map_filename = new char[100]; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT ztype," - "fog_red,fog_green,fog_blue,fog_minclip,fog_maxclip," - "fog_red2,fog_green2,fog_blue2,fog_minclip2,fog_maxclip2," - "fog_red3,fog_green3,fog_blue3,fog_minclip3,fog_maxclip3," - "fog_red4,fog_green4,fog_blue4,fog_minclip4,fog_maxclip4,fog_density," - "sky,zone_exp_multiplier,safe_x,safe_y,safe_z,underworld," - "minclip,maxclip,time_type,canbind,cancombat,canlevitate," - "castoutdoor,hotzone,ruleset,suspendbuffs,map_file_name,short_name," - "rain_chance1,rain_chance2,rain_chance3,rain_chance4," - "rain_duration1,rain_duration2,rain_duration3,rain_duration4," - "snow_chance1,snow_chance2,snow_chance3,snow_chance4," - "snow_duration1,snow_duration2,snow_duration3,snow_duration4" - " from zone where zoneidnumber=%i and version=%i",zoneid, instance_id), errbuf, &result)) { - safe_delete_array(query); - row = mysql_fetch_row(result); - if(row) - { - int r = 0; - memset(zone_data,0,sizeof(NewZone_Struct)); - zone_data->ztype=atoi(row[r++]); - - for(i=0;i<4;i++){ - zone_data->fog_red[i]=atoi(row[r++]); - zone_data->fog_green[i]=atoi(row[r++]); - zone_data->fog_blue[i]=atoi(row[r++]); - zone_data->fog_minclip[i]=atof(row[r++]); - zone_data->fog_maxclip[i]=atof(row[r++]); - } - - zone_data->fog_density = atof(row[r++]);; - zone_data->sky=atoi(row[r++]); - zone_data->zone_exp_multiplier=atof(row[r++]); - zone_data->safe_x=atof(row[r++]); - zone_data->safe_y=atof(row[r++]); - zone_data->safe_z=atof(row[r++]); - zone_data->underworld=atof(row[r++]); - zone_data->minclip=atof(row[r++]); - zone_data->maxclip=atof(row[r++]); - - zone_data->time_type=atoi(row[r++]); -//not in the DB yet: - zone_data->gravity = 0.4; - - b = atoi(row[r++]); - can_bind = b==0?false:true; - is_city = b==2?true:false; - can_combat = atoi(row[r++])==0?false:true; - can_levitate = atoi(row[r++])==0?false:true; - can_castoutdoor = atoi(row[r++])==0?false:true; - is_hotzone = atoi(row[r++])==0?false:true; - allow_mercs = true; - zone_type = zone_data->ztype; - ruleset = atoi(row[r++]); - zone_data->SuspendBuffs = atoi(row[r++]); - char *file = row[r++]; - if(file) - { - strcpy(*map_filename, file); - } - else - { - strcpy(*map_filename, row[r++]); - } - for(i=0;i<4;i++){ - zone_data->rain_chance[i]=atoi(row[r++]); - } - for(i=0;i<4;i++){ - zone_data->rain_duration[i]=atoi(row[r++]); - } - for(i=0;i<4;i++){ - zone_data->snow_chance[i]=atoi(row[r++]); - } - for(i=0;i<4;i++){ - zone_data->snow_duration[i]=atof(row[r++]); - } - good = true; - } - mysql_free_result(result); - } - else - { - LogFile->write(EQEMuLog::Error, "Error in GetZoneCFG query %s: %s", query, errbuf); - strcpy(*map_filename, "default"); - } - safe_delete_array(query); - zone_data->zone_id = zoneid; - return(good); + std::string query = StringFormat("SELECT ztype, fog_red, fog_green, fog_blue, fog_minclip, fog_maxclip, " // 5 + "fog_red2, fog_green2, fog_blue2, fog_minclip2, fog_maxclip2, " // 5 + "fog_red3, fog_green3, fog_blue3, fog_minclip3, fog_maxclip3, " // 5 + "fog_red4, fog_green4, fog_blue4, fog_minclip4, fog_maxclip4, " // 5 + "fog_density, sky, zone_exp_multiplier, safe_x, safe_y, safe_z, underworld, " // 7 + "minclip, maxclip, time_type, canbind, cancombat, canlevitate, " // 6 + "castoutdoor, hotzone, ruleset, suspendbuffs, map_file_name, short_name, " // 6 + "rain_chance1, rain_chance2, rain_chance3, rain_chance4, " // 4 + "rain_duration1, rain_duration2, rain_duration3, rain_duration4, " // 4 + "snow_chance1, snow_chance2, snow_chance3, snow_chance4, " // 4 + "snow_duration1, snow_duration2, snow_duration3, snow_duration4 " // 4 + "FROM zone WHERE zoneidnumber = %i AND version = %i", zoneid, instance_id); + auto results = QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in GetZoneCFG query %s: %s", query.c_str(), results.ErrorMessage().c_str()); + strcpy(*map_filename, "default"); + return false; + } + + if (results.RowCount() == 0) { + strcpy(*map_filename, "default"); + return false; + } + + auto row = results.begin(); + + memset(zone_data, 0, sizeof(NewZone_Struct)); + zone_data->ztype = atoi(row[0]); + zone_type = zone_data->ztype; + + int index; + for(index = 0; index < 4; index++) { + zone_data->fog_red[index]=atoi(row[1 + index * 5]); + zone_data->fog_green[index]=atoi(row[2 + index * 5]); + zone_data->fog_blue[index]=atoi(row[3 + index * 5]); + zone_data->fog_minclip[index]=atof(row[4 + index * 5]); + zone_data->fog_maxclip[index]=atof(row[5 + index * 5]); + } + + zone_data->fog_density = atof(row[22]); + zone_data->sky=atoi(row[23]); + zone_data->zone_exp_multiplier=atof(row[24]); + zone_data->safe_x=atof(row[25]); + zone_data->safe_y=atof(row[26]); + zone_data->safe_z=atof(row[27]); + zone_data->underworld=atof(row[28]); + zone_data->minclip=atof(row[29]); + zone_data->maxclip=atof(row[30]); + zone_data->time_type=atoi(row[31]); + + //not in the DB yet: + zone_data->gravity = 0.4; + allow_mercs = true; + + int bindable = 0; + bindable = atoi(row[32]); + + can_bind = bindable == 0? false: true; + is_city = bindable == 2? true: false; + can_combat = atoi(row[33]) == 0? false: true; + can_levitate = atoi(row[34]) == 0? false: true; + can_castoutdoor = atoi(row[35]) == 0? false: true; + is_hotzone = atoi(row[36]) == 0? false: true; + + + ruleset = atoi(row[36]); + zone_data->SuspendBuffs = atoi(row[37]); + + char *file = row[38]; + if(file) + strcpy(*map_filename, file); + else + strcpy(*map_filename, row[39]); + + for(index = 0; index < 4; index++) + zone_data->rain_chance[index]=atoi(row[40 + index]); + + for(index = 0; index < 4; index++) + zone_data->rain_duration[index]=atoi(row[44 + index]); + + for(index = 0; index < 4; index++) + zone_data->snow_chance[index]=atoi(row[49 + index]); + + for(index = 0; index < 4; index++) + zone_data->snow_duration[index]=atof(row[53 + index]); + + return true; } //updates or clears the respawn time in the database for the current spawn id From bcdfd32bc07e011c50efff02ab51cd464930224b Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:21:07 -0700 Subject: [PATCH 03/67] UpdateSpawn2Timeleft converted to QueryDatabase --- zone/zonedb.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index cba20fdcc..ae3ecdfe6 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -193,29 +193,26 @@ void ZoneDatabase::UpdateSpawn2Timeleft(uint32 id, uint16 instance_id, uint32 ti gettimeofday(&tv, nullptr); uint32 cur = tv.tv_sec; - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - //if we pass timeleft as 0 that means we clear from respawn time //otherwise we update with a REPLACE INTO - if(timeleft == 0) - { - if (!RunQuery(query, MakeAnyLenString(&query, "DELETE FROM respawn_times WHERE id=%lu " - "AND instance_id=%lu",(unsigned long)id, (unsigned long)instance_id),errbuf)) - { - LogFile->write(EQEMuLog::Error, "Error in UpdateTimeLeft query %s: %s", query, errbuf); - } - safe_delete_array(query); - } - else - { - if (!RunQuery(query, MakeAnyLenString(&query, "REPLACE INTO respawn_times (id,start,duration,instance_id) " - "VALUES(%lu,%lu,%lu,%lu)",(unsigned long)id, (unsigned long)cur, (unsigned long)timeleft, (unsigned long)instance_id),errbuf)) - { - LogFile->write(EQEMuLog::Error, "Error in UpdateTimeLeft query %s: %s", query, errbuf); - } - safe_delete_array(query); + if(timeleft == 0) { + std::string query = StringFormat("DELETE FROM respawn_times WHERE id=%lu " + "AND instance_id = %lu",(unsigned long)id, (unsigned long)instance_id); + auto results = QueryDatabase(query); + if (!results.Success()) + LogFile->write(EQEMuLog::Error, "Error in UpdateTimeLeft query %s: %s", query.c_str(), results.ErrorMessage().c_str()); + + return; } + + std::string query = StringFormat("REPLACE INTO respawn_times (id, start, duration, instance_id) " + "VALUES (%lu, %lu, %lu, %lu)", + (unsigned long)id, (unsigned long)cur, + (unsigned long)timeleft, (unsigned long)instance_id); + auto results = QueryDatabase(query); + if (!results.Success()) + LogFile->write(EQEMuLog::Error, "Error in UpdateTimeLeft query %s: %s", query.c_str(), results.ErrorMessage().c_str()); + return; } From 4f9d4b00238b3bd8781a7b5a95724ba709f7410e Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:25:27 -0700 Subject: [PATCH 04/67] GetSpawnTimeLeft converted to QueryDatabase --- zone/zonedb.cpp | 72 +++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index ae3ecdfe6..63d6f83eb 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -219,52 +219,34 @@ void ZoneDatabase::UpdateSpawn2Timeleft(uint32 id, uint16 instance_id, uint32 ti //Gets the respawn time left in the database for the current spawn id uint32 ZoneDatabase::GetSpawnTimeLeft(uint32 id, uint16 instance_id) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - - MakeAnyLenString(&query, "SELECT start, duration FROM respawn_times WHERE id=%lu AND instance_id=%lu", - (unsigned long)id, (unsigned long)zone->GetInstanceID()); - - if (RunQuery(query, strlen(query), errbuf, &result)) - { - safe_delete_array(query); - row = mysql_fetch_row(result); - if(row) - { - timeval tv; - gettimeofday(&tv, nullptr); - uint32 resStart = atoi(row[0]); - uint32 resDuration = atoi(row[1]); - - //compare our values to current time - if((resStart + resDuration) <= tv.tv_sec) - { - //our current time was expired - mysql_free_result(result); - return 0; - } - else - { - //we still have time left on this timer - mysql_free_result(result); - return ((resStart + resDuration) - tv.tv_sec); - } - } - else - { - mysql_free_result(result); - return 0; - } - } - else - { - LogFile->write(EQEMuLog::Error, "Error in GetSpawnTimeLeft query '%s': %s", query, errbuf); - safe_delete_array(query); + std::string query = StringFormat("SELECT start, duration FROM respawn_times " + "WHERE id = %lu AND instance_id = %lu", + (unsigned long)id, (unsigned long)zone->GetInstanceID()); + auto results = QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in GetSpawnTimeLeft query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); return 0; - } - return 0; + } + + if (results.RowCount() != 1) + return 0; + + auto row = results.begin(); + + timeval tv; + gettimeofday(&tv, nullptr); + uint32 resStart = atoi(row[0]); + uint32 resDuration = atoi(row[1]); + + //compare our values to current time + if((resStart + resDuration) <= tv.tv_sec) { + //our current time was expired + return 0; + } + + //we still have time left on this timer + return ((resStart + resDuration) - tv.tv_sec); + } void ZoneDatabase::UpdateSpawn2Status(uint32 id, uint8 new_status) From 3479525f391ba4f8bb6d51fc8d8d48ba689b65f5 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:27:19 -0700 Subject: [PATCH 05/67] UpdateSpawn2Status converted to QueryDatabase --- zone/zonedb.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 63d6f83eb..bcf67b5f5 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -251,15 +251,11 @@ uint32 ZoneDatabase::GetSpawnTimeLeft(uint32 id, uint16 instance_id) void ZoneDatabase::UpdateSpawn2Status(uint32 id, uint8 new_status) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; + std::string query = StringFormat("UPDATE spawn2 SET enabled = %i WHERE id = %lu", new_status, (unsigned long)id); + auto results = QueryDatabase(query); + if(!results.Success()) + LogFile->write(EQEMuLog::Error, "Error in UpdateSpawn2Status query %s: %s", query.c_str(), results.ErrorMessage().c_str()); - if(!RunQuery(query, MakeAnyLenString(&query, "UPDATE spawn2 SET enabled=%i WHERE id=%lu", new_status, (unsigned long)id),errbuf)) - { - LogFile->write(EQEMuLog::Error, "Error in UpdateSpawn2Status query %s: %s", query, errbuf); - } - safe_delete_array(query); - return; } bool ZoneDatabase::logevents(const char* accountname,uint32 accountid,uint8 status,const char* charname, const char* target,const char* descriptiontype, const char* description,int event_nid){ From 96f122f9018beb78d08037f83e07dee16cc96416 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:31:16 -0700 Subject: [PATCH 06/67] logevents converted to QueryDatabase --- zone/zonedb.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index bcf67b5f5..2b15560b1 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -259,8 +259,7 @@ void ZoneDatabase::UpdateSpawn2Status(uint32 id, uint8 new_status) } bool ZoneDatabase::logevents(const char* accountname,uint32 accountid,uint8 status,const char* charname, const char* target,const char* descriptiontype, const char* description,int event_nid){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; + uint32 len = strlen(description); uint32 len2 = strlen(target); char* descriptiontext = new char[2*len+1]; @@ -269,14 +268,20 @@ bool ZoneDatabase::logevents(const char* accountname,uint32 accountid,uint8 stat memset(targetarr, 0, 2*len2+1); DoEscapeString(descriptiontext, description, len); DoEscapeString(targetarr, target, len2); - if (!RunQuery(query, MakeAnyLenString(&query, "Insert into eventlog (accountname,accountid,status,charname,target,descriptiontype,description,event_nid) values('%s',%i,%i,'%s','%s','%s','%s','%i')", accountname,accountid,status,charname,targetarr,descriptiontype,descriptiontext,event_nid), errbuf)) { - std::cerr << "Error in logevents" << query << "' " << errbuf << std::endl; - safe_delete_array(query); + + std::string query = StringFormat("INSERT INTO eventlog (accountname, accountid, status, " + "charname, target, descriptiontype, description, event_nid) " + "VALUES('%s', %i, %i, '%s', '%s', '%s', '%s', '%i')", + accountname, accountid, status, charname, targetarr, + descriptiontype, descriptiontext, event_nid); + safe_delete_array(descriptiontext); + safe_delete_array(targetarr); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in logevents" << query << "' " << results.ErrorMessage() << std::endl; return false; } - safe_delete_array(query); - safe_delete_array(descriptiontext); - safe_delete_array(targetarr); + return true; } From ce507d891a9d056e3f87356c3278bd8014e05095 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:39:25 -0700 Subject: [PATCH 07/67] UpdateBug converted to QueryDatabase --- zone/zonedb.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 2b15560b1..aa444e9db 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -286,10 +286,7 @@ bool ZoneDatabase::logevents(const char* accountname,uint32 accountid,uint8 stat } -void ZoneDatabase::UpdateBug(BugStruct* bug){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - +void ZoneDatabase::UpdateBug(BugStruct* bug) { uint32 len = strlen(bug->bug); char* bugtext = nullptr; @@ -319,16 +316,18 @@ void ZoneDatabase::UpdateBug(BugStruct* bug){ } //x and y are intentionally swapped because eq is inversexy coords - if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO bugs (zone, name, ui, x, y, z, type, flag, target, bug, date) " - "values('%s', '%s', '%s', '%.2f', '%.2f', '%.2f', '%s', %d, '%s', '%s', CURDATE())", zone->GetShortName(), bug->name, - uitext==nullptr?"":uitext, bug->y, bug->x, bug->z, bug->chartype, bug->type, targettext==nullptr?"Unknown Target":targettext, - bugtext==nullptr?"":bugtext), errbuf)) { - std::cerr << "Error in UpdateBug" << query << "' " << errbuf << std::endl; - } - safe_delete_array(query); - safe_delete_array(bugtext); + std::string query = StringFormat("INSERT INTO bugs (zone, name, ui, x, y, z, type, flag, target, bug, date) " + "VALUES('%s', '%s', '%s', '%.2f', '%.2f', '%.2f', '%s', %d, '%s', '%s', CURDATE())", + zone->GetShortName(), bug->name, uitext == nullptr ? "": uitext, + bug->x, bug->y, bug->z, bug->chartype, bug->type, targettext == nullptr? "Unknown Target": targettext, + bugtext==nullptr?"":bugtext); + safe_delete_array(bugtext); safe_delete_array(uitext); safe_delete_array(targettext); + auto results = QueryDatabase(query); + if (!results.Success()) + std::cerr << "Error in UpdateBug '" << query << "' " << results.ErrorMessage() << std::endl; + } void ZoneDatabase::UpdateBug(PetitionBug_Struct* bug){ From 09332f6c2678ad796fb647da23c6ce116fe01e84 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:42:13 -0700 Subject: [PATCH 08/67] UpdateBug converted to QueryDatabase --- zone/zonedb.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index aa444e9db..ec5f8b251 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -331,17 +331,20 @@ void ZoneDatabase::UpdateBug(BugStruct* bug) { } void ZoneDatabase::UpdateBug(PetitionBug_Struct* bug){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; + uint32 len = strlen(bug->text); char* bugtext = new char[2*len+1]; memset(bugtext, 0, 2*len+1); DoEscapeString(bugtext, bug->text, len); - if (!RunQuery(query, MakeAnyLenString(&query, "Insert into bugs (type,name,bugtext,flag) values('%s','%s','%s',%i)","Petition",bug->name,bugtext,25), errbuf)) { - std::cerr << "Error in UpdateBug" << query << "' " << errbuf << std::endl; - } - safe_delete_array(query); - safe_delete_array(bugtext); + + std::string query = StringFormat("INSERT INTO bugs (type, name, bugtext, flag) " + "VALUES('%s', '%s', '%s', %i)", + "Petition", bug->name, bugtext, 25); + safe_delete_array(bugtext); + auto results = QueryDatabase(query); + if (!results.Success()) + std::cerr << "Error in UpdateBug '" << query << "' " << results.ErrorMessage() << std::endl; + } From 046da9efae78fb6de2c4e05012c43ad0a9cb532b Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:46:12 -0700 Subject: [PATCH 09/67] SetSpecialAttkFlag converted to QueryDatabase --- zone/zonedb.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index ec5f8b251..8ac38b712 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -383,21 +383,13 @@ bool ZoneDatabase::GetAccountInfoForLogin_result(MYSQL_RES* result, int16* admin bool ZoneDatabase::SetSpecialAttkFlag(uint8 id, const char* flag) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - uint32 affected_rows = 0; - if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE npc_types SET npcspecialattks='%s' WHERE id=%i;",flag,id), errbuf, 0, &affected_rows)) { - safe_delete_array(query); + std::string query = StringFormat("UPDATE npc_types SET npcspecialattks='%s' WHERE id = %i;", flag, id); + auto results = QueryDatabase(query); + if (!results.Success()) return false; - } - safe_delete_array(query); - if (affected_rows == 0) { - return false; - } - - return true; + return results.RowsAffected() != 0; } bool ZoneDatabase::DoorIsOpen(uint8 door_id,const char* zone_name) From e60658c684f8c3af3f126f1ddaeba13addfa28e2 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:51:52 -0700 Subject: [PATCH 10/67] GetEventLogs converted to QueryDatabase --- zone/zonedb.cpp | 64 +++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 8ac38b712..892cafcc6 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -411,12 +411,6 @@ void ZoneDatabase::SetDoorPlace(uint8 value,uint8 door_id,const char* zone_name) void ZoneDatabase::GetEventLogs(const char* name,char* target,uint32 account_id,uint8 eventid,char* detail,char* timestamp, CharacterEventLog_Struct* cel) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - query = new char[256]; - uint32 count = 0; char modifications[200]; if(strlen(name) != 0) sprintf(modifications,"charname=\'%s\'",name); @@ -424,46 +418,42 @@ void ZoneDatabase::GetEventLogs(const char* name,char* target,uint32 account_id, sprintf(modifications,"accountid=%i",account_id); if(strlen(target) != 0) - sprintf(modifications,"%s AND target like \'%%%s%%\'",modifications,target); + sprintf(modifications,"%s AND target LIKE \'%%%s%%\'",modifications,target); if(strlen(detail) != 0) - sprintf(modifications,"%s AND description like \'%%%s%%\'",modifications,detail); + sprintf(modifications,"%s AND description LIKE \'%%%s%%\'",modifications,detail); if(strlen(timestamp) != 0) - sprintf(modifications,"%s AND time like \'%%%s%%\'",modifications,timestamp); + sprintf(modifications,"%s AND time LIKE \'%%%s%%\'",modifications,timestamp); if(eventid == 0) eventid =1; sprintf(modifications,"%s AND event_nid=%i",modifications,eventid); - MakeAnyLenString(&query, "SELECT id,accountname,accountid,status,charname,target,time,descriptiontype,description FROM eventlog where %s",modifications); - if (RunQuery(query, strlen(query), errbuf, &result)) - { - safe_delete_array(query); - while((row = mysql_fetch_row(result))) - { - if(count > 255) - break; - cel->eld[count].id = atoi(row[0]); - strn0cpy(cel->eld[count].accountname,row[1],64); - cel->eld[count].account_id = atoi(row[2]); - cel->eld[count].status = atoi(row[3]); - strn0cpy(cel->eld[count].charactername,row[4],64); - strn0cpy(cel->eld[count].targetname,row[5],64); - sprintf(cel->eld[count].timestamp,"%s",row[6]); - strn0cpy(cel->eld[count].descriptiontype,row[7],64); - strn0cpy(cel->eld[count].details,row[8],128); - cel->eventid = eventid; - count++; - cel->count = count; - } - mysql_free_result(result); - } - else - { - // TODO: Invalid item length in database - safe_delete_array(query); - } + std::string query = StringFormat("SELECT id, accountname, accountid, status, charname, target, " + "time, descriptiontype, description FROM eventlog WHERE %s", modifications); + auto results = QueryDatabase(query); + if (!results.Success()) + return; + + int index = 0; + for (auto row = results.begin(); row != results.end(); ++row, ++index) { + if(index == 255) + break; + + cel->eld[index].id = atoi(row[0]); + strn0cpy(cel->eld[index].accountname,row[1],64); + cel->eld[index].account_id = atoi(row[2]); + cel->eld[index].status = atoi(row[3]); + strn0cpy(cel->eld[index].charactername,row[4],64); + strn0cpy(cel->eld[index].targetname,row[5],64); + sprintf(cel->eld[index].timestamp,"%s",row[6]); + strn0cpy(cel->eld[index].descriptiontype,row[7],64); + strn0cpy(cel->eld[index].details,row[8],128); + cel->eventid = eventid; + cel->count = index + 1; + } + } // Load child objects for a world container (i.e., forge, bag dropped to ground, etc) From 3777e8d1ce9922d53b9e93e017583ab392e78442 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 17:57:44 -0700 Subject: [PATCH 11/67] LoadWorldContainer converted to QueryDatabase --- zone/zonedb.cpp | 67 ++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 892cafcc6..e428c0fb9 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -464,49 +464,36 @@ void ZoneDatabase::LoadWorldContainer(uint32 parentid, ItemInst* container) return; } - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - //const Item_Struct* item = nullptr; - //ItemInst* inst = nullptr; + std::string query = StringFormat("SELECT bagidx, itemid, charges, augslot1, augslot2, augslot3, augslot4, augslot5 " + "FROM object_contents WHERE parentid = %i", parentid); + auto results = QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in DB::LoadWorldContainer: %s", results.ErrorMessage().c_str()); + return; + } - uint32 len_query = MakeAnyLenString(&query, "select " - "bagidx,itemid,charges,augslot1,augslot2,augslot3,augslot4,augslot5 from object_contents where parentid=%i", parentid); + for (auto row = results.begin(); row != results.end(); ++row) { + uint8 index = (uint8)atoi(row[0]); + uint32 item_id = (uint32)atoi(row[1]); + int8 charges = (int8)atoi(row[2]); + uint32 aug[EmuConstants::ITEM_COMMON_SIZE]; + aug[0] = (uint32)atoi(row[3]); + aug[1] = (uint32)atoi(row[4]); + aug[2] = (uint32)atoi(row[5]); + aug[3] = (uint32)atoi(row[6]); + aug[4] = (uint32)atoi(row[7]); - if (RunQuery(query, len_query, errbuf, &result)) { - while ((row = mysql_fetch_row(result))) { - uint8 index = (uint8)atoi(row[0]); - uint32 item_id = (uint32)atoi(row[1]); - int8 charges = (int8)atoi(row[2]); - uint32 aug[EmuConstants::ITEM_COMMON_SIZE]; - aug[0] = (uint32)atoi(row[3]); - aug[1] = (uint32)atoi(row[4]); - aug[2] = (uint32)atoi(row[5]); - aug[3] = (uint32)atoi(row[6]); - aug[4] = (uint32)atoi(row[7]); + ItemInst* inst = database.CreateItem(item_id, charges); + if (inst && inst->GetItem()->ItemClass == ItemClassCommon) { + for(int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) + if (aug[i]) + inst->PutAugment(&database, i, aug[i]); + // Put item inside world container + container->PutItem(index, *inst); + safe_delete(inst); + } + } - ItemInst* inst = database.CreateItem(item_id, charges); - if (inst) { - if (inst->GetItem()->ItemClass == ItemClassCommon) { - for(int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) { - if (aug[i]) { - inst->PutAugment(&database, i, aug[i]); - } - } - } - // Put item inside world container - container->PutItem(index, *inst); - safe_delete(inst); - } - } - mysql_free_result(result); - } - else { - LogFile->write(EQEMuLog::Error, "Error in DB::LoadWorldContainer: %s", errbuf); - } - - safe_delete_array(query); } // Save child objects for a world container (i.e., forge, bag dropped to ground, etc) From c666d9c553146d2706979b5a8e1770659020033b Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:03:02 -0700 Subject: [PATCH 12/67] SaveWorldContainer converted to QueryDatabase --- zone/zonedb.cpp | 51 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index e428c0fb9..ac2bb1705 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -499,42 +499,43 @@ void ZoneDatabase::LoadWorldContainer(uint32 parentid, ItemInst* container) // Save child objects for a world container (i.e., forge, bag dropped to ground, etc) void ZoneDatabase::SaveWorldContainer(uint32 zone_id, uint32 parent_id, const ItemInst* container) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - // Since state is not saved for each world container action, we'll just delete // all and save from scratch .. we may come back later to optimize - //DeleteWorldContainer(parent_id); - - if (!container) { + if (!container) return; - } + //Delete all items from container DeleteWorldContainer(parent_id,zone_id); + // Save all 10 items, if they exist for (uint8 index = SUB_BEGIN; index < EmuConstants::ITEM_CONTAINER_SIZE; index++) { + ItemInst* inst = container->GetItem(index); - if (inst) { - uint32 item_id = inst->GetItem()->ID; - uint32 augslot[EmuConstants::ITEM_COMMON_SIZE] = { NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM }; - if (inst->IsType(ItemClassCommon)) { - for(int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) { - ItemInst *auginst=inst->GetAugment(i); - augslot[i]=(auginst && auginst->GetItem()) ? auginst->GetItem()->ID : 0; - } - } - uint32 len_query = MakeAnyLenString(&query, + if (!inst) + continue; - "replace into object_contents (zoneid,parentid,bagidx,itemid,charges,augslot1,augslot2,augslot3,augslot4,augslot5,droptime) values (%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,now())", - zone_id, parent_id, index, item_id, inst->GetCharges(),augslot[0],augslot[1],augslot[2],augslot[3],augslot[4]); + uint32 item_id = inst->GetItem()->ID; + uint32 augslot[EmuConstants::ITEM_COMMON_SIZE] = { NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM }; - if (!RunQuery(query, len_query, errbuf)) { - LogFile->write(EQEMuLog::Error, "Error in ZoneDatabase::SaveWorldContainer: %s", errbuf); - } - safe_delete_array(query); - } + if (inst->IsType(ItemClassCommon)) { + for(int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) { + ItemInst *auginst=inst->GetAugment(i); + augslot[i]=(auginst && auginst->GetItem()) ? auginst->GetItem()->ID : 0; + } + } + + std::string query = StringFormat("REPLACE INTO object_contents " + "(zoneid, parentid, bagidx, itemid, charges, " + "augslot1, augslot2, augslot3, augslot4, augslot5, droptime) " + "VALUES (%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, now())", + zone_id, parent_id, index, item_id, inst->GetCharges(), + augslot[0], augslot[1], augslot[2], augslot[3], augslot[4]); + auto results = QueryDatabase(query); + if (!results.Success()) + LogFile->write(EQEMuLog::Error, "Error in ZoneDatabase::SaveWorldContainer: %s", results.ErrorMessage().c_str()); + + } - } } // Remove all child objects inside a world container (i.e., forge, bag dropped to ground, etc) From 09713311f6172872c37c79d8610c2d42789069e9 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:06:03 -0700 Subject: [PATCH 13/67] DeleteWorldContainer converted to QueryDatabase --- zone/zonedb.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index ac2bb1705..0c62c273b 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -539,18 +539,13 @@ void ZoneDatabase::SaveWorldContainer(uint32 zone_id, uint32 parent_id, const It } // Remove all child objects inside a world container (i.e., forge, bag dropped to ground, etc) -void ZoneDatabase::DeleteWorldContainer(uint32 parent_id,uint32 zone_id) +void ZoneDatabase::DeleteWorldContainer(uint32 parent_id, uint32 zone_id) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; + std::string query = StringFormat("DELETE FROM object_contents WHERE parentid = %i AND zoneid = %i", parent_id, zone_id); + auto results = QueryDatabase(query); + if (!results.Success()) + LogFile->write(EQEMuLog::Error, "Error in ZoneDatabase::DeleteWorldContainer: %s", results.ErrorMessage().c_str()); - uint32 len_query = MakeAnyLenString(&query, - "delete from object_contents where parentid=%i and zoneid=%i", parent_id,zone_id); - if (!RunQuery(query, len_query, errbuf)) { - LogFile->write(EQEMuLog::Error, "Error in ZoneDatabase::DeleteWorldContainer: %s", errbuf); - } - - safe_delete_array(query); } Trader_Struct* ZoneDatabase::LoadTraderItem(uint32 char_id){ From e9c6e96452a513df29542c98cf05c287bd7660d6 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:16:05 -0700 Subject: [PATCH 14/67] LoadTraderItem converted to QueryDatabase --- zone/zonedb.cpp | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 0c62c273b..47d03e851 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -549,30 +549,27 @@ void ZoneDatabase::DeleteWorldContainer(uint32 parent_id, uint32 zone_id) } Trader_Struct* ZoneDatabase::LoadTraderItem(uint32 char_id){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result; - MYSQL_ROW row; + Trader_Struct* loadti = new Trader_Struct; memset(loadti,0,sizeof(Trader_Struct)); - if (RunQuery(query,MakeAnyLenString(&query, "select * from trader where char_id=%i order by slot_id limit 80",char_id),errbuf,&result)){ - safe_delete_array(query); - loadti->Code = BazaarTrader_ShowItems; - while ((row = mysql_fetch_row(result))) { - if(atoi(row[5])>=80 || atoi(row[4])<0) - _log(TRADING__CLIENT, "Bad Slot number when trying to load trader information!\n"); - else{ - loadti->Items[atoi(row[5])] = atoi(row[1]); - loadti->ItemCost[atoi(row[5])] = atoi(row[4]); - } - } - mysql_free_result(result); + + std::string query = StringFormat("SELECT * FROM trader WHERE char_id = %i ORDER BY slot_id LIMIT 80", char_id); + auto results = QueryDatabase(query); + if (!results.Success()) { + _log(TRADING__CLIENT, "Failed to load trader information!\n"); + return loadti; } - else{ - safe_delete_array(query); - _log(TRADING__CLIENT, "Failed to load trader information!\n"); - } - return loadti; + + loadti->Code = BazaarTrader_ShowItems; + for (auto row = results.begin(); row != results.end(); ++row) { + if(atoi(row[5])>=80 || atoi(row[4])<0) { + _log(TRADING__CLIENT, "Bad Slot number when trying to load trader information!\n"); + continue; + } + + loadti->Items[atoi(row[5])] = atoi(row[1]); + loadti->ItemCost[atoi(row[5])] = atoi(row[4]); + } } TraderCharges_Struct* ZoneDatabase::LoadTraderItemWithCharges(uint32 char_id){ From 0f47b73a64f2b0e9f160ae34e6c62560ab12ea8c Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:21:50 -0700 Subject: [PATCH 15/67] LoadTraderItemWithCharges converted to QueryDatabase --- zone/zonedb.cpp | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 47d03e851..3a34c40ae 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -573,30 +573,29 @@ Trader_Struct* ZoneDatabase::LoadTraderItem(uint32 char_id){ } TraderCharges_Struct* ZoneDatabase::LoadTraderItemWithCharges(uint32 char_id){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result; - MYSQL_ROW row; + TraderCharges_Struct* loadti = new TraderCharges_Struct; memset(loadti,0,sizeof(TraderCharges_Struct)); - if (RunQuery(query,MakeAnyLenString(&query, "select * from trader where char_id=%i order by slot_id limit 80",char_id),errbuf,&result)){ - safe_delete_array(query); - while ((row = mysql_fetch_row(result))) { - if(atoi(row[5])>=80 || atoi(row[5])<0) - _log(TRADING__CLIENT, "Bad Slot number when trying to load trader information!\n"); - else{ - loadti->ItemID[atoi(row[5])] = atoi(row[1]); - loadti->SerialNumber[atoi(row[5])] = atoi(row[2]); - loadti->Charges[atoi(row[5])] = atoi(row[3]); - loadti->ItemCost[atoi(row[5])] = atoi(row[4]); - } - } - mysql_free_result(result); - } - else{ - safe_delete_array(query); - _log(TRADING__CLIENT, "Failed to load trader information!\n"); - } + + std::string query = StringFormat("SELECT * FROM trader WHERE char_id=%i ORDER BY slot_id LIMIT 80", char_id); + auto results = QueryDatabase(query); + if (!results.Success()) { + _log(TRADING__CLIENT, "Failed to load trader information!\n"); + return loadti; + } + + for (auto row = results.begin(); row != results.end(); ++row) { + if(atoi(row[5])>=80 || atoi(row[5])<0) { + _log(TRADING__CLIENT, "Bad Slot number when trying to load trader information!\n"); + continue; + } + + loadti->ItemID[atoi(row[5])] = atoi(row[1]); + loadti->SerialNumber[atoi(row[5])] = atoi(row[2]); + loadti->Charges[atoi(row[5])] = atoi(row[3]); + loadti->ItemCost[atoi(row[5])] = atoi(row[4]); + } + return loadti; } From bc884f5daf7680b201b690fea7a9be399c95e769 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:35:54 -0700 Subject: [PATCH 16/67] LoadSingleTraderItem converted to QueryDatabase --- zone/zonedb.cpp | 72 ++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 3a34c40ae..5b014d188 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -601,52 +601,50 @@ TraderCharges_Struct* ZoneDatabase::LoadTraderItemWithCharges(uint32 char_id){ ItemInst* ZoneDatabase::LoadSingleTraderItem(uint32 CharID, int SerialNumber) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result; - MYSQL_ROW row; + std::string query = StringFormat("SELECT * FROM trader WHERE char_id = %i AND serialnumber = %i " + "ORDER BY slot_id LIMIT 80", CharID, SerialNumber); + auto results = QueryDatabase(query); + if (!results.Success()) + return nullptr; - if (RunQuery(query,MakeAnyLenString(&query, "select * from trader where char_id=%i and serialnumber=%i order by slot_id limit 80", - CharID, SerialNumber),errbuf,&result)){ - safe_delete_array(query); + if (results.RowCount() == 0) { + _log(TRADING__CLIENT, "Bad result from query\n"); fflush(stdout); + return nullptr; + } - if (mysql_num_rows(result) != 1) { - _log(TRADING__CLIENT, "Bad result from query\n"); fflush(stdout); - return nullptr; - } - row = mysql_fetch_row(result); - int ItemID = atoi(row[1]); - int Charges = atoi(row[3]); - int Cost = atoi(row[4]); + auto row = results.begin(); - const Item_Struct *item=database.GetItem(ItemID); + int ItemID = atoi(row[1]); + int Charges = atoi(row[3]); + int Cost = atoi(row[4]); - if(!item) { - _log(TRADING__CLIENT, "Unable to create item\n"); fflush(stdout); - return nullptr; - } + const Item_Struct *item = database.GetItem(ItemID); - if (item && (item->NoDrop!=0)) { - ItemInst* inst = database.CreateItem(item); - if(!inst) { - _log(TRADING__CLIENT, "Unable to create item instance\n"); fflush(stdout); - return nullptr; - } - - inst->SetCharges(Charges); - inst->SetSerialNumber(SerialNumber); - inst->SetMerchantSlot(SerialNumber); - inst->SetPrice(Cost); - if(inst->IsStackable()) - inst->SetMerchantCount(Charges); - - return inst; - } + if(!item) { + _log(TRADING__CLIENT, "Unable to create item\n"); + fflush(stdout); + return nullptr; } - return nullptr; + if (item->NoDrop == 0) + return nullptr; + ItemInst* inst = database.CreateItem(item); + if(!inst) { + _log(TRADING__CLIENT, "Unable to create item instance\n"); + fflush(stdout); + return nullptr; + } + inst->SetCharges(Charges); + inst->SetSerialNumber(SerialNumber); + inst->SetMerchantSlot(SerialNumber); + inst->SetPrice(Cost); + + if(inst->IsStackable()) + inst->SetMerchantCount(Charges); + + return inst; } void ZoneDatabase::SaveTraderItem(uint32 CharID, uint32 ItemID, uint32 SerialNumber, int32 Charges, uint32 ItemCost, uint8 Slot){ From efd97bad1476aa4485e08b6472a84b66d057cb22 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:38:57 -0700 Subject: [PATCH 17/67] SaveTraderItem converted to QueryDatabase --- zone/zonedb.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 5b014d188..1bd17ee35 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -649,13 +649,12 @@ ItemInst* ZoneDatabase::LoadSingleTraderItem(uint32 CharID, int SerialNumber) { void ZoneDatabase::SaveTraderItem(uint32 CharID, uint32 ItemID, uint32 SerialNumber, int32 Charges, uint32 ItemCost, uint8 Slot){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - if (!(RunQuery(query,MakeAnyLenString(&query, "replace INTO trader VALUES(%i,%i,%i,%i,%i,%i)", - CharID, ItemID, SerialNumber, Charges, ItemCost, Slot),errbuf))) - _log(TRADING__CLIENT, "Failed to save trader item: %i for char_id: %i, the error was: %s\n", ItemID, CharID, errbuf); + std::string query = StringFormat("REPLACE INTO trader VALUES(%i, %i, %i, %i, %i, %i)", + CharID, ItemID, SerialNumber, Charges, ItemCost, Slot); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to save trader item: %i for char_id: %i, the error was: %s\n", ItemID, CharID, results.ErrorMessage().c_str()); - safe_delete_array(query); } void ZoneDatabase::UpdateTraderItemCharges(int CharID, uint32 SerialNumber, int32 Charges) { From d44d7c6bbde1b64e7e6d6ae4fa22eaf6970124d7 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:42:25 -0700 Subject: [PATCH 18/67] UpdateTraderItemCharges converted to QueryDatabase --- zone/zonedb.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 1bd17ee35..3e8eb5b1f 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -660,14 +660,13 @@ void ZoneDatabase::SaveTraderItem(uint32 CharID, uint32 ItemID, uint32 SerialNum void ZoneDatabase::UpdateTraderItemCharges(int CharID, uint32 SerialNumber, int32 Charges) { _log(TRADING__CLIENT, "ZoneDatabase::UpdateTraderItemCharges(%i, %i, %i)", CharID, SerialNumber, Charges); - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - if (!(RunQuery(query,MakeAnyLenString(&query, "update trader set charges=%i where char_id=%i and serialnumber=%i", - Charges, CharID, SerialNumber),errbuf))) - _log(TRADING__CLIENT, "Failed to update charges for trader item: %i for char_id: %i, the error was: %s\n", - SerialNumber, CharID, errbuf); - safe_delete_array(query); + std::string query = StringFormat("UPDATE trader SET charges = %i WHERE char_id = %i AND serialnumber = %i", + Charges, CharID, SerialNumber); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to update charges for trader item: %i for char_id: %i, the error was: %s\n", + SerialNumber, CharID, results.ErrorMessage().c_str()); } From 62ad60b4ad76ab20a5d830c4827cb0f331e62a48 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:50:10 -0700 Subject: [PATCH 19/67] UpdateTraderItemPrice converted to QueryDatabase --- zone/zonedb.cpp | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 3e8eb5b1f..dbed63f9c 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -679,42 +679,34 @@ void ZoneDatabase::UpdateTraderItemPrice(int CharID, uint32 ItemID, uint32 Charg if(!item) return; - char errbuf[MYSQL_ERRMSG_SIZE]; - - char* Query = 0; - if(NewPrice == 0) { _log(TRADING__CLIENT, "Removing Trader items from the DB for CharID %i, ItemID %i", CharID, ItemID); - if (!(RunQuery(Query,MakeAnyLenString(&Query, "delete from trader where char_id=%i and item_id=%i", - CharID, ItemID),errbuf))) - - _log(TRADING__CLIENT, "Failed to remove trader item(s): %i for char_id: %i, the error was: %s\n", - ItemID, CharID, errbuf); - - safe_delete_array(Query); + std::string query = StringFormat("DELETE FROM trader WHERE char_id = %i AND item_id = %i",CharID, ItemID); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to remove trader item(s): %i for char_id: %i, the error was: %s\n", ItemID, CharID, results.ErrorMessage().c_str()); return; } - else { - if(!item->Stackable) { - if (!(RunQuery(Query,MakeAnyLenString(&Query, "update trader set item_cost=%i where char_id=%i and item_id=%i" - " and charges=%i", NewPrice, CharID, ItemID, Charges),errbuf))) - _log(TRADING__CLIENT, "Failed to update price for trader item: %i for char_id: %i, the error was: %s\n", - ItemID, CharID, errbuf); - } - else { - if (!(RunQuery(Query,MakeAnyLenString(&Query, "update trader set item_cost=%i where char_id=%i and item_id=%i", - NewPrice, CharID, ItemID),errbuf))) + if(!item->Stackable) { + std::string query = StringFormat("UPDATE trader SET item_cost = %i " + "WHERE char_id = %i AND item_id = %i AND charges=%i", + NewPrice, CharID, ItemID, Charges); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to update price for trader item: %i for char_id: %i, the error was: %s\n", ItemID, CharID, results.ErrorMessage().c_str()); - _log(TRADING__CLIENT, "Failed to update price for trader item: %i for char_id: %i, the error was: %s\n", - ItemID, CharID, errbuf); - } - - safe_delete_array(Query); - } + return; + } + std::string query = StringFormat("UPDATE trader SET item_cost = %i " + "WHERE char_id = %i AND item_id = %i", + NewPrice, CharID, ItemID); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to update price for trader item: %i for char_id: %i, the error was: %s\n", ItemID, CharID, results.ErrorMessage().c_str()); } void ZoneDatabase::DeleteTraderItem(uint32 char_id){ From c160d6d929cd181d16c593c2aa02276dbdfc1934 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:53:05 -0700 Subject: [PATCH 20/67] DeleteTraderItem converted to QueryDatabase --- zone/zonedb.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index dbed63f9c..187af5e09 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -710,17 +710,21 @@ void ZoneDatabase::UpdateTraderItemPrice(int CharID, uint32 ItemID, uint32 Charg } void ZoneDatabase::DeleteTraderItem(uint32 char_id){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - if(char_id==0){ - if (!(RunQuery(query,MakeAnyLenString(&query, "delete from trader"),errbuf))) - _log(TRADING__CLIENT, "Failed to delete all trader items data, the error was: %s\n",errbuf); + + if(char_id==0) { + const std::string query = "DELETE FROM trader"; + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to delete all trader items data, the error was: %s\n", results.ErrorMessage().c_str()); + + return; } - else{ - if (!(RunQuery(query,MakeAnyLenString(&query, "delete from trader where char_id=%i",char_id),errbuf))) - _log(TRADING__CLIENT, "Failed to delete trader item data for char_id: %i, the error was: %s\n",char_id,errbuf); - } - safe_delete_array(query); + + std::string query = StringFormat("DELETE FROM trader WHERE char_id = %i", char_id); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to delete trader item data for char_id: %i, the error was: %s\n", char_id, results.ErrorMessage().c_str()); + } void ZoneDatabase::DeleteTraderItem(uint32 CharID,uint16 SlotID){ char errbuf[MYSQL_ERRMSG_SIZE]; From d234016224f83f8705ae5468aa52a2b1544485fd Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:55:42 -0700 Subject: [PATCH 21/67] DeleteTraderItem converted to QueryDatabase --- zone/zonedb.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 187af5e09..5521a7255 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -726,12 +726,12 @@ void ZoneDatabase::DeleteTraderItem(uint32 char_id){ _log(TRADING__CLIENT, "Failed to delete trader item data for char_id: %i, the error was: %s\n", char_id, results.ErrorMessage().c_str()); } -void ZoneDatabase::DeleteTraderItem(uint32 CharID,uint16 SlotID){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - if (!(RunQuery(query,MakeAnyLenString(&query, "delete from trader where char_id=%i and slot_id=%i",CharID, SlotID),errbuf))) - _log(TRADING__CLIENT, "Failed to delete trader item data for char_id: %i, the error was: %s\n",CharID, errbuf); - safe_delete_array(query); +void ZoneDatabase::DeleteTraderItem(uint32 CharID,uint16 SlotID) { + + std::string query = StringFormat("DELETE FROM trader WHERE char_id = %i And slot_id = %i", CharID, SlotID); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to delete trader item data for char_id: %i, the error was: %s\n",CharID, results.ErrorMessage().c_str()); } void ZoneDatabase::DeleteBuyLines(uint32 CharID){ From e19a59b2691317440af29cb3954e72726005c329 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 18:59:17 -0700 Subject: [PATCH 22/67] DeleteBuyLines converted to QueryDatabase --- zone/zonedb.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 5521a7255..c1240810f 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -734,19 +734,22 @@ void ZoneDatabase::DeleteTraderItem(uint32 CharID,uint16 SlotID) { _log(TRADING__CLIENT, "Failed to delete trader item data for char_id: %i, the error was: %s\n",CharID, results.ErrorMessage().c_str()); } -void ZoneDatabase::DeleteBuyLines(uint32 CharID){ +void ZoneDatabase::DeleteBuyLines(uint32 CharID) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - if(CharID==0){ - if (!(RunQuery(query,MakeAnyLenString(&query, "delete from buyer"),errbuf))) - _log(TRADING__CLIENT, "Failed to delete all buyer items data, the error was: %s\n",errbuf); + if(CharID==0) { + const std::string query = "DELETE FROM buyer"; + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to delete all buyer items data, the error was: %s\n",results.ErrorMessage().c_str()); + + return; } - else{ - if (!(RunQuery(query,MakeAnyLenString(&query, "delete from buyer where charid=%i",CharID),errbuf))) - _log(TRADING__CLIENT, "Failed to delete buyer item data for charid: %i, the error was: %s\n",CharID,errbuf); - } - safe_delete_array(query); + + std::string query = StringFormat("DELETE FROM buyer WHERE charid = %i", CharID); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to delete buyer item data for charid: %i, the error was: %s\n",CharID,results.ErrorMessage().c_str()); + } void ZoneDatabase::AddBuyLine(uint32 CharID, uint32 BuySlot, uint32 ItemID, const char* ItemName, uint32 Quantity, uint32 Price) { From 9ed69999a5e5af2d8bd7d89a7fcc345803846446 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 19:02:28 -0700 Subject: [PATCH 23/67] AddBuyLine converted to QueryDatabase --- zone/zonedb.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index c1240810f..30b3db079 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -754,13 +754,12 @@ void ZoneDatabase::DeleteBuyLines(uint32 CharID) { void ZoneDatabase::AddBuyLine(uint32 CharID, uint32 BuySlot, uint32 ItemID, const char* ItemName, uint32 Quantity, uint32 Price) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - if (!(RunQuery(query,MakeAnyLenString(&query, "replace INTO buyer VALUES(%i,%i, %i,\"%s\",%i,%i)", - CharID, BuySlot, ItemID, ItemName, Quantity, Price),errbuf))) - _log(TRADING__CLIENT, "Failed to save buline item: %i for char_id: %i, the error was: %s\n", ItemID, CharID, errbuf); + std::string query = StringFormat("REPLACE INTO buyer VALUES(%i, %i, %i, \"%s\", %i, %i)", + CharID, BuySlot, ItemID, ItemName, Quantity, Price); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to save buline item: %i for char_id: %i, the error was: %s\n", ItemID, CharID, results.ErrorMessage().c_str()); - safe_delete_array(query); } void ZoneDatabase::RemoveBuyLine(uint32 CharID, uint32 BuySlot) { From a7efa9d4e43cc97d04bfdd21bb263e6caf59cbcc Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 19:20:32 -0700 Subject: [PATCH 24/67] RemoveBuyLine converted to QueryDatabase --- zone/zonedb.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 30b3db079..726ad4b16 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -764,13 +764,11 @@ void ZoneDatabase::AddBuyLine(uint32 CharID, uint32 BuySlot, uint32 ItemID, cons void ZoneDatabase::RemoveBuyLine(uint32 CharID, uint32 BuySlot) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; + std::string query = StringFormat("DELETE FROM buyer WHERE charid = %i AND buyslot = %i", CharID, BuySlot); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to delete buyslot %i for charid: %i, the error was: %s\n", BuySlot, CharID, results.ErrorMessage().c_str()); - if (!(RunQuery(query,MakeAnyLenString(&query, "delete from buyer where charid=%i and buyslot=%i", CharID, BuySlot), errbuf))) - _log(TRADING__CLIENT, "Failed to delete buyslot %i for charid: %i, the error was: %s\n", BuySlot, CharID, errbuf); - - safe_delete_array(query); } void ZoneDatabase::UpdateBuyLine(uint32 CharID, uint32 BuySlot, uint32 Quantity) { From 41769a3fa8a4598591e0bc3dc00cfc82f3529eac Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 19:28:53 -0700 Subject: [PATCH 25/67] UpdateBuyLine converted to QueryDatabase --- zone/zonedb.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 726ad4b16..cf60969ea 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -778,14 +778,10 @@ void ZoneDatabase::UpdateBuyLine(uint32 CharID, uint32 BuySlot, uint32 Quantity) return; } - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - - if (!(RunQuery(query,MakeAnyLenString(&query, "update buyer set quantity=%i where charid=%i and buyslot=%i", - Quantity, CharID, BuySlot), errbuf))) - _log(TRADING__CLIENT, "Failed to update quantity in buyslot %i for charid: %i, the error was: %s\n", BuySlot, CharID, errbuf); - - safe_delete_array(query); + std::string query = StringFormat("UPDATE buyer SET quantity = %i WHERE charid = %i AND buyslot = %i", Quantity, CharID, BuySlot); + auto results = QueryDatabase(query); + if (!results.Success()) + _log(TRADING__CLIENT, "Failed to update quantity in buyslot %i for charid: %i, the error was: %s\n", BuySlot, CharID, results.ErrorMessage().c_str()); } From 74d3192c2e8c9b8023a3fd7612c687be16be1fc5 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 19:46:23 -0700 Subject: [PATCH 26/67] NoRentExpired converted to QueryDatabase --- zone/zonedb.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index cf60969ea..f51074396 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -918,20 +918,19 @@ bool ZoneDatabase::GetCharacterInfoForLogin_result(MYSQL_RES* result, } bool ZoneDatabase::NoRentExpired(const char* name){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - if (RunQuery(query, MakeAnyLenString(&query, "Select (UNIX_TIMESTAMP(NOW())-timelaston) from character_ where name='%s'", name), errbuf, &result)) { - safe_delete_array(query); - if (mysql_num_rows(result) == 1) { - row = mysql_fetch_row(result); - uint32 seconds = atoi(row[0]); - mysql_free_result(result); - return (seconds>1800); - } - } - return false; + std::string query = StringFormat("SELECT (UNIX_TIMESTAMP(NOW())-timelaston) " + "FROM character_ WHERE name = '%s'", name); + auto results = QueryDatabase(query); + if (!results.Success()) + return false; + + if (results.RowCount() != 1) + return false; + + auto row = results.begin(); + uint32 seconds = atoi(row[0]); + + return (seconds>1800); } /* Searches npctable for matching id, and returns the item if found, From 9769a96ebdbc4ced444cc4227f35dfeb1753d83d Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 20:21:39 -0700 Subject: [PATCH 27/67] GetNPCType converted to QueryDatabase --- zone/zonedb.cpp | 469 +++++++++++++++++++----------------------------- 1 file changed, 180 insertions(+), 289 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index f51074396..837878720 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -939,320 +939,211 @@ bool ZoneDatabase::NoRentExpired(const char* name){ */ const NPCType* ZoneDatabase::GetNPCType (uint32 id) { const NPCType *npc=nullptr; - std::map::iterator itr; // If NPC is already in tree, return it. - if((itr = zone->npctable.find(id)) != zone->npctable.end()) + auto itr = zone->npctable.find(id); + if(itr != zone->npctable.end()) return itr->second; - // Otherwise, get NPCs from database. - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; + // Otherwise, get NPCs from database. - // If id is 0, load all npc_types for the current zone, - // according to spawn2. - const char *basic_query = "SELECT " - "npc_types.id," - "npc_types.name," - "npc_types.level," - "npc_types.race," - "npc_types.class," - "npc_types.hp," - "npc_types.mana," - "npc_types.gender," - "npc_types.texture," - "npc_types.helmtexture," - "npc_types.size," - "npc_types.loottable_id," - "npc_types.merchant_id," - "npc_types.alt_currency_id," - "npc_types.adventure_template_id," - "npc_types.trap_template," - "npc_types.attack_speed," - "npc_types.STR," - "npc_types.STA," - "npc_types.DEX," - "npc_types.AGI," - "npc_types._INT," - "npc_types.WIS," - "npc_types.CHA," - "npc_types.MR," - "npc_types.CR," - "npc_types.DR," - "npc_types.FR," - "npc_types.PR," - "npc_types.Corrup," - "npc_types.PhR," - "npc_types.mindmg," - "npc_types.maxdmg," - "npc_types.attack_count," - "npc_types.special_abilities," - "npc_types.npc_spells_id," - "npc_types.npc_spells_effects_id," - "npc_types.d_meele_texture1," - "npc_types.d_meele_texture2," - "npc_types.ammo_idfile," - "npc_types.prim_melee_type," - "npc_types.sec_melee_type," - "npc_types.ranged_type," - "npc_types.runspeed," - "npc_types.findable," - "npc_types.trackable," - "npc_types.hp_regen_rate," - "npc_types.mana_regen_rate," - "npc_types.aggroradius," - "npc_types.assistradius," - "npc_types.bodytype," - "npc_types.npc_faction_id," - "npc_types.face," - "npc_types.luclin_hairstyle," - "npc_types.luclin_haircolor," - "npc_types.luclin_eyecolor," - "npc_types.luclin_eyecolor2," - "npc_types.luclin_beardcolor," - "npc_types.luclin_beard," - "npc_types.drakkin_heritage," - "npc_types.drakkin_tattoo," - "npc_types.drakkin_details," - "npc_types.armortint_id," - "npc_types.armortint_red," - "npc_types.armortint_green," - "npc_types.armortint_blue," - "npc_types.see_invis," - "npc_types.see_invis_undead," - "npc_types.lastname," - "npc_types.qglobal," - "npc_types.AC," - "npc_types.npc_aggro," - "npc_types.spawn_limit," - "npc_types.see_hide," - "npc_types.see_improved_hide," - "npc_types.ATK," - "npc_types.Accuracy," - "npc_types.Avoidance," - "npc_types.slow_mitigation," - "npc_types.maxlevel," - "npc_types.scalerate," - "npc_types.private_corpse," - "npc_types.unique_spawn_by_name," - "npc_types.underwater," - "npc_types.emoteid," - "npc_types.spellscale," - "npc_types.healscale," - "npc_types.no_target_hotkey," - "npc_types.raid_target"; + // If id is 0, load all npc_types for the current zone, + // according to spawn2. + std::string query = StringFormat("SELECT npc_types.id, npc_types.name, npc_types.level, npc_types.race, " + "npc_types.class, npc_types.hp, npc_types.mana, npc_types.gender, " + "npc_types.texture, npc_types.helmtexture, npc_types.size, " + "npc_types.loottable_id, npc_types.merchant_id, npc_types.alt_currency_id, " + "npc_types.adventure_template_id, npc_types.trap_template, npc_types.attack_speed, " + "npc_types.STR, npc_types.STA, npc_types.DEX, npc_types.AGI, npc_types._INT, " + "npc_types.WIS, npc_types.CHA, npc_types.MR, npc_types.CR, npc_types.DR, " + "npc_types.FR, npc_types.PR, npc_types.Corrup, npc_types.PhR," + "npc_types.mindmg, npc_types.maxdmg, npc_types.attack_count, npc_types.special_abilities," + "npc_types.npc_spells_id, npc_types.npc_spells_effects_id, npc_types.d_meele_texture1," + "npc_types.d_meele_texture2, npc_types.ammo_idfile, npc_types.prim_melee_type," + "npc_types.sec_melee_type, npc_types.ranged_type, npc_types.runspeed, npc_types.findable," + "npc_types.trackable, npc_types.hp_regen_rate, npc_types.mana_regen_rate, " + "npc_types.aggroradius, npc_types.assistradius, npc_types.bodytype, npc_types.npc_faction_id, " + "npc_types.face, npc_types.luclin_hairstyle, npc_types.luclin_haircolor, " + "npc_types.luclin_eyecolor, npc_types.luclin_eyecolor2, npc_types.luclin_beardcolor," + "npc_types.luclin_beard, npc_types.drakkin_heritage, npc_types.drakkin_tattoo, " + "npc_types.drakkin_details, npc_types.armortint_id, " + "npc_types.armortint_red, npc_types.armortint_green, npc_types.armortint_blue, " + "npc_types.see_invis, npc_types.see_invis_undead, npc_types.lastname, " + "npc_types.qglobal, npc_types.AC, npc_types.npc_aggro, npc_types.spawn_limit, " + "npc_types.see_hide, npc_types.see_improved_hide, npc_types.ATK, npc_types.Accuracy, " + "npc_types.Avoidance, npc_types.slow_mitigation, npc_types.maxlevel, npc_types.scalerate, " + "npc_types.private_corpse, npc_types.unique_spawn_by_name, npc_types.underwater, " + "npc_types.emoteid, npc_types.spellscale, npc_types.healscale, npc_types.no_target_hotkey," + "npc_types.raid_target FROM npc_types WHERE id = %d", id); - MakeAnyLenString(&query, "%s FROM npc_types WHERE id=%d", basic_query, id); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error loading NPCs from database. Bad query: " << results.ErrorMessage() << std::endl; + return nullptr; + } - if (RunQuery(query, strlen(query), errbuf, &result)) { - // Process each row returned. - while((row = mysql_fetch_row(result))) { - NPCType *tmpNPCType; - tmpNPCType = new NPCType; - memset (tmpNPCType, 0, sizeof *tmpNPCType); - int r = 0; - tmpNPCType->npc_id = atoi(row[r++]); + for (auto row = results.begin(); row != results.end(); ++row) { + NPCType *tmpNPCType; + tmpNPCType = new NPCType; + memset (tmpNPCType, 0, sizeof *tmpNPCType); - strn0cpy(tmpNPCType->name, row[r++], 50); + tmpNPCType->npc_id = atoi(row[0]); - tmpNPCType->level = atoi(row[r++]); - tmpNPCType->race = atoi(row[r++]); - tmpNPCType->class_ = atoi(row[r++]); - tmpNPCType->max_hp = atoi(row[r++]); - tmpNPCType->cur_hp = tmpNPCType->max_hp; - tmpNPCType->Mana = atoi(row[r++]); - tmpNPCType->gender = atoi(row[r++]); - tmpNPCType->texture = atoi(row[r++]); - tmpNPCType->helmtexture = atoi(row[r++]); - tmpNPCType->size = atof(row[r++]); - tmpNPCType->loottable_id = atoi(row[r++]); - tmpNPCType->merchanttype = atoi(row[r++]); - tmpNPCType->alt_currency_type = atoi(row[r++]); - tmpNPCType->adventure_template = atoi(row[r++]); - tmpNPCType->trap_template = atoi(row[r++]); - tmpNPCType->attack_speed = atof(row[r++]); - tmpNPCType->STR = atoi(row[r++]); - tmpNPCType->STA = atoi(row[r++]); - tmpNPCType->DEX = atoi(row[r++]); - tmpNPCType->AGI = atoi(row[r++]); - tmpNPCType->INT = atoi(row[r++]); - tmpNPCType->WIS = atoi(row[r++]); - tmpNPCType->CHA = atoi(row[r++]); - tmpNPCType->MR = atoi(row[r++]); - tmpNPCType->CR = atoi(row[r++]); - tmpNPCType->DR = atoi(row[r++]); - tmpNPCType->FR = atoi(row[r++]); - tmpNPCType->PR = atoi(row[r++]); - tmpNPCType->Corrup = atoi(row[r++]); - tmpNPCType->PhR = atoi(row[r++]); - tmpNPCType->min_dmg = atoi(row[r++]); - tmpNPCType->max_dmg = atoi(row[r++]); - tmpNPCType->attack_count = atoi(row[r++]); - strn0cpy(tmpNPCType->special_abilities, row[r++], 512); - tmpNPCType->npc_spells_id = atoi(row[r++]); - tmpNPCType->npc_spells_effects_id = atoi(row[r++]); - tmpNPCType->d_meele_texture1 = atoi(row[r++]); - tmpNPCType->d_meele_texture2 = atoi(row[r++]); - strn0cpy(tmpNPCType->ammo_idfile, row[r++], 30); - tmpNPCType->prim_melee_type = atoi(row[r++]); - tmpNPCType->sec_melee_type = atoi(row[r++]); - tmpNPCType->ranged_type = atoi(row[r++]); - tmpNPCType->runspeed= atof(row[r++]); - tmpNPCType->findable = atoi(row[r++]) == 0? false : true; - tmpNPCType->trackable = atoi(row[r++]) == 0? false : true; - tmpNPCType->hp_regen = atoi(row[r++]); - tmpNPCType->mana_regen = atoi(row[r++]); + strn0cpy(tmpNPCType->name, row[1], 50); - tmpNPCType->aggroradius = (int32)atoi(row[r++]); - // set defaultvalue for aggroradius - if (tmpNPCType->aggroradius <= 0) - tmpNPCType->aggroradius = 70; - tmpNPCType->assistradius = (int32)atoi(row[r++]); - if (tmpNPCType->assistradius <= 0) - tmpNPCType->assistradius = tmpNPCType->aggroradius; + tmpNPCType->level = atoi(row[2]); + tmpNPCType->race = atoi(row[3]); + tmpNPCType->class_ = atoi(row[4]); + tmpNPCType->max_hp = atoi(row[5]); + tmpNPCType->cur_hp = tmpNPCType->max_hp; + tmpNPCType->Mana = atoi(row[6]); + tmpNPCType->gender = atoi(row[7]); + tmpNPCType->texture = atoi(row[8]); + tmpNPCType->helmtexture = atoi(row[9]); + tmpNPCType->size = atof(row[10]); + tmpNPCType->loottable_id = atoi(row[11]); + tmpNPCType->merchanttype = atoi(row[12]); + tmpNPCType->alt_currency_type = atoi(row[13]); + tmpNPCType->adventure_template = atoi(row[14]); + tmpNPCType->trap_template = atoi(row[15]); + tmpNPCType->attack_speed = atof(row[16]); + tmpNPCType->STR = atoi(row[17]); + tmpNPCType->STA = atoi(row[18]); + tmpNPCType->DEX = atoi(row[19]); + tmpNPCType->AGI = atoi(row[20]); + tmpNPCType->INT = atoi(row[21]); + tmpNPCType->WIS = atoi(row[22]); + tmpNPCType->CHA = atoi(row[23]); + tmpNPCType->MR = atoi(row[24]); + tmpNPCType->CR = atoi(row[25]); + tmpNPCType->DR = atoi(row[26]); + tmpNPCType->FR = atoi(row[27]); + tmpNPCType->PR = atoi(row[28]); + tmpNPCType->Corrup = atoi(row[29]); + tmpNPCType->PhR = atoi(row[30]); + tmpNPCType->min_dmg = atoi(row[31]); + tmpNPCType->max_dmg = atoi(row[32]); + tmpNPCType->attack_count = atoi(row[33]); + strn0cpy(tmpNPCType->special_abilities, row[34], 512); + tmpNPCType->npc_spells_id = atoi(row[35]); + tmpNPCType->npc_spells_effects_id = atoi(row[36]); + tmpNPCType->d_meele_texture1 = atoi(row[37]); + tmpNPCType->d_meele_texture2 = atoi(row[38]); + strn0cpy(tmpNPCType->ammo_idfile, row[39], 30); + tmpNPCType->prim_melee_type = atoi(row[40]); + tmpNPCType->sec_melee_type = atoi(row[41]); + tmpNPCType->ranged_type = atoi(row[42]); + tmpNPCType->runspeed= atof(row[43]); + tmpNPCType->findable = atoi(row[44]) == 0? false : true; + tmpNPCType->trackable = atoi(row[45]) == 0? false : true; + tmpNPCType->hp_regen = atoi(row[46]); + tmpNPCType->mana_regen = atoi(row[47]); - if (row[r] && strlen(row[r])) - tmpNPCType->bodytype = (uint8)atoi(row[r]); - else - tmpNPCType->bodytype = 0; - r++; + // set defaultvalue for aggroradius + tmpNPCType->aggroradius = (int32)atoi(row[48]); + if (tmpNPCType->aggroradius <= 0) + tmpNPCType->aggroradius = 70; - tmpNPCType->npc_faction_id = atoi(row[r++]); + tmpNPCType->assistradius = (int32)atoi(row[49]); + if (tmpNPCType->assistradius <= 0) + tmpNPCType->assistradius = tmpNPCType->aggroradius; - tmpNPCType->luclinface = atoi(row[r++]); - tmpNPCType->hairstyle = atoi(row[r++]); - tmpNPCType->haircolor = atoi(row[r++]); - tmpNPCType->eyecolor1 = atoi(row[r++]); - tmpNPCType->eyecolor2 = atoi(row[r++]); - tmpNPCType->beardcolor = atoi(row[r++]); - tmpNPCType->beard = atoi(row[r++]); - tmpNPCType->drakkin_heritage = atoi(row[r++]); - tmpNPCType->drakkin_tattoo = atoi(row[r++]); - tmpNPCType->drakkin_details = atoi(row[r++]); - uint32 armor_tint_id = atoi(row[r++]); - tmpNPCType->armor_tint[0] = (atoi(row[r++]) & 0xFF) << 16; - tmpNPCType->armor_tint[0] |= (atoi(row[r++]) & 0xFF) << 8; - tmpNPCType->armor_tint[0] |= (atoi(row[r++]) & 0xFF); - tmpNPCType->armor_tint[0] |= (tmpNPCType->armor_tint[0]) ? (0xFF << 24) : 0; + if (row[50] && strlen(row[50])) + tmpNPCType->bodytype = (uint8)atoi(row[50]); + else + tmpNPCType->bodytype = 0; - int i; - if (armor_tint_id > 0) - { - if (tmpNPCType->armor_tint[0] == 0) - { - char at_errbuf[MYSQL_ERRMSG_SIZE]; - char *at_query = nullptr; - MYSQL_RES *at_result = nullptr; - MYSQL_ROW at_row; + tmpNPCType->npc_faction_id = atoi(row[51]); - MakeAnyLenString(&at_query, - "SELECT " - "red1h,grn1h,blu1h," - "red2c,grn2c,blu2c," - "red3a,grn3a,blu3a," - "red4b,grn4b,blu4b," - "red5g,grn5g,blu5g," - "red6l,grn6l,blu6l," - "red7f,grn7f,blu7f," - "red8x,grn8x,blu8x," - "red9x,grn9x,blu9x " - "FROM npc_types_tint WHERE id=%d", armor_tint_id); + tmpNPCType->luclinface = atoi(row[52]); + tmpNPCType->hairstyle = atoi(row[53]); + tmpNPCType->haircolor = atoi(row[54]); + tmpNPCType->eyecolor1 = atoi(row[55]); + tmpNPCType->eyecolor2 = atoi(row[56]); + tmpNPCType->beardcolor = atoi(row[57]); + tmpNPCType->beard = atoi(row[58]); + tmpNPCType->drakkin_heritage = atoi(row[59]); + tmpNPCType->drakkin_tattoo = atoi(row[60]); + tmpNPCType->drakkin_details = atoi(row[61]); - if (RunQuery(at_query, strlen(at_query), at_errbuf, &at_result)) - { - if ((at_row = mysql_fetch_row(at_result))) - { - for (i = EmuConstants::MATERIAL_BEGIN; i <= EmuConstants::MATERIAL_END; i++) - { - tmpNPCType->armor_tint[i] = atoi(at_row[i * 3]) << 16; - tmpNPCType->armor_tint[i] |= atoi(at_row[i * 3 + 1]) << 8; - tmpNPCType->armor_tint[i] |= atoi(at_row[i * 3 + 2]); - tmpNPCType->armor_tint[i] |= (tmpNPCType->armor_tint[i]) ? (0xFF << 24) : 0; - } - } - else - { - armor_tint_id = 0; - } - } - else - { - armor_tint_id = 0; - } + uint32 armor_tint_id = atoi(row[62]); - if (at_result) - { - mysql_free_result(at_result); - } + tmpNPCType->armor_tint[0] = (atoi(row[63]) & 0xFF) << 16; + tmpNPCType->armor_tint[0] |= (atoi(row[64]) & 0xFF) << 8; + tmpNPCType->armor_tint[0] |= (atoi(row[65]) & 0xFF); + tmpNPCType->armor_tint[0] |= (tmpNPCType->armor_tint[0]) ? (0xFF << 24) : 0; - safe_delete_array(at_query); - } - else - { - armor_tint_id = 0; - } - } + if (armor_tint_id == 0) + for (int index = MaterialChest; index <= EmuConstants::MATERIAL_END; index++) + tmpNPCType->armor_tint[index] = tmpNPCType->armor_tint[0]; + else if (tmpNPCType->armor_tint[0] == 0) + { + std::string armortint_query = StringFormat("SELECT red1h, grn1h, blu1h, " + "red2c, grn2c, blu2c, " + "red3a, grn3a, blu3a, " + "red4b, grn4b, blu4b, " + "red5g, grn5g, blu5g, " + "red6l, grn6l, blu6l, " + "red7f, grn7f, blu7f, " + "red8x, grn8x, blu8x, " + "red9x, grn9x, blu9x " + "FROM npc_types_tint WHERE id = %d", + armor_tint_id); + auto armortint_results = QueryDatabase(armortint_query); + if (!armortint_results.Success() || armortint_results.RowCount() == 0) + armor_tint_id = 0; + else { + auto armorTint_row = results.begin(); - if (armor_tint_id == 0) - { - for (i = MaterialChest; i <= EmuConstants::MATERIAL_END; i++) - { - tmpNPCType->armor_tint[i] = tmpNPCType->armor_tint[0]; - } - } + for (int index = EmuConstants::MATERIAL_BEGIN; index <= EmuConstants::MATERIAL_END; index++) { + tmpNPCType->armor_tint[index] = atoi(armorTint_row[index * 3]) << 16; + tmpNPCType->armor_tint[index] |= atoi(armorTint_row[index * 3 + 1]) << 8; + tmpNPCType->armor_tint[index] |= atoi(armorTint_row[index * 3 + 2]); + tmpNPCType->armor_tint[index] |= (tmpNPCType->armor_tint[index]) ? (0xFF << 24) : 0; + } + } + } else + armor_tint_id = 0; - tmpNPCType->see_invis = atoi(row[r++]); - tmpNPCType->see_invis_undead = atoi(row[r++])==0?false:true; // Set see_invis_undead flag - if (row[r] != nullptr) - strn0cpy(tmpNPCType->lastname, row[r], 32); - r++; + tmpNPCType->see_invis = atoi(row[66]); + tmpNPCType->see_invis_undead = atoi(row[67]) == 0? false: true; // Set see_invis_undead flag + if (row[68] != nullptr) + strn0cpy(tmpNPCType->lastname, row[68], 32); - tmpNPCType->qglobal = atoi(row[r++])==0?false:true; // qglobal - tmpNPCType->AC = atoi(row[r++]); - tmpNPCType->npc_aggro = atoi(row[r++])==0?false:true; - tmpNPCType->spawn_limit = atoi(row[r++]); - tmpNPCType->see_hide = atoi(row[r++])==0?false:true; - tmpNPCType->see_improved_hide = atoi(row[r++])==0?false:true; - tmpNPCType->ATK = atoi(row[r++]); - tmpNPCType->accuracy_rating = atoi(row[r++]); - tmpNPCType->avoidance_rating = atoi(row[r++]); - tmpNPCType->slow_mitigation = atoi(row[r++]); - tmpNPCType->maxlevel = atoi(row[r++]); - tmpNPCType->scalerate = atoi(row[r++]); - tmpNPCType->private_corpse = atoi(row[r++]) == 1 ? true : false; - tmpNPCType->unique_spawn_by_name = atoi(row[r++]) == 1 ? true : false; - tmpNPCType->underwater = atoi(row[r++]) == 1 ? true : false; - tmpNPCType->emoteid = atoi(row[r++]); - tmpNPCType->spellscale = atoi(row[r++]); - tmpNPCType->healscale = atoi(row[r++]); - tmpNPCType->no_target_hotkey = atoi(row[r++]) == 1 ? true : false; - tmpNPCType->raid_target = atoi(row[r++]) == 0 ? false : true; + tmpNPCType->qglobal = atoi(row[69]) == 0? false: true; // qglobal + tmpNPCType->AC = atoi(row[70]); + tmpNPCType->npc_aggro = atoi(row[71]) == 0? false: true; + tmpNPCType->spawn_limit = atoi(row[72]); + tmpNPCType->see_hide = atoi(row[73]) == 0? false: true; + tmpNPCType->see_improved_hide = atoi(row[74]) == 0? false: true; + tmpNPCType->ATK = atoi(row[75]); + tmpNPCType->accuracy_rating = atoi(row[76]); + tmpNPCType->avoidance_rating = atoi(row[77]); + tmpNPCType->slow_mitigation = atoi(row[78]); + tmpNPCType->maxlevel = atoi(row[79]); + tmpNPCType->scalerate = atoi(row[80]); + tmpNPCType->private_corpse = atoi(row[81]) == 1 ? true: false; + tmpNPCType->unique_spawn_by_name = atoi(row[82]) == 1 ? true: false; + tmpNPCType->underwater = atoi(row[83]) == 1 ? true: false; + tmpNPCType->emoteid = atoi(row[84]); + tmpNPCType->spellscale = atoi(row[85]); + tmpNPCType->healscale = atoi(row[86]); + tmpNPCType->no_target_hotkey = atoi(row[87]) == 1 ? true: false; + tmpNPCType->raid_target = atoi(row[88]) == 0 ? false: true; - // If NPC with duplicate NPC id already in table, - // free item we attempted to add. - if (zone->npctable.find(tmpNPCType->npc_id) != zone->npctable.end()) - { - std::cerr << "Error loading duplicate NPC " << tmpNPCType->npc_id << std::endl; - delete tmpNPCType; - npc = nullptr; - } else { - zone->npctable[tmpNPCType->npc_id]=tmpNPCType; - npc = tmpNPCType; - } + // If NPC with duplicate NPC id already in table, + // free item we attempted to add. + if (zone->npctable.find(tmpNPCType->npc_id) != zone->npctable.end()) { + std::cerr << "Error loading duplicate NPC " << tmpNPCType->npc_id << std::endl; + delete tmpNPCType; + return nullptr; + } -// Sleep(0); - } - - if (result) { - mysql_free_result(result); - } - } else - std::cerr << "Error loading NPCs from database. Bad query: " << errbuf << std::endl; - safe_delete_array(query); + zone->npctable[tmpNPCType->npc_id]=tmpNPCType; + npc = tmpNPCType; + } return npc; } From 205e1d404e86fffe66dafdd2c6e261d00b0b9501 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 20:50:36 -0700 Subject: [PATCH 28/67] GetMercType converted to QueryDatabase --- zone/zonedb.cpp | 405 +++++++++++++++--------------------------------- 1 file changed, 125 insertions(+), 280 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 837878720..a43295ce9 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1148,312 +1148,157 @@ const NPCType* ZoneDatabase::GetNPCType (uint32 id) { return npc; } - const NPCType* ZoneDatabase::GetMercType(uint32 id, uint16 raceid, uint32 clientlevel) { - const NPCType *npc=nullptr; - std::map::iterator itr; //need to save based on merc_npc_type & client level uint32 merc_type_id = id * 100 + clientlevel; // If NPC is already in tree, return it. - if((itr = zone->merctable.find(merc_type_id)) != zone->merctable.end()) + auto itr = zone->merctable.find(merc_type_id); + if(itr != zone->merctable.end()) return itr->second; + //If the NPC type is 0, return nullptr. (sanity check) if(id == 0) - return nullptr; + return nullptr; // Otherwise, get NPCs from database. - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; + // If id is 0, load all npc_types for the current zone, + // according to spawn2. + std::string query = StringFormat("SELECT vwMercNpcTypes.merc_npc_type_id, vwMercNpcTypes.name, " + "vwMercNpcTypes.level, vwMercNpcTypes.race_id, vwMercNpcTypes.class_id, " + "vwMercNpcTypes.hp, vwMercNpcTypes.mana, vwMercNpcTypes.gender, " + "vwMercNpcTypes.texture, vwMercNpcTypes.helmtexture, vwMercNpcTypes.attack_speed, " + "vwMercNpcTypes.STR, vwMercNpcTypes.STA, vwMercNpcTypes.DEX, vwMercNpcTypes.AGI, " + "vwMercNpcTypes._INT, vwMercNpcTypes.WIS, vwMercNpcTypes.CHA, vwMercNpcTypes.MR, " + "vwMercNpcTypes.CR, vwMercNpcTypes.DR, vwMercNpcTypes.FR, vwMercNpcTypes.PR, " + "vwMercNpcTypes.Corrup, vwMercNpcTypes.mindmg, vwMercNpcTypes.maxdmg, " + "vwMercNpcTypes.attack_count, vwMercNpcTypes.special_abilities, " + "vwMercNpcTypes.d_meele_texture1, vwMercNpcTypes.d_meele_texture2, " + "vwMercNpcTypes.prim_melee_type, vwMercNpcTypes.sec_melee_type, " + "vwMercNpcTypes.runspeed, vwMercNpcTypes.hp_regen_rate, vwMercNpcTypes.mana_regen_rate, " + "vwMercNpcTypes.bodytype, vwMercNpcTypes.armortint_id, " + "vwMercNpcTypes.armortint_red, vwMercNpcTypes.armortint_green, vwMercNpcTypes.armortint_blue, " + "vwMercNpcTypes.AC, vwMercNpcTypes.ATK, vwMercNpcTypes.Accuracy, vwMercNpcTypes.spellscale, " + "vwMercNpcTypes.healscale FROM vwMercNpcTypes " + "WHERE merc_npc_type_id = %d AND clientlevel = %d AND race_id = %d", + id, clientlevel, raceid); //dual primary keys. one is ID, one is level. + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error loading NPCs from database. Bad query: " << results.ErrorMessage() << std::endl; + return nullptr; + } + const NPCType *npc; - // If id is 0, load all npc_types for the current zone, - // according to spawn2. - const char *basic_query = "SELECT " - "vwMercNpcTypes.merc_npc_type_id," - "vwMercNpcTypes.name," - //"vwMercNpcTypes.clientlevel," - "vwMercNpcTypes.level," - "vwMercNpcTypes.race_id," - "vwMercNpcTypes.class_id," - "vwMercNpcTypes.hp," - "vwMercNpcTypes.mana," - "vwMercNpcTypes.gender," - "vwMercNpcTypes.texture," - "vwMercNpcTypes.helmtexture," - //"vwMercNpcTypes.size," - // "vwMercNpcTypes.loottable_id," - // "vwMercNpcTypes.merchant_id," - // "vwMercNpcTypes.alt_currency_id," - // "vwMercNpcTypes.adventure_template_id," - // "vwMercNpcTypes.trap_template," - "vwMercNpcTypes.attack_speed," - "vwMercNpcTypes.STR," - "vwMercNpcTypes.STA," - "vwMercNpcTypes.DEX," - "vwMercNpcTypes.AGI," - "vwMercNpcTypes._INT," - "vwMercNpcTypes.WIS," - "vwMercNpcTypes.CHA," - "vwMercNpcTypes.MR," - "vwMercNpcTypes.CR," - "vwMercNpcTypes.DR," - "vwMercNpcTypes.FR," - "vwMercNpcTypes.PR," - "vwMercNpcTypes.Corrup," - "vwMercNpcTypes.mindmg," - "vwMercNpcTypes.maxdmg," - "vwMercNpcTypes.attack_count," - "vwMercNpcTypes.special_abilities," - // "vwMercNpcTypes.npc_spells_id," - "vwMercNpcTypes.d_meele_texture1," - "vwMercNpcTypes.d_meele_texture2," - "vwMercNpcTypes.prim_melee_type," - "vwMercNpcTypes.sec_melee_type," - "vwMercNpcTypes.runspeed," - // "vwMercNpcTypes.findable," - // "vwMercNpcTypes.trackable," - "vwMercNpcTypes.hp_regen_rate," - "vwMercNpcTypes.mana_regen_rate," - // "vwMercNpcTypes.aggroradius," - "vwMercNpcTypes.bodytype," - // "vwMercNpcTypes.npc_faction_id," - //"vwMercNpcTypes.face," - //"vwMercNpcTypes.luclin_hairstyle," - //"vwMercNpcTypes.luclin_haircolor," - //"vwMercNpcTypes.luclin_eyecolor," - //"vwMercNpcTypes.luclin_eyecolor2," - //"vwMercNpcTypes.luclin_beardcolor," - //"vwMercNpcTypes.luclin_beard," - //"vwMercNpcTypes.drakkin_heritage," - //"vwMercNpcTypes.drakkin_tattoo," - //"vwMercNpcTypes.drakkin_details," - "vwMercNpcTypes.armortint_id," - "vwMercNpcTypes.armortint_red," - "vwMercNpcTypes.armortint_green," - "vwMercNpcTypes.armortint_blue," - // "vwMercNpcTypes.see_invis," - // "vwMercNpcTypes.see_invis_undead," - // "vwMercNpcTypes.lastname," - // "vwMercNpcTypes.qglobal," - "vwMercNpcTypes.AC," - // "vwMercNpcTypes.npc_aggro," - // "vwMercNpcTypes.spawn_limit," - // "vwMercNpcTypes.see_hide," - // "vwMercNpcTypes.see_improved_hide," - "vwMercNpcTypes.ATK," - "vwMercNpcTypes.Accuracy," - "vwMercNpcTypes.spellscale," - "vwMercNpcTypes.healscale"; - // "vwMercNpcTypes.slow_mitigation," - // "vwMercNpcTypes.maxlevel," - // "vwMercNpcTypes.scalerate," - // "vwMercNpcTypes.private_corpse," - // "vwMercNpcTypes.unique_spawn_by_name," - // "vwMercNpcTypes.underwater," - // "vwMercNpcTypes.emoteid"; + // Process each row returned. + for (auto row = results.begin(); row != results.end(); ++row) { + NPCType *tmpNPCType; + tmpNPCType = new NPCType; + memset (tmpNPCType, 0, sizeof *tmpNPCType); - MakeAnyLenString(&query, "%s FROM vwMercNpcTypes WHERE merc_npc_type_id=%d AND clientlevel=%d AND race_id = %d", basic_query, id, clientlevel, raceid); //dual primary keys. one is ID, one is level. + tmpNPCType->npc_id = atoi(row[0]); - if (RunQuery(query, strlen(query), errbuf, &result)) { - // Process each row returned. - while((row = mysql_fetch_row(result))) { - NPCType *tmpNPCType; - tmpNPCType = new NPCType; - memset (tmpNPCType, 0, sizeof *tmpNPCType); + strn0cpy(tmpNPCType->name, row[1], 50); - int r = 0; - tmpNPCType->npc_id = atoi(row[r++]); + tmpNPCType->level = atoi(row[2]); + tmpNPCType->race = atoi(row[3]); + tmpNPCType->class_ = atoi(row[4]); + tmpNPCType->max_hp = atoi(row[5]); + tmpNPCType->cur_hp = tmpNPCType->max_hp; + tmpNPCType->Mana = atoi(row[6]); + tmpNPCType->gender = atoi(row[7]); + tmpNPCType->texture = atoi(row[8]); + tmpNPCType->helmtexture = atoi(row[9]); + tmpNPCType->attack_speed = atof(row[10]); + tmpNPCType->STR = atoi(row[11]); + tmpNPCType->STA = atoi(row[12]); + tmpNPCType->DEX = atoi(row[13]); + tmpNPCType->AGI = atoi(row[14]); + tmpNPCType->INT = atoi(row[15]); + tmpNPCType->WIS = atoi(row[16]); + tmpNPCType->CHA = atoi(row[17]); + tmpNPCType->MR = atoi(row[18]); + tmpNPCType->CR = atoi(row[19]); + tmpNPCType->DR = atoi(row[20]); + tmpNPCType->FR = atoi(row[21]); + tmpNPCType->PR = atoi(row[22]); + tmpNPCType->Corrup = atoi(row[23]); + tmpNPCType->min_dmg = atoi(row[24]); + tmpNPCType->max_dmg = atoi(row[25]); + tmpNPCType->attack_count = atoi(row[26]); + strn0cpy(tmpNPCType->special_abilities, row[27], 512); - strn0cpy(tmpNPCType->name, row[r++], 50); + tmpNPCType->d_meele_texture1 = atoi(row[28]); + tmpNPCType->d_meele_texture2 = atoi(row[29]); + tmpNPCType->prim_melee_type = atoi(row[30]); + tmpNPCType->sec_melee_type = atoi(row[31]); + tmpNPCType->runspeed= atof(row[32]); - tmpNPCType->level = atoi(row[r++]); - tmpNPCType->race = atoi(row[r++]); - tmpNPCType->class_ = atoi(row[r++]); - tmpNPCType->max_hp = atoi(row[r++]); - tmpNPCType->cur_hp = tmpNPCType->max_hp; - tmpNPCType->Mana = atoi(row[r++]); - tmpNPCType->gender = atoi(row[r++]); - tmpNPCType->texture = atoi(row[r++]); - tmpNPCType->helmtexture = atoi(row[r++]); - //tmpNPCType->size = atof(row[r++]); - //tmpNPCType->loottable_id = atoi(row[r++]); - //tmpNPCType->merchanttype = atoi(row[r++]); - //tmpNPCType->alt_currency_type = atoi(row[r++]); - //tmpNPCType->adventure_template = atoi(row[r++]); - //tmpNPCType->trap_template = atoi(row[r++]); - tmpNPCType->attack_speed = atof(row[r++]); - tmpNPCType->STR = atoi(row[r++]); - tmpNPCType->STA = atoi(row[r++]); - tmpNPCType->DEX = atoi(row[r++]); - tmpNPCType->AGI = atoi(row[r++]); - tmpNPCType->INT = atoi(row[r++]); - tmpNPCType->WIS = atoi(row[r++]); - tmpNPCType->CHA = atoi(row[r++]); - tmpNPCType->MR = atoi(row[r++]); - tmpNPCType->CR = atoi(row[r++]); - tmpNPCType->DR = atoi(row[r++]); - tmpNPCType->FR = atoi(row[r++]); - tmpNPCType->PR = atoi(row[r++]); - tmpNPCType->Corrup = atoi(row[r++]); - tmpNPCType->min_dmg = atoi(row[r++]); - tmpNPCType->max_dmg = atoi(row[r++]); - tmpNPCType->attack_count = atoi(row[r++]); - strn0cpy(tmpNPCType->special_abilities, row[r++], 512); - //tmpNPCType->npc_spells_id = atoi(row[r++]); - tmpNPCType->d_meele_texture1 = atoi(row[r++]); - tmpNPCType->d_meele_texture2 = atoi(row[r++]); - tmpNPCType->prim_melee_type = atoi(row[r++]); - tmpNPCType->sec_melee_type = atoi(row[r++]); - tmpNPCType->runspeed= atof(row[r++]); - //tmpNPCType->findable = atoi(row[r++]) == 0? false : true; - //tmpNPCType->trackable = atoi(row[r++]) == 0? false : true; - tmpNPCType->hp_regen = atoi(row[r++]); - tmpNPCType->mana_regen = atoi(row[r++]); + tmpNPCType->hp_regen = atoi(row[33]); + tmpNPCType->mana_regen = atoi(row[34]); - //tmpNPCType->aggroradius = (int32)atoi(row[r++]); - tmpNPCType->aggroradius = RuleI(Mercs, AggroRadius); - // set defaultvalue for aggroradius - //if (tmpNPCType->aggroradius <= 0) - // tmpNPCType->aggroradius = 70; + tmpNPCType->aggroradius = RuleI(Mercs, AggroRadius); - if (row[r] && strlen(row[r])) - tmpNPCType->bodytype = (uint8)atoi(row[r]); - else - tmpNPCType->bodytype = 1; - r++; + if (row[35] && strlen(row[35])) + tmpNPCType->bodytype = (uint8)atoi(row[35]); + else + tmpNPCType->bodytype = 1; - //tmpNPCType->npc_faction_id = atoi(row[r++]); + uint32 armor_tint_id = atoi(row[36]); + tmpNPCType->armor_tint[0] = (atoi(row[37]) & 0xFF) << 16; + tmpNPCType->armor_tint[0] |= (atoi(row[38]) & 0xFF) << 8; + tmpNPCType->armor_tint[0] |= (atoi(row[39]) & 0xFF); + tmpNPCType->armor_tint[0] |= (tmpNPCType->armor_tint[0]) ? (0xFF << 24) : 0; - //tmpNPCType->luclinface = atoi(row[r++]); - //tmpNPCType->hairstyle = atoi(row[r++]); - //tmpNPCType->haircolor = atoi(row[r++]); - //tmpNPCType->eyecolor1 = atoi(row[r++]); - //tmpNPCType->eyecolor2 = atoi(row[r++]); - //tmpNPCType->beardcolor = atoi(row[r++]); - //tmpNPCType->beard = atoi(row[r++]); - //tmpNPCType->drakkin_heritage = atoi(row[r++]); - //tmpNPCType->drakkin_tattoo = atoi(row[r++]); - //tmpNPCType->drakkin_details = atoi(row[r++]); - uint32 armor_tint_id = atoi(row[r++]); - tmpNPCType->armor_tint[0] = (atoi(row[r++]) & 0xFF) << 16; - tmpNPCType->armor_tint[0] |= (atoi(row[r++]) & 0xFF) << 8; - tmpNPCType->armor_tint[0] |= (atoi(row[r++]) & 0xFF); - tmpNPCType->armor_tint[0] |= (tmpNPCType->armor_tint[0]) ? (0xFF << 24) : 0; + if (armor_tint_id == 0) + for (int index = MaterialChest; index <= EmuConstants::MATERIAL_END; index++) + tmpNPCType->armor_tint[index] = tmpNPCType->armor_tint[0]; + else if (tmpNPCType->armor_tint[0] == 0) { + std::string armorTint_query = StringFormat("SELECT red1h, grn1h, blu1h, " + "red2c, grn2c, blu2c, " + "red3a, grn3a, blu3a, " + "red4b, grn4b, blu4b, " + "red5g, grn5g, blu5g, " + "red6l, grn6l, blu6l, " + "red7f, grn7f, blu7f, " + "red8x, grn8x, blu8x, " + "red9x, grn9x, blu9x " + "FROM npc_types_tint WHERE id = %d", + armor_tint_id); + auto armorTint_results = QueryDatabase(armorTint_query); + if (!results.Success() || results.RowCount() == 0) + armor_tint_id = 0; + else { + auto armorTint_row = results.begin(); - int i; - if (armor_tint_id > 0) - { - if (tmpNPCType->armor_tint[0] == 0) - { - char at_errbuf[MYSQL_ERRMSG_SIZE]; - char *at_query = nullptr; - MYSQL_RES *at_result = nullptr; - MYSQL_ROW at_row; + for (int index = EmuConstants::MATERIAL_BEGIN; index <= EmuConstants::MATERIAL_END; index++) { + tmpNPCType->armor_tint[index] = atoi(armorTint_row[index * 3]) << 16; + tmpNPCType->armor_tint[index] |= atoi(armorTint_row[index * 3 + 1]) << 8; + tmpNPCType->armor_tint[index] |= atoi(armorTint_row[index * 3 + 2]); + tmpNPCType->armor_tint[index] |= (tmpNPCType->armor_tint[index]) ? (0xFF << 24) : 0; + } + } + } else + armor_tint_id = 0; - MakeAnyLenString(&at_query, - "SELECT " - "red1h,grn1h,blu1h," - "red2c,grn2c,blu2c," - "red3a,grn3a,blu3a," - "red4b,grn4b,blu4b," - "red5g,grn5g,blu5g," - "red6l,grn6l,blu6l," - "red7f,grn7f,blu7f," - "red8x,grn8x,blu8x," - "red9x,grn9x,blu9x " - "FROM npc_types_tint WHERE id=%d", armor_tint_id); + tmpNPCType->AC = atoi(row[40]); + tmpNPCType->ATK = atoi(row[41]); + tmpNPCType->accuracy_rating = atoi(row[42]); + tmpNPCType->scalerate = RuleI(Mercs, ScaleRate); + tmpNPCType->spellscale = atoi(row[43]); + tmpNPCType->healscale = atoi(row[4]); - if (RunQuery(at_query, strlen(at_query), at_errbuf, &at_result)) - { - if ((at_row = mysql_fetch_row(at_result))) - { - for (i = EmuConstants::MATERIAL_BEGIN; i <= EmuConstants::MATERIAL_END; i++) - { - tmpNPCType->armor_tint[i] = atoi(at_row[i * 3]) << 16; - tmpNPCType->armor_tint[i] |= atoi(at_row[i * 3 + 1]) << 8; - tmpNPCType->armor_tint[i] |= atoi(at_row[i * 3 + 2]); - tmpNPCType->armor_tint[i] |= (tmpNPCType->armor_tint[i]) ? (0xFF << 24) : 0; - } - } - else - { - armor_tint_id = 0; - } - } - else - { - armor_tint_id = 0; - } + // If NPC with duplicate NPC id already in table, + // free item we attempted to add. + if (zone->merctable.find(tmpNPCType->npc_id * 100 + clientlevel) != zone->merctable.end()) { + delete tmpNPCType; + return nullptr; + } - if (at_result) - { - mysql_free_result(at_result); - } - - safe_delete_array(at_query); - } - else - { - armor_tint_id = 0; - } - } - - if (armor_tint_id == 0) - { - for (i = MaterialChest; i <= EmuConstants::MATERIAL_END; i++) - { - tmpNPCType->armor_tint[i] = tmpNPCType->armor_tint[0]; - } - } - - //tmpNPCType->see_invis = atoi(row[r++]); - //tmpNPCType->see_invis_undead = atoi(row[r++])==0?false:true; // Set see_invis_undead flag - //if (row[r] != nullptr) - // strn0cpy(tmpNPCType->lastname, row[r], 32); - //r++; - - //tmpNPCType->qglobal = atoi(row[r++])==0?false:true; // qglobal - tmpNPCType->AC = atoi(row[r++]); - //tmpNPCType->npc_aggro = atoi(row[r++])==0?false:true; - //tmpNPCType->spawn_limit = atoi(row[r++]); - //tmpNPCType->see_hide = atoi(row[r++])==0?false:true; - //tmpNPCType->see_improved_hide = atoi(row[r++])==0?false:true; - tmpNPCType->ATK = atoi(row[r++]); - tmpNPCType->accuracy_rating = atoi(row[r++]); - //tmpNPCType->slow_mitigation = atof(row[r++]); - //tmpNPCType->maxlevel = atoi(row[r++]); - tmpNPCType->scalerate = RuleI(Mercs, ScaleRate); - //tmpNPCType->private_corpse = atoi(row[r++]) == 1 ? true : false; - //tmpNPCType->unique_spawn_by_name = atoi(row[r++]) == 1 ? true : false; - //tmpNPCType->underwater = atoi(row[r++]) == 1 ? true : false; - //tmpNPCType->emoteid = atoi(row[r++]); - tmpNPCType->spellscale = atoi(row[r++]); - tmpNPCType->healscale = atoi(row[r++]); - - // If NPC with duplicate NPC id already in table, - // free item we attempted to add. - if (zone->merctable.find(tmpNPCType->npc_id * 100 + clientlevel) != zone->merctable.end()) - { - delete tmpNPCType; - npc = nullptr; - } else { - zone->merctable[tmpNPCType->npc_id * 100 + clientlevel]=tmpNPCType; - npc = tmpNPCType; - } - -// Sleep(0); - } - - if (result) { - mysql_free_result(result); - } - } else - std::cerr << "Error loading NPCs from database. Bad query: " << errbuf << std::endl; - safe_delete_array(query); + zone->merctable[tmpNPCType->npc_id * 100 + clientlevel]=tmpNPCType; + npc = tmpNPCType; + } return npc; } From 322cea73427c36e2d5f6dd3a4e48a603aef61453 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 20:58:11 -0700 Subject: [PATCH 29/67] LoadMercInfo converted to QueryDatabase --- zone/zonedb.cpp | 92 ++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 51 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index a43295ce9..7084d8e81 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1303,63 +1303,53 @@ const NPCType* ZoneDatabase::GetMercType(uint32 id, uint16 raceid, uint32 client return npc; } -bool ZoneDatabase::LoadMercInfo(Client *c) { - bool loaded = false; +bool ZoneDatabase::LoadMercInfo(Client *client) { - if(c->GetEPP().merc_name[0] != 0) { - std::string errorMessage; - char* Query = 0; - char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; - MYSQL_RES* DatasetResult; - MYSQL_ROW DataRow; - //char name[64]; + if(client->GetEPP().merc_name[0] == 0) + return false; - //CleanMobName(c->GetEPP().merc_name, name); + std::string query = StringFormat("SELECT MercID, Slot, Name, TemplateID, SuspendedTime, " + "IsSuspended, TimerRemaining, Gender, StanceID, HP, Mana, " + "Endurance, Face, LuclinHairStyle, LuclinHairColor, " + "LuclinEyeColor, LuclinEyeColor2, LuclinBeardColor, LuclinBeard, " + "DrakkinHeritage, DrakkinTattoo, DrakkinDetails " + "FROM mercs WHERE OwnerCharacterID = '%i' ORDER BY Slot", client->CharacterID()); + auto results = QueryDatabase(query); + if (!results.Success()) + return false; - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT MercID, Slot, Name, TemplateID, SuspendedTime, IsSuspended, TimerRemaining, Gender, StanceID, HP, Mana, Endurance, Face, LuclinHairStyle, LuclinHairColor, LuclinEyeColor, LuclinEyeColor2, LuclinBeardColor, LuclinBeard, DrakkinHeritage, DrakkinTattoo, DrakkinDetails FROM mercs WHERE OwnerCharacterID = '%i' ORDER BY Slot", c->CharacterID()), TempErrorMessageBuffer, &DatasetResult)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - else { - while(DataRow = mysql_fetch_row(DatasetResult)) { - uint8 slot = atoi(DataRow[1]); + for (auto row = results.begin(); row != results.end(); ++row) { + uint8 slot = atoi(row[1]); - if(slot >= MAXMERCS) { - continue; - } + if(slot >= MAXMERCS) + continue; - c->GetMercInfo(slot).mercid = atoi(DataRow[0]); - c->GetMercInfo(slot).slot = slot; - snprintf(c->GetMercInfo(slot).merc_name, 64, "%s", std::string(DataRow[2]).c_str()); - c->GetMercInfo(slot).MercTemplateID = atoi(DataRow[3]); - c->GetMercInfo(slot).SuspendedTime = atoi(DataRow[4]); - c->GetMercInfo(slot).IsSuspended = atoi(DataRow[5]) == 1 ? true : false; - c->GetMercInfo(slot).MercTimerRemaining = atoi(DataRow[6]); - c->GetMercInfo(slot).Gender = atoi(DataRow[7]); - c->GetMercInfo(slot).State = 5; - c->GetMercInfo(slot).Stance = atoi(DataRow[8]); - c->GetMercInfo(slot).hp = atoi(DataRow[9]); - c->GetMercInfo(slot).mana = atoi(DataRow[10]); - c->GetMercInfo(slot).endurance = atoi(DataRow[11]); - c->GetMercInfo(slot).face = atoi(DataRow[12]); - c->GetMercInfo(slot).luclinHairStyle = atoi(DataRow[13]); - c->GetMercInfo(slot).luclinHairColor = atoi(DataRow[14]); - c->GetMercInfo(slot).luclinEyeColor = atoi(DataRow[15]); - c->GetMercInfo(slot).luclinEyeColor2 = atoi(DataRow[16]); - c->GetMercInfo(slot).luclinBeardColor = atoi(DataRow[17]); - c->GetMercInfo(slot).luclinBeard = atoi(DataRow[18]); - c->GetMercInfo(slot).drakkinHeritage = atoi(DataRow[19]); - c->GetMercInfo(slot).drakkinTattoo = atoi(DataRow[20]); - c->GetMercInfo(slot).drakkinDetails = atoi(DataRow[21]); - loaded = true; - } + client->GetMercInfo(slot).mercid = atoi(row[0]); + client->GetMercInfo(slot).slot = slot; + snprintf(client->GetMercInfo(slot).merc_name, 64, "%s", row[2]); + client->GetMercInfo(slot).MercTemplateID = atoi(row[3]); + client->GetMercInfo(slot).SuspendedTime = atoi(row[4]); + client->GetMercInfo(slot).IsSuspended = atoi(row[5]) == 1 ? true : false; + client->GetMercInfo(slot).MercTimerRemaining = atoi(row[6]); + client->GetMercInfo(slot).Gender = atoi(row[7]); + client->GetMercInfo(slot).State = 5; + client->GetMercInfo(slot).Stance = atoi(row[8]); + client->GetMercInfo(slot).hp = atoi(row[9]); + client->GetMercInfo(slot).mana = atoi(row[10]); + client->GetMercInfo(slot).endurance = atoi(row[11]); + client->GetMercInfo(slot).face = atoi(row[12]); + client->GetMercInfo(slot).luclinHairStyle = atoi(row[13]); + client->GetMercInfo(slot).luclinHairColor = atoi(row[14]); + client->GetMercInfo(slot).luclinEyeColor = atoi(row[15]); + client->GetMercInfo(slot).luclinEyeColor2 = atoi(row[16]); + client->GetMercInfo(slot).luclinBeardColor = atoi(row[17]); + client->GetMercInfo(slot).luclinBeard = atoi(row[18]); + client->GetMercInfo(slot).drakkinHeritage = atoi(row[19]); + client->GetMercInfo(slot).drakkinTattoo = atoi(row[20]); + client->GetMercInfo(slot).drakkinDetails = atoi(row[21]); + } - mysql_free_result(DatasetResult); - } - - safe_delete_array(Query); - } - - return loaded; + return true; } bool ZoneDatabase::LoadCurrentMerc(Client *c) { From b846d89b5dde5385018cfe8e1ebb24f9c6fc1dac Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 21:04:00 -0700 Subject: [PATCH 30/67] LoadCurrentMerc converted to QueryDatabase --- zone/zonedb.cpp | 87 +++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 7084d8e81..47381d5af 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1352,60 +1352,55 @@ bool ZoneDatabase::LoadMercInfo(Client *client) { return true; } -bool ZoneDatabase::LoadCurrentMerc(Client *c) { - bool loaded = false; +bool ZoneDatabase::LoadCurrentMerc(Client *client) { - if(c->GetEPP().merc_name[0] != 0) { - std::string errorMessage; - char* Query = 0; - char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; - MYSQL_RES* DatasetResult; - MYSQL_ROW DataRow; - //char name[64]; + if(client->GetEPP().merc_name[0] == 0) + return false; - uint8 slot = c->GetMercSlot(); + uint8 slot = client->GetMercSlot(); - if(slot > MAXMERCS) { - return false; - } + if(slot > MAXMERCS) + return false; - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT MercID, Name, TemplateID, SuspendedTime, IsSuspended, TimerRemaining, Gender, StanceID, HP, Mana, Endurance, Face, LuclinHairStyle, LuclinHairColor, LuclinEyeColor, LuclinEyeColor2, LuclinBeardColor, LuclinBeard, DrakkinHeritage, DrakkinTattoo, DrakkinDetails FROM mercs WHERE OwnerCharacterID = '%i' AND Slot = '%u'", c->CharacterID(), slot), TempErrorMessageBuffer, &DatasetResult)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - else { - while(DataRow = mysql_fetch_row(DatasetResult)) { - c->GetMercInfo(slot).mercid = atoi(DataRow[0]); - c->GetMercInfo(slot).slot = slot; - snprintf(c->GetMercInfo(slot).merc_name, 64, "%s", std::string(DataRow[1]).c_str()); - c->GetMercInfo(slot).MercTemplateID = atoi(DataRow[2]); - c->GetMercInfo(slot).SuspendedTime = atoi(DataRow[3]); - c->GetMercInfo(slot).IsSuspended = atoi(DataRow[4]) == 1 ? true : false; - c->GetMercInfo(slot).MercTimerRemaining = atoi(DataRow[5]); - c->GetMercInfo(slot).Gender = atoi(DataRow[6]); - c->GetMercInfo(slot).State = atoi(DataRow[7]); - c->GetMercInfo(slot).hp = atoi(DataRow[8]); - c->GetMercInfo(slot).mana = atoi(DataRow[9]); - c->GetMercInfo(slot).endurance = atoi(DataRow[10]); - c->GetMercInfo(slot).face = atoi(DataRow[11]); - c->GetMercInfo(slot).luclinHairStyle = atoi(DataRow[12]); - c->GetMercInfo(slot).luclinHairColor = atoi(DataRow[13]); - c->GetMercInfo(slot).luclinEyeColor = atoi(DataRow[14]); - c->GetMercInfo(slot).luclinEyeColor2 = atoi(DataRow[15]); - c->GetMercInfo(slot).luclinBeardColor = atoi(DataRow[16]); - c->GetMercInfo(slot).luclinBeard = atoi(DataRow[17]); - c->GetMercInfo(slot).drakkinHeritage = atoi(DataRow[18]); - c->GetMercInfo(slot).drakkinTattoo = atoi(DataRow[19]); - c->GetMercInfo(slot).drakkinDetails = atoi(DataRow[20]); - loaded = true; - } + std::string query = StringFormat("SELECT MercID, Name, TemplateID, SuspendedTime, " + "IsSuspended, TimerRemaining, Gender, StanceID, HP, " + "Mana, Endurance, Face, LuclinHairStyle, LuclinHairColor, " + "LuclinEyeColor, LuclinEyeColor2, LuclinBeardColor, " + "LuclinBeard, DrakkinHeritage, DrakkinTattoo, DrakkinDetails " + "FROM mercs WHERE OwnerCharacterID = '%i' AND Slot = '%u'", + client->CharacterID(), slot); + auto results = database.QueryDatabase(query); - mysql_free_result(DatasetResult); - } + if(!results.Success()) + return false; - safe_delete_array(Query); + + for (auto row = results.begin(); row != results.end(); ++row) { + client->GetMercInfo(slot).mercid = atoi(row[0]); + client->GetMercInfo(slot).slot = slot; + snprintf(client->GetMercInfo(slot).merc_name, 64, "%s", row[1]); + client->GetMercInfo(slot).MercTemplateID = atoi(row[2]); + client->GetMercInfo(slot).SuspendedTime = atoi(row[3]); + client->GetMercInfo(slot).IsSuspended = atoi(row[4]) == 1? true: false; + client->GetMercInfo(slot).MercTimerRemaining = atoi(row[5]); + client->GetMercInfo(slot).Gender = atoi(row[6]); + client->GetMercInfo(slot).State = atoi(row[7]); + client->GetMercInfo(slot).hp = atoi(row[8]); + client->GetMercInfo(slot).mana = atoi(row[9]); + client->GetMercInfo(slot).endurance = atoi(row[10]); + client->GetMercInfo(slot).face = atoi(row[11]); + client->GetMercInfo(slot).luclinHairStyle = atoi(row[12]); + client->GetMercInfo(slot).luclinHairColor = atoi(row[13]); + client->GetMercInfo(slot).luclinEyeColor = atoi(row[14]); + client->GetMercInfo(slot).luclinEyeColor2 = atoi(row[15]); + client->GetMercInfo(slot).luclinBeardColor = atoi(row[16]); + client->GetMercInfo(slot).luclinBeard = atoi(row[17]); + client->GetMercInfo(slot).drakkinHeritage = atoi(row[18]); + client->GetMercInfo(slot).drakkinTattoo = atoi(row[19]); + client->GetMercInfo(slot).drakkinDetails = atoi(row[20]); } - return loaded; + return true; } bool ZoneDatabase::SaveMerc(Merc *merc) { From c6e82448b6454488c81505dcd69a20706f6e90b8 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 21:17:17 -0700 Subject: [PATCH 31/67] SaveMerc converted to QueryDatabase --- zone/zonedb.cpp | 101 +++++++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 47381d5af..9e3c97ee5 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1405,57 +1405,78 @@ bool ZoneDatabase::LoadCurrentMerc(Client *client) { bool ZoneDatabase::SaveMerc(Merc *merc) { Client *owner = merc->GetMercOwner(); - bool Result = false; - std::string errorMessage; - if(!owner) { + if(!owner) return false; - } - - char* Query = 0; - char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; - uint32 affectedRows = 0; if(merc->GetMercID() == 0) { // New merc record uint32 TempNewMercID = 0; - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "INSERT INTO mercs (OwnerCharacterID, Slot, Name, TemplateID, SuspendedTime, IsSuspended, TimerRemaining, Gender, StanceID, HP, Mana, Endurance, Face, LuclinHairStyle, LuclinHairColor, LuclinEyeColor, LuclinEyeColor2, LuclinBeardColor, LuclinBeard, DrakkinHeritage, DrakkinTattoo, DrakkinDetails) VALUES('%u', '%u', '%s', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%i', '%i', '%i', '%i', '%i', '%i', '%i', '%i', '%i', '%i')", merc->GetMercCharacterID(), owner->GetNumMercs(), merc->GetCleanName(), merc->GetMercTemplateID(), owner->GetMercInfo().SuspendedTime, merc->IsSuspended(), owner->GetMercInfo().MercTimerRemaining, merc->GetGender(), merc->GetStance(), merc->GetHP(), merc->GetMana(), merc->GetEndurance(), merc->GetLuclinFace(), merc->GetHairStyle(), merc->GetHairColor(), merc->GetEyeColor1(), merc->GetEyeColor2(), merc->GetBeardColor(), merc->GetBeard(), merc->GetDrakkinHeritage(), merc->GetDrakkinTattoo(), merc->GetDrakkinDetails() ), TempErrorMessageBuffer, 0, &affectedRows, &TempNewMercID)) { - errorMessage = std::string(TempErrorMessageBuffer); + std::string query = StringFormat("INSERT INTO mercs " + "(OwnerCharacterID, Slot, Name, TemplateID, " + "SuspendedTime, IsSuspended, TimerRemaining, " + "Gender, StanceID, HP, Mana, Endurance, Face, " + "LuclinHairStyle, LuclinHairColor, LuclinEyeColor, " + "LuclinEyeColor2, LuclinBeardColor, LuclinBeard, " + "DrakkinHeritage, DrakkinTattoo, DrakkinDetails) " + "VALUES('%u', '%u', '%s', '%u', '%u', '%u', '%u', " + "'%u', '%u', '%u', '%u', '%u', '%i', '%i', '%i', " + "'%i', '%i', '%i', '%i', '%i', '%i', '%i')", + merc->GetMercCharacterID(), owner->GetNumMercs(), + merc->GetCleanName(), merc->GetMercTemplateID(), + owner->GetMercInfo().SuspendedTime, merc->IsSuspended(), + owner->GetMercInfo().MercTimerRemaining, merc->GetGender(), + merc->GetStance(), merc->GetHP(), merc->GetMana(), + merc->GetEndurance(), merc->GetLuclinFace(), + merc->GetHairStyle(), merc->GetHairColor(), merc->GetEyeColor1(), + merc->GetEyeColor2(), merc->GetBeardColor(), + merc->GetBeard(), merc->GetDrakkinHeritage(), + merc->GetDrakkinTattoo(), merc->GetDrakkinDetails()); + auto results = database.QueryDatabase(query); + if(!results.Success()) { + owner->Message(13, results.ErrorMessage().c_str()); + return false; + } else if (results.RowsAffected() != 1) { + owner->Message(13, "Unable to save merc to the database."); + return false; } - else { - merc->SetMercID(TempNewMercID); - Result = true; - } - } - else { - // Update existing merc record - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "UPDATE mercs SET OwnerCharacterID = '%u', Slot = '%u', Name = '%s', TemplateID = '%u', SuspendedTime = '%u', IsSuspended = '%u', TimerRemaining = '%u', Gender = '%u', StanceID = '%u', HP = '%u', Mana = '%u', Endurance = '%u', Face = '%i', LuclinHairStyle = '%i', LuclinHairColor = '%i', LuclinEyeColor = '%i', LuclinEyeColor2 = '%i', LuclinBeardColor = '%i', LuclinBeard = '%i', DrakkinHeritage = '%i', DrakkinTattoo = '%i', DrakkinDetails = '%i' WHERE MercID = '%u'", merc->GetMercCharacterID(), owner->GetMercSlot(), merc->GetCleanName(), merc->GetMercTemplateID(), owner->GetMercInfo().SuspendedTime, merc->IsSuspended(), owner->GetMercInfo().MercTimerRemaining, merc->GetGender(), merc->GetStance(), merc->GetHP(), merc->GetMana(), merc->GetEndurance(), merc->GetLuclinFace(), merc->GetHairStyle(), merc->GetHairColor(), merc->GetEyeColor1(), merc->GetEyeColor2(), merc->GetBeardColor(), merc->GetBeard(), merc->GetDrakkinHeritage(), merc->GetDrakkinTattoo(), merc->GetDrakkinDetails(), merc->GetMercID()), TempErrorMessageBuffer, 0, &affectedRows)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - else { - Result = true; - //time(&_startTotalPlayTime); - } - } - safe_delete_array(Query); - - if(!errorMessage.empty() || (Result && affectedRows != 1)) { - if(owner && !errorMessage.empty()) - owner->Message(13, errorMessage.c_str()); - else if(owner) - owner->Message(13, std::string("Unable to save merc to the database.").c_str()); - - Result = false; - } - else { - merc->UpdateMercInfo(owner); + merc->SetMercID(TempNewMercID); + merc->UpdateMercInfo(owner); database.SaveMercBuffs(merc); - //database.SaveMercStance(this); - //database.SaveMercTimers(this); + return true; } - return Result; + // Update existing merc record + std::string query = StringFormat("UPDATE mercs SET OwnerCharacterID = '%u', Slot = '%u', " + "Name = '%s', TemplateID = '%u', SuspendedTime = '%u', " + "IsSuspended = '%u', TimerRemaining = '%u', Gender = '%u', " + "StanceID = '%u', HP = '%u', Mana = '%u', Endurance = '%u', " + "Face = '%i', LuclinHairStyle = '%i', LuclinHairColor = '%i', " + "LuclinEyeColor = '%i', LuclinEyeColor2 = '%i', LuclinBeardColor = '%i', " + "LuclinBeard = '%i', DrakkinHeritage = '%i', DrakkinTattoo = '%i', " + "DrakkinDetails = '%i' WHERE MercID = '%u'", + merc->GetMercCharacterID(), owner->GetMercSlot(), merc->GetCleanName(), + merc->GetMercTemplateID(), owner->GetMercInfo().SuspendedTime, + merc->IsSuspended(), owner->GetMercInfo().MercTimerRemaining, + merc->GetGender(), merc->GetStance(), merc->GetHP(), merc->GetMana(), + merc->GetEndurance(), merc->GetLuclinFace(), merc->GetHairStyle(), + merc->GetHairColor(), merc->GetEyeColor1(), merc->GetEyeColor2(), + merc->GetBeardColor(), merc->GetBeard(), merc->GetDrakkinHeritage(), + merc->GetDrakkinTattoo(), merc->GetDrakkinDetails(), merc->GetMercID()); + auto results = database.QueryDatabase(query); + if (!results.Success()) { + owner->Message(13, results.ErrorMessage().c_str()); + return false; + } else if (results.RowsAffected() != 1) { + owner->Message(13, "Unable to save merc to the database."); + return false; + } + + merc->UpdateMercInfo(owner); + database.SaveMercBuffs(merc); + + return true; } void ZoneDatabase::SaveMercBuffs(Merc *merc) { From 5cabe109da6f2472140efc8ce13d452125d05de7 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 21:30:51 -0700 Subject: [PATCH 32/67] SaveMercBuffs converted to QueryDatabase --- zone/zonedb.cpp | 86 ++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 55 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 9e3c97ee5..fc92c1254 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1480,66 +1480,42 @@ bool ZoneDatabase::SaveMerc(Merc *merc) { } void ZoneDatabase::SaveMercBuffs(Merc *merc) { + Buffs_Struct *buffs = merc->GetBuffs(); - std::string errorMessage; - char* Query = 0; - char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; - int BuffCount = 0; - int InsertCount = 0; - uint32 buff_count = merc->GetMaxBuffSlots(); - while(BuffCount < BUFF_COUNT) { - if(buffs[BuffCount].spellid > 0 && buffs[BuffCount].spellid != SPELL_UNKNOWN) { - if(InsertCount == 0) { - // Remove any existing buff saves - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM merc_buffs WHERE MercId = %u", merc->GetMercID()), TempErrorMessageBuffer)) { - errorMessage = std::string(TempErrorMessageBuffer); - safe_delete(Query); - Query = 0; - break; - } - } + // Remove any existing buff saves + std::string query = StringFormat("DELETE FROM merc_buffs WHERE MercId = %u", merc->GetMercID()); + auto results = database.QueryDatabase(query); + if(!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error While Deleting Merc Buffs before save: %s", results.ErrorMessage().c_str()); + return; + } - int IsPersistent = 0; + for (int buffCount = 0; buffCount <= BUFF_COUNT; buffCount++) { + if(buffs[buffCount].spellid == 0 || buffs[buffCount].spellid == SPELL_UNKNOWN) + continue; - if(buffs[BuffCount].persistant_buff) - IsPersistent = 1; - else - IsPersistent = 0; + int IsPersistent = buffs[buffCount].persistant_buff? 1: 0; - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "INSERT INTO merc_buffs (MercId, SpellId, CasterLevel, DurationFormula, " - "TicsRemaining, PoisonCounters, DiseaseCounters, CurseCounters, CorruptionCounters, HitCount, MeleeRune, MagicRune, " - "dot_rune, caston_x, Persistent, caston_y, caston_z, ExtraDIChance) VALUES (%u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %i, %u, %i, %i, %i);", - merc->GetMercID(), buffs[BuffCount].spellid, buffs[BuffCount].casterlevel, spells[buffs[BuffCount].spellid].buffdurationformula, - buffs[BuffCount].ticsremaining, - CalculatePoisonCounters(buffs[BuffCount].spellid) > 0 ? buffs[BuffCount].counters : 0, - CalculateDiseaseCounters(buffs[BuffCount].spellid) > 0 ? buffs[BuffCount].counters : 0, - CalculateCurseCounters(buffs[BuffCount].spellid) > 0 ? buffs[BuffCount].counters : 0, - CalculateCorruptionCounters(buffs[BuffCount].spellid) > 0 ? buffs[BuffCount].counters : 0, - buffs[BuffCount].numhits, buffs[BuffCount].melee_rune, buffs[BuffCount].magic_rune, - buffs[BuffCount].dot_rune, - buffs[BuffCount].caston_x, - IsPersistent, - buffs[BuffCount].caston_y, - buffs[BuffCount].caston_z, - buffs[BuffCount].ExtraDIChance), TempErrorMessageBuffer)) { - errorMessage = std::string(TempErrorMessageBuffer); - safe_delete(Query); - Query = 0; - break; - } - else { - safe_delete(Query); - Query = 0; - InsertCount++; - } - } - - BuffCount++; - } - - if(!errorMessage.empty()) { - LogFile->write(EQEMuLog::Error, "Error Saving Merc Buffs: %s", errorMessage.c_str()); + query = StringFormat("INSERT INTO merc_buffs (MercId, SpellId, CasterLevel, DurationFormula, " + "TicsRemaining, PoisonCounters, DiseaseCounters, CurseCounters, " + "CorruptionCounters, HitCount, MeleeRune, MagicRune, dot_rune, " + "caston_x, Persistent, caston_y, caston_z, ExtraDIChance) " + "VALUES (%u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %i, %u, %i, %i, %i);", + merc->GetMercID(), buffs[buffCount].spellid, buffs[buffCount].casterlevel, + spells[buffs[buffCount].spellid].buffdurationformula, buffs[buffCount].ticsremaining, + CalculatePoisonCounters(buffs[buffCount].spellid) > 0 ? buffs[buffCount].counters : 0, + CalculateDiseaseCounters(buffs[buffCount].spellid) > 0 ? buffs[buffCount].counters : 0, + CalculateCurseCounters(buffs[buffCount].spellid) > 0 ? buffs[buffCount].counters : 0, + CalculateCorruptionCounters(buffs[buffCount].spellid) > 0 ? buffs[buffCount].counters : 0, + buffs[buffCount].numhits, buffs[buffCount].melee_rune, buffs[buffCount].magic_rune, + buffs[buffCount].dot_rune, buffs[buffCount].caston_x, IsPersistent, buffs[buffCount].caston_y, + buffs[buffCount].caston_z, buffs[buffCount].ExtraDIChance); + results = database.QueryDatabase(query); + if(!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error Saving Merc Buffs: %s", results.ErrorMessage().c_str()); + break; + } } } From 17b175daa4e42d4911b0088405a4e9b2109e8386 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 21:46:23 -0700 Subject: [PATCH 33/67] LoadMercBuffs converted to QueryDatabase --- zone/zonedb.cpp | 114 ++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 63 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index fc92c1254..ff5c4e772 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1522,75 +1522,63 @@ void ZoneDatabase::SaveMercBuffs(Merc *merc) { void ZoneDatabase::LoadMercBuffs(Merc *merc) { Buffs_Struct *buffs = merc->GetBuffs(); uint32 max_slots = merc->GetMaxBuffSlots(); - std::string errorMessage; - char* Query = 0; - char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; - MYSQL_RES* DatasetResult; - MYSQL_ROW DataRow; + bool BuffsLoaded = false; - - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT SpellId, CasterLevel, DurationFormula, TicsRemaining, PoisonCounters, DiseaseCounters, CurseCounters, CorruptionCounters, HitCount, MeleeRune, MagicRune, dot_rune, caston_x, Persistent, caston_y, caston_z, ExtraDIChance FROM merc_buffs WHERE MercId = %u", merc->GetMercID()), TempErrorMessageBuffer, &DatasetResult)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - else { - int BuffCount = 0; - - while(DataRow = mysql_fetch_row(DatasetResult)) { - if(BuffCount == BUFF_COUNT) - break; - - buffs[BuffCount].spellid = atoi(DataRow[0]); - buffs[BuffCount].casterlevel = atoi(DataRow[1]); - buffs[BuffCount].ticsremaining = atoi(DataRow[3]); - - if(CalculatePoisonCounters(buffs[BuffCount].spellid) > 0) { - buffs[BuffCount].counters = atoi(DataRow[4]); - } else if(CalculateDiseaseCounters(buffs[BuffCount].spellid) > 0) { - buffs[BuffCount].counters = atoi(DataRow[5]); - } else if(CalculateCurseCounters(buffs[BuffCount].spellid) > 0) { - buffs[BuffCount].counters = atoi(DataRow[6]); - } else if(CalculateCorruptionCounters(buffs[BuffCount].spellid) > 0) { - buffs[BuffCount].counters = atoi(DataRow[7]); - } - buffs[BuffCount].numhits = atoi(DataRow[8]); - buffs[BuffCount].melee_rune = atoi(DataRow[9]); - buffs[BuffCount].magic_rune = atoi(DataRow[10]); - buffs[BuffCount].dot_rune = atoi(DataRow[11]); - buffs[BuffCount].caston_x = atoi(DataRow[12]); - buffs[BuffCount].casterid = 0; - - bool IsPersistent = false; - - if(atoi(DataRow[13])) - IsPersistent = true; - - buffs[BuffCount].caston_y = atoi(DataRow[13]); - buffs[BuffCount].caston_z = atoi(DataRow[14]); - buffs[BuffCount].ExtraDIChance = atoi(DataRow[15]); - - buffs[BuffCount].persistant_buff = IsPersistent; - - BuffCount++; - } - - mysql_free_result(DatasetResult); - - BuffsLoaded = true; + std::string query = StringFormat("SELECT SpellId, CasterLevel, DurationFormula, TicsRemaining, " + "PoisonCounters, DiseaseCounters, CurseCounters, CorruptionCounters, " + "HitCount, MeleeRune, MagicRune, dot_rune, caston_x, Persistent, " + "caston_y, caston_z, ExtraDIChance FROM merc_buffs WHERE MercId = %u", + merc->GetMercID()); + auto results = database.QueryDatabase(query); + if(!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error Loading Merc Buffs: %s", results.ErrorMessage().c_str()); + return; } - safe_delete_array(Query); + int buffCount = 0; + for (auto row = results.begin(); row != results.end(); ++row, ++buffCount) { + if(buffCount == BUFF_COUNT) + break; - if(errorMessage.empty() && BuffsLoaded) { - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM merc_buffs WHERE MercId = %u", merc->GetMercID()), TempErrorMessageBuffer)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - safe_delete_array(Query); - } + buffs[buffCount].spellid = atoi(row[0]); + buffs[buffCount].casterlevel = atoi(row[1]); + buffs[buffCount].ticsremaining = atoi(row[3]); + + if(CalculatePoisonCounters(buffs[buffCount].spellid) > 0) + buffs[buffCount].counters = atoi(row[4]); + + if(CalculateDiseaseCounters(buffs[buffCount].spellid) > 0) + buffs[buffCount].counters = atoi(row[5]); + + if(CalculateCurseCounters(buffs[buffCount].spellid) > 0) + buffs[buffCount].counters = atoi(row[6]); + + if(CalculateCorruptionCounters(buffs[buffCount].spellid) > 0) + buffs[buffCount].counters = atoi(row[7]); + + buffs[buffCount].numhits = atoi(row[8]); + buffs[buffCount].melee_rune = atoi(row[9]); + buffs[buffCount].magic_rune = atoi(row[10]); + buffs[buffCount].dot_rune = atoi(row[11]); + buffs[buffCount].caston_x = atoi(row[12]); + buffs[buffCount].casterid = 0; + + bool IsPersistent = atoi(row[13])? true: false; + + buffs[buffCount].caston_y = atoi(row[13]); + buffs[buffCount].caston_z = atoi(row[14]); + buffs[buffCount].ExtraDIChance = atoi(row[15]); + + buffs[buffCount].persistant_buff = IsPersistent; + + } + + query = StringFormat("DELETE FROM merc_buffs WHERE MercId = %u", merc->GetMercID()); + results = database.QueryDatabase(query); + if(!results.Success()) + LogFile->write(EQEMuLog::Error, "Error Loading Merc Buffs: %s", results.ErrorMessage().c_str()); - if(!errorMessage.empty()) { - LogFile->write(EQEMuLog::Error, "Error Loading Merc Buffs: %s", errorMessage.c_str()); - } } bool ZoneDatabase::DeleteMerc(uint32 merc_id) { From 2fd2cd4cece5f0df370278f716b3aab3539a9b39 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 21:54:28 -0700 Subject: [PATCH 34/67] DeleteMerc converted to QueryDatabase --- zone/zonedb.cpp | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index ff5c4e772..2bbc3f840 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1582,41 +1582,27 @@ void ZoneDatabase::LoadMercBuffs(Merc *merc) { } bool ZoneDatabase::DeleteMerc(uint32 merc_id) { - std::string errorMessage; - bool Result = false; - int TempCounter = 0; - if(merc_id > 0) { - char* Query = 0; - char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; + if(merc_id == 0) + return false; - // TODO: These queries need to be ran together as a transaction.. ie, if one or more fail then they all will fail to commit to the database. + bool firstQueryWorked = false; + // TODO: These queries need to be ran together as a transaction.. ie, + // if one or more fail then they all will fail to commit to the database. + std::string query = StringFormat("DELETE FROM merc_buffs WHERE MercID = '%u'", merc_id); + auto results = database.QueryDatabase(query); + if(!results.Success()) + LogFile->write(EQEMuLog::Error, "Error Deleting Merc: %s", results.ErrorMessage().c_str()); + else + firstQueryWorked = true; - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM merc_buffs WHERE MercID = '%u'", merc_id), TempErrorMessageBuffer)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - else - TempCounter++; + query = StringFormat("DELETE FROM mercs WHERE MercID = '%u'", merc_id); + if(!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error Deleting Merc: %s", results.ErrorMessage().c_str()); + return false; + } - safe_delete_array(Query); - - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM mercs WHERE MercID = '%u'", merc_id), TempErrorMessageBuffer)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - else - TempCounter++; - - safe_delete_array(Query); - - if(TempCounter == 2) - Result = true; - } - - if(!errorMessage.empty()) { - LogFile->write(EQEMuLog::Error, "Error Deleting Merc: %s", errorMessage.c_str()); - } - - return Result; + return firstQueryWorked; } void ZoneDatabase::LoadMercEquipment(Merc *merc) { From 2028a5846ce3ddada170a7cef93544cad1e47af7 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 22:00:00 -0700 Subject: [PATCH 35/67] LoadMercEquipment converted to QueryDatabase --- zone/zonedb.cpp | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 2bbc3f840..25dc8f15c 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1606,38 +1606,31 @@ bool ZoneDatabase::DeleteMerc(uint32 merc_id) { } void ZoneDatabase::LoadMercEquipment(Merc *merc) { - std::string errorMessage; - char* Query = 0; - char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; - MYSQL_RES* DatasetResult; - MYSQL_ROW DataRow; - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT item_id FROM merc_inventory WHERE merc_subtype_id = (SELECT merc_subtype_id FROM merc_subtypes WHERE class_id = '%u' AND tier_id = '%u') AND min_level <= %u AND max_level >= %u", merc->GetClass(), merc->GetTierID(), merc->GetLevel(), merc->GetLevel()), TempErrorMessageBuffer, &DatasetResult)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - else { - int itemCount = 0; - - while(DataRow = mysql_fetch_row(DatasetResult)) { - if (itemCount == EmuConstants::EQUIPMENT_SIZE) - break; - - if(atoi(DataRow[0]) > 0) { - merc->AddItem(itemCount, atoi(DataRow[0])); - - itemCount++; - } - } - - mysql_free_result(DatasetResult); + std::string query = StringFormat("SELECT item_id FROM merc_inventory " + "WHERE merc_subtype_id = (" + "SELECT merc_subtype_id FROM merc_subtypes " + "WHERE class_id = '%u' AND tier_id = '%u') " + "AND min_level <= %u AND max_level >= %u", + merc->GetClass(), merc->GetTierID(), + merc->GetLevel(), merc->GetLevel()); + auto results = database.QueryDatabase(query); + if(!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error Loading Merc Inventory: %s", results.ErrorMessage().c_str()); + return; } - safe_delete_array(Query); - Query = 0; + int itemCount = 0; + for(auto row = results.begin(); row != results.end(); ++row) { + if (itemCount == EmuConstants::EQUIPMENT_SIZE) + break; - if(!errorMessage.empty()) { - LogFile->write(EQEMuLog::Error, "Error Loading Merc Inventory: %s", errorMessage.c_str()); - } + if(atoi(row[0]) == 0) + continue; + + merc->AddItem(itemCount, atoi(row[0])); + itemCount++; + } } uint8 ZoneDatabase::GetGridType(uint32 grid, uint32 zoneid ) { From 2df66bd625c7a563559c84b0bb0d963df35ad804 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 22:04:40 -0700 Subject: [PATCH 36/67] GetGridType converted to QueryDatabase --- zone/zonedb.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 25dc8f15c..d28719134 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1634,23 +1634,20 @@ void ZoneDatabase::LoadMercEquipment(Merc *merc) { } uint8 ZoneDatabase::GetGridType(uint32 grid, uint32 zoneid ) { - char *query = 0; - char errbuf[MYSQL_ERRMSG_SIZE]; - MYSQL_RES *result; - MYSQL_ROW row; - int type = 0; - if (RunQuery(query, MakeAnyLenString(&query,"SELECT type from grid where id = %i and zoneid = %i",grid,zoneid),errbuf,&result)) { - safe_delete_array(query); - if (mysql_num_rows(result) == 1) { - row = mysql_fetch_row(result); - type = atoi( row[0] ); - } - mysql_free_result(result); - } else { - std::cerr << "Error in GetGridType query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); + + std::string query = StringFormat("SELECT type FROM grid WHERE id = %i AND zoneid = %i", grid, zoneid); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in GetGridType query '" << query << "' " << results.ErrorMessage() << std::endl; + return 0; } - return type; + + if (results.RowCount() != 1) + return 0; + + auto row = results.begin(); + + return atoi(row[0]); } From e25f64d03b6ed9a27762e94cc4566d927c2a42e2 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 22:06:56 -0700 Subject: [PATCH 37/67] SaveMerchantTemp converted to QueryDatabase --- zone/zonedb.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index d28719134..6c291bc00 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1650,17 +1650,15 @@ uint8 ZoneDatabase::GetGridType(uint32 grid, uint32 zoneid ) { return atoi(row[0]); } - - void ZoneDatabase::SaveMerchantTemp(uint32 npcid, uint32 slot, uint32 item, uint32 charges){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - if (!RunQuery(query, MakeAnyLenString(&query, "replace into merchantlist_temp (npcid,slot,itemid,charges) values(%d,%d,%d,%d)", npcid, slot, item, charges), errbuf)) { - std::cerr << "Error in SaveMerchantTemp query '" << query << "' " << errbuf << std::endl; - } - safe_delete_array(query); + std::string query = StringFormat("REPLACE INTO merchantlist_temp (npcid, slot, itemid, charges) " + "VALUES(%d, %d, %d, %d)", npcid, slot, item, charges); + auto results = QueryDatabase(query); + if (!results.Success()) + std::cerr << "Error in SaveMerchantTemp query '" << query << "' " << results.ErrorMessage() << std::endl; } + void ZoneDatabase::DeleteMerchantTemp(uint32 npcid, uint32 slot){ char errbuf[MYSQL_ERRMSG_SIZE]; char *query = 0; From 909ca5440dd149b3cd1449be534ef0c52d230ef5 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 22:11:14 -0700 Subject: [PATCH 38/67] UpdateZoneSafeCoords converted to QueryDatabase --- zone/zonedb.cpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 6c291bc00..fd1b1649c 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1660,31 +1660,21 @@ void ZoneDatabase::SaveMerchantTemp(uint32 npcid, uint32 slot, uint32 item, uint } void ZoneDatabase::DeleteMerchantTemp(uint32 npcid, uint32 slot){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - if (!RunQuery(query, MakeAnyLenString(&query, "delete from merchantlist_temp where npcid=%d and slot=%d", npcid, slot), errbuf)) { - std::cerr << "Error in DeleteMerchantTemp query '" << query << "' " << errbuf << std::endl; - } - safe_delete_array(query); + std::string query = StringFormat("DELETE FROM merchantlist_temp WHERE npcid=%d AND slot=%d", npcid, slot); + auto results = QueryDatabase(query); + if (!results.Success()) + std::cerr << "Error in DeleteMerchantTemp query '" << query << "' " << results.ErrorMessage() << std::endl; + } - bool ZoneDatabase::UpdateZoneSafeCoords(const char* zonename, float x=0, float y=0, float z=0) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - uint32 affected_rows = 0; - if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE zone SET safe_x='%f', safe_y='%f', safe_z='%f' WHERE short_name='%s';", x, y, z, zonename), errbuf, 0, &affected_rows)) { - safe_delete_array(query); + std::string query = StringFormat("UPDATE zone SET safe_x='%f', safe_y='%f', safe_z='%f' " + "WHERE short_name='%s';", x, y, z, zonename); + auto results = QueryDatabase(query); + if (!results.Success() || results.RowsAffected() == 0) return false; - } - safe_delete_array(query); - - if (affected_rows == 0) - { - return false; - } return true; } From babaff1985d45444c2e71d68efbe5bb09592fa67 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 22:14:40 -0700 Subject: [PATCH 39/67] GetUseCFGSafeCoords converted to QueryDatabase --- zone/zonedb.cpp | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index fd1b1649c..ea709b3c9 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1679,40 +1679,21 @@ bool ZoneDatabase::UpdateZoneSafeCoords(const char* zonename, float x=0, float y return true; } - uint8 ZoneDatabase::GetUseCFGSafeCoords() { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT value FROM variables WHERE varname='UseCFGSafeCoords'"), errbuf, &result)) { - safe_delete_array(query); - if (mysql_num_rows(result) == 1) - { - row = mysql_fetch_row(result); - - uint8 usecoords = atoi(row[0]); - mysql_free_result(result); - return usecoords; - } - else - { - mysql_free_result(result); - return 0; - } - mysql_free_result(result); - } - else - { - - std::cerr << "Error in GetUseCFGSafeCoords query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); - return false; + const std::string query = "SELECT value FROM variables WHERE varname='UseCFGSafeCoords'"; + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in GetUseCFGSafeCoords query '" << query << "' " << results.ErrorMessage() << std::endl; + return 0; } - return 0; + if (results.RowCount() != 1) + return 0; + auto row = results.begin(); + + return atoi(row[0]); } From fe600bb0844448e6baa50b98963c6b8c89a61e49 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 23:07:19 -0700 Subject: [PATCH 40/67] Removed Get/SetServerFilters, unused and unsupported --- zone/zonedb.cpp | 80 ------------------------------------------------- zone/zonedb.h | 2 -- 2 files changed, 82 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index ea709b3c9..0a10e1401 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1696,86 +1696,6 @@ uint8 ZoneDatabase::GetUseCFGSafeCoords() return atoi(row[0]); } - -uint32 ZoneDatabase::GetServerFilters(char* name, ServerSideFilters_Struct *ssfs) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - - MYSQL_ROW row; - - - unsigned long* lengths; - - if (RunQuery(query, MakeAnyLenString(&query, "SELECT serverfilters FROM account WHERE name='%s'", name), errbuf, &result)) { - safe_delete_array(query); - if (mysql_num_rows(result) == 1) { - row = mysql_fetch_row(result); - lengths = mysql_fetch_lengths(result); - if (lengths[0] == sizeof(ServerSideFilters_Struct)) { - memcpy(ssfs, row[0], sizeof(ServerSideFilters_Struct)); - } - else { - std::cerr << "Player profile length mismatch in ServerSideFilters" << std::endl; - mysql_free_result(result); - return 0; - } - } - else { - mysql_free_result(result); - return 0; - - } - uint32 len = lengths[0]; - mysql_free_result(result); - return len; - } - else { - std::cerr << "Error in ServerSideFilters query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); - return 0; - } - - return 0; -} - -bool ZoneDatabase::SetServerFilters(char* name, ServerSideFilters_Struct *ssfs) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char query[256+sizeof(ServerSideFilters_Struct)*2+1]; - char* end = query; - - //if (strlen(name) > 15) - // return false; - - /*for (int i=0; i 'z') && - (name[i] < 'A' || name[i] > 'Z') && - (name[i] < '0' || name[i] > '9')) - return 0; -}*/ - - - end += sprintf(end, "UPDATE account SET serverfilters="); - *end++ = '\''; - end += DoEscapeString(end, (char*)ssfs, sizeof(ServerSideFilters_Struct)); - *end++ = '\''; - end += sprintf(end," WHERE name='%s'", name); - - uint32 affected_rows = 0; - if (!RunQuery(query, (uint32) (end - query), errbuf, 0, &affected_rows)) { - std::cerr << "Error in SetServerSideFilters query " << errbuf << std::endl; - return false; - } - - if (affected_rows == 0) { - return false; - } - - return true; -} - - //New functions for timezone uint32 ZoneDatabase::GetZoneTZ(uint32 zoneid, uint32 version) { char errbuf[MYSQL_ERRMSG_SIZE]; diff --git a/zone/zonedb.h b/zone/zonedb.h index 22aa0eba4..3a7881d44 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -246,8 +246,6 @@ public: /* * General Character Related Stuff */ - bool SetServerFilters(char* name, ServerSideFilters_Struct *ssfs); - uint32 GetServerFilters(char* name, ServerSideFilters_Struct *ssfs); bool GetAccountInfoForLogin(uint32 account_id, int16* admin = 0, char* account_name = 0, uint32* lsaccountid = 0, uint8* gmspeed = 0, bool* revoked = 0, bool* gmhideme = 0); bool GetAccountInfoForLogin_result(MYSQL_RES* result, int16* admin = 0, char* account_name = 0, From 8525d819c1e9c81dad2933b6c1f97fcd13cb775f Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 23:13:59 -0700 Subject: [PATCH 41/67] GetZoneTZ converted to QueryDatabase --- zone/zonedb.cpp | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 0a10e1401..7718dbda4 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1698,27 +1698,21 @@ uint8 ZoneDatabase::GetUseCFGSafeCoords() //New functions for timezone uint32 ZoneDatabase::GetZoneTZ(uint32 zoneid, uint32 version) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT timezone FROM zone WHERE zoneidnumber=%i AND (version=%i OR version=0) ORDER BY version DESC", zoneid, version), errbuf, &result)) - { - safe_delete_array(query); - if (mysql_num_rows(result) > 0) { - row = mysql_fetch_row(result); - uint32 tmp = atoi(row[0]); - mysql_free_result(result); - return tmp; - } - mysql_free_result(result); - } - else { - std::cerr << "Error in GetZoneTZ query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); - } - return 0; + std::string query = StringFormat("SELECT timezone FROM zone WHERE zoneidnumber = %i " + "AND (version = %i OR version = 0) ORDER BY version DESC", + zoneid, version); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in GetZoneTZ query '" << query << "' " << results.ErrorMessage() << std::endl; + return 0; + } + + if (results.RowCount() == 0) + return 0; + + auto row = results.begin(); + return atoi(row[0]); } bool ZoneDatabase::SetZoneTZ(uint32 zoneid, uint32 version, uint32 tz) { From e79747c91995511a5872dae49930846857b984aa Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 20 Aug 2014 23:26:41 -0700 Subject: [PATCH 42/67] SetZoneTZ converted to QueryDatabase --- zone/zonedb.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 7718dbda4..b76fd6c5f 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1716,27 +1716,18 @@ uint32 ZoneDatabase::GetZoneTZ(uint32 zoneid, uint32 version) { } bool ZoneDatabase::SetZoneTZ(uint32 zoneid, uint32 version, uint32 tz) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - uint32 affected_rows = 0; - if (RunQuery(query, MakeAnyLenString(&query, "UPDATE zone SET timezone=%i WHERE zoneidnumber=%i AND version=%i", tz, zoneid, version), errbuf, 0, &affected_rows)) { - safe_delete_array(query); - - if (affected_rows == 1) - return true; - else - return false; - } - else { - std::cerr << "Error in SetZoneTZ query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); + std::string query = StringFormat("UPDATE zone SET timezone = %i " + "WHERE zoneidnumber = %i AND version = %i", + tz, zoneid, version); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in SetZoneTZ query '" << query << "' " << results.ErrorMessage() << std::endl; return false; - } + } - return false; + return results.RowsAffected() == 1; } -//End new timezone functions. /* solar: this is never actually called, client_process starts an async query From 8441ffda3130e90ce073037b6b5e88044677335c Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 11:52:15 -0700 Subject: [PATCH 43/67] GetAccountInfoForLogin removed, unused, unsupported --- zone/zonedb.cpp | 25 ------------------------- zone/zonedb.h | 2 -- 2 files changed, 27 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index b76fd6c5f..b7e4c5339 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1729,31 +1729,6 @@ bool ZoneDatabase::SetZoneTZ(uint32 zoneid, uint32 version, uint32 tz) { return results.RowsAffected() == 1; } -/* - solar: this is never actually called, client_process starts an async query - instead and uses GetAccountInfoForLogin_result to process it.. - */ -bool ZoneDatabase::GetAccountInfoForLogin(uint32 account_id, int16* admin, char* account_name, uint32* lsaccountid, uint8* gmspeed, bool* revoked,bool* gmhideme) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - - if (RunQuery(query, MakeAnyLenString(&query, "SELECT status, name, lsaccount_id, gmspeed, revoked, hideme FROM account WHERE id=%i", account_id), errbuf, &result)) { - safe_delete_array(query); - bool ret = GetAccountInfoForLogin_result(result, admin, account_name, lsaccountid, gmspeed, revoked,gmhideme); - mysql_free_result(result); - return ret; - } - else - { - std::cerr << "Error in GetAccountInfoForLogin query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); - return false; - } - - return false; -} - void ZoneDatabase::RefreshGroupFromDB(Client *c){ if(!c){ return; diff --git a/zone/zonedb.h b/zone/zonedb.h index 3a7881d44..ae58bb596 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -246,8 +246,6 @@ public: /* * General Character Related Stuff */ - bool GetAccountInfoForLogin(uint32 account_id, int16* admin = 0, char* account_name = 0, - uint32* lsaccountid = 0, uint8* gmspeed = 0, bool* revoked = 0, bool* gmhideme = 0); bool GetAccountInfoForLogin_result(MYSQL_RES* result, int16* admin = 0, char* account_name = 0, uint32* lsaccountid = 0, uint8* gmspeed = 0, bool* revoked = 0, bool* gmhideme = nullptr, uint32* account_creation = 0); From 351a7a52fe50badf8d20e28aad160c8d865803bc Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 12:01:22 -0700 Subject: [PATCH 44/67] GetCharacterInfoForLogin removed, unused, unsupported --- zone/zonedb.cpp | 33 --------------------------------- zone/zonedb.h | 4 ---- 2 files changed, 37 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index b7e4c5339..ee7d3a62f 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -785,39 +785,6 @@ void ZoneDatabase::UpdateBuyLine(uint32 CharID, uint32 BuySlot, uint32 Quantity) } -bool ZoneDatabase::GetCharacterInfoForLogin(const char* name, uint32* character_id, -char* current_zone, PlayerProfile_Struct* pp, Inventory* inv, ExtendedProfile_Struct *ext, -uint32* pplen, uint32* guilddbid, uint8* guildrank, -uint8 *class_, uint8 *level, bool *LFP, bool *LFG, uint8 *NumXTargets, uint8 *firstlogon) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - uint32 querylen; - MYSQL_RES *result; - - bool ret = false; - - //DO NOT FORGET TO EDIT Client::Handle_Connect_OP_ZoneEntry if you change this. - - if (character_id && *character_id) { - // searching by ID should be a lil bit faster - querylen = MakeAnyLenString(&query, "SELECT id,profile,zonename,x,y,z,guild_id,rank,extprofile,class,level,lfp,lfg,instanceid,xtargets,firstlogon FROM character_ LEFT JOIN guild_members ON id=char_id WHERE id=%i", *character_id); - } - else { - querylen = MakeAnyLenString(&query, "SELECT id,profile,zonename,x,y,z,guild_id,rank,extprofile,class,level,lfp,lfg,instanceid,xtargets,firstlogon FROM character_ LEFT JOIN guild_members ON id=char_id WHERE name='%s'", name); - } - - if (RunQuery(query, querylen, errbuf, &result)) { - ret = GetCharacterInfoForLogin_result(result, character_id, current_zone, pp, inv, ext, pplen, guilddbid, guildrank, class_, level, LFP, LFG, NumXTargets, firstlogon); - mysql_free_result(result); - } - else { - LogFile->write(EQEMuLog::Error, "GetCharacterInfoForLogin query '%s' %s", query, errbuf); - } - - safe_delete_array(query); - return ret; -} - #define StructDist(in, f1, f2) (uint32(&in->f2)-uint32(&in->f1)) // Process results of GetCharacterInfoForLogin() diff --git a/zone/zonedb.h b/zone/zonedb.h index ae58bb596..cab3e84a9 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -253,10 +253,6 @@ public: PlayerProfile_Struct* pp = 0, Inventory* inv = 0, ExtendedProfile_Struct *ext = 0, uint32* pplen = 0, uint32* guilddbid = 0, uint8* guildrank = 0, uint8 *class_= 0, uint8 *level = 0, bool *LFP = 0, bool *LFG = 0, uint8 *NumXTargets = 0, uint8* firstlogon = 0); - bool GetCharacterInfoForLogin(const char* name, uint32* character_id = 0, char* current_zone = 0, - PlayerProfile_Struct* pp = 0, Inventory* inv = 0, ExtendedProfile_Struct *ext = 0, uint32* pplen = 0, - uint32* guilddbid = 0, uint8* guildrank = 0, uint8 *class_ = 0, uint8 *level = 0, bool *LFP = 0, - bool *LFG = 0, uint8 *NumXTargets = 0, uint8* firstlogon = 0); void SaveBuffs(Client *c); void LoadBuffs(Client *c); void LoadPetInfo(Client *c); From fbefad9eafbb17cfe88f8ce9b204c0cd1c43db66 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 12:25:32 -0700 Subject: [PATCH 45/67] RefreshGroupFromDB converted to QueryDatabase --- zone/zonedb.cpp | 73 ++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index ee7d3a62f..6a4633dc9 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1696,62 +1696,55 @@ bool ZoneDatabase::SetZoneTZ(uint32 zoneid, uint32 version, uint32 tz) { return results.RowsAffected() == 1; } -void ZoneDatabase::RefreshGroupFromDB(Client *c){ - if(!c){ +void ZoneDatabase::RefreshGroupFromDB(Client *client){ + if(!client) return; - } - Group *g = c->GetGroup(); + Group *group = client->GetGroup(); - if(!g){ + if(!group) return; - } EQApplicationPacket* outapp = new EQApplicationPacket(OP_GroupUpdate,sizeof(GroupUpdate2_Struct)); GroupUpdate2_Struct* gu = (GroupUpdate2_Struct*)outapp->pBuffer; gu->action = groupActUpdate; - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - strcpy(gu->yourname, c->GetName()); - GetGroupLeadershipInfo(g->GetID(), gu->leadersname, nullptr, nullptr, nullptr, nullptr, &gu->leader_aas); - gu->NPCMarkerID = g->GetNPCMarkerID(); + strcpy(gu->yourname, client->GetName()); + GetGroupLeadershipInfo(group->GetID(), gu->leadersname, nullptr, nullptr, nullptr, nullptr, &gu->leader_aas); + gu->NPCMarkerID = group->GetNPCMarkerID(); int index = 0; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT name from group_id where groupid=%d", g->GetID()), errbuf, &result)) { - while((row = mysql_fetch_row(result))){ - if(index < 6){ - if(strcmp(c->GetName(), row[0]) != 0){ - strcpy(gu->membername[index], row[0]); - index++; - } - } - } - mysql_free_result(result); - } - else - { - printf("Error in group update query: %s\n", errbuf); - } - safe_delete_array(query); - c->QueuePacket(outapp); + std::string query = StringFormat("SELECT name FROM group_id WHERE groupid = %d", group->GetID()); + auto results = QueryDatabase(query); + if (!results.Success()) + printf("Error in group update query: %s\n", results.ErrorMessage().c_str()); + else + for (auto row = results.begin(); row != results.end(); ++row) { + if(index >= 6) + continue; + + if(strcmp(client->GetName(), row[0]) == 0) + continue; + + strcpy(gu->membername[index], row[0]); + index++; + } + + client->QueuePacket(outapp); safe_delete(outapp); - if(c->GetClientVersion() >= EQClientSoD) { - g->NotifyMainTank(c, 1); - g->NotifyPuller(c, 1); + if(client->GetClientVersion() >= EQClientSoD) { + group->NotifyMainTank(client, 1); + group->NotifyPuller(client, 1); } - g->NotifyMainAssist(c, 1); - - g->NotifyMarkNPC(c); - g->NotifyAssistTarget(c); - g->NotifyTankTarget(c); - g->NotifyPullerTarget(c); - g->SendMarkedNPCsToMember(c); + group->NotifyMainAssist(client, 1); + group->NotifyMarkNPC(client); + group->NotifyAssistTarget(client); + group->NotifyTankTarget(client); + group->NotifyPullerTarget(client); + group->SendMarkedNPCsToMember(client); } From 0ece5bf178d554023f7a948293d1dd84fff38541 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 12:30:06 -0700 Subject: [PATCH 46/67] GroupCount converted to QueryDatabase --- zone/zonedb.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 6a4633dc9..3bfec9adf 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1748,21 +1748,21 @@ void ZoneDatabase::RefreshGroupFromDB(Client *client){ } -uint8 ZoneDatabase::GroupCount(uint32 groupid){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - uint8 count=0; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT count(charid) FROM group_id WHERE groupid=%d", groupid), errbuf, &result)) { - if((row = mysql_fetch_row(result))!=nullptr) - count = atoi(row[0]); - mysql_free_result(result); - } else { - LogFile->write(EQEMuLog::Error, "Error in ZoneDatabase::GroupCount query '%s': %s", query, errbuf); - } - safe_delete_array(query); - return count; +uint8 ZoneDatabase::GroupCount(uint32 groupid) { + + std::string query = StringFormat("SELECT count(charid) FROM group_id WHERE groupid = %d", groupid); + auto results = QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in ZoneDatabase::GroupCount query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); + return 0; + } + + if (results.RowCount() == 0) + return 0; + + auto row = results.begin(); + + return atoi(row[0]); } uint8 ZoneDatabase::RaidGroupCount(uint32 raidid, uint32 groupid) From a3bde6e1f183c10aa310b9830d1826c8c27cbd22 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 12:35:33 -0700 Subject: [PATCH 47/67] RaidGroupCount converted to QueryDatabase --- zone/zonedb.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 3bfec9adf..447d1f94e 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1765,22 +1765,23 @@ uint8 ZoneDatabase::GroupCount(uint32 groupid) { return atoi(row[0]); } - uint8 ZoneDatabase::RaidGroupCount(uint32 raidid, uint32 groupid) - { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - uint8 count=0; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT count(charid) FROM raid_members WHERE raidid=%d AND groupid=%d;", raidid, groupid), errbuf, &result)) { - if((row = mysql_fetch_row(result))!=nullptr) - count = atoi(row[0]); - mysql_free_result(result); - } else { - LogFile->write(EQEMuLog::Error, "Error in ZoneDatabase::RaidGroupCount query '%s': %s", query, errbuf); - } - safe_delete_array(query); - return count; +uint8 ZoneDatabase::RaidGroupCount(uint32 raidid, uint32 groupid) { + + std::string query = StringFormat("SELECT count(charid) FROM raid_members " + "WHERE raidid = %d AND groupid = %d;", raidid, groupid); + auto results = QueryDatabase(query); + + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in ZoneDatabase::RaidGroupCount query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); + return 0; + } + + if (results.RowCount() == 0) + return 0; + + auto row = results.begin(); + + return atoi(row[0]); } int32 ZoneDatabase::GetBlockedSpellsCount(uint32 zoneid) From 5839921e08fea6334794b29092491b5aa1e37f3a Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 12:39:38 -0700 Subject: [PATCH 48/67] GetBlockedSpellsCount converted to QueryDatabase --- zone/zonedb.cpp | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 447d1f94e..e0abc51c5 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1786,30 +1786,19 @@ uint8 ZoneDatabase::RaidGroupCount(uint32 raidid, uint32 groupid) { int32 ZoneDatabase::GetBlockedSpellsCount(uint32 zoneid) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - - MYSQL_RES *result; - MYSQL_ROW row; - query = new char[256]; - sprintf(query, "SELECT count(*) FROM blocked_spells WHERE zoneid=%d", zoneid); - if (RunQuery(query, strlen(query), errbuf, &result)) { - safe_delete_array(query); - row = mysql_fetch_row(result); - if (row != nullptr && row[0] != 0) { - int32 ret = atoi(row[0]); - mysql_free_result(result); - return ret; - } - mysql_free_result(result); - } - else { - std::cerr << "Error in GetBlockedSpellsCount query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); + std::string query = StringFormat("SELECT count(*) FROM blocked_spells WHERE zoneid = %d", zoneid); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in GetBlockedSpellsCount query '" << query << "' " << results.ErrorMessage() << std::endl; return -1; } - return -1; + if (results.RowCount() == 0) + return -1; + + auto row = results.begin(); + + return atoi(row[0]); } bool ZoneDatabase::LoadBlockedSpells(int32 blockedSpellsCount, ZoneSpellsBlocked* into, uint32 zoneid) From 699c8cc1eba5b230f03668e52262be85aecd30da Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 12:46:52 -0700 Subject: [PATCH 49/67] LoadBlockedSpells converted to QueryDatabase --- zone/zonedb.cpp | 64 ++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index e0abc51c5..0cd0aae9b 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1805,42 +1805,36 @@ bool ZoneDatabase::LoadBlockedSpells(int32 blockedSpellsCount, ZoneSpellsBlocked { LogFile->write(EQEMuLog::Status, "Loading Blocked Spells from database..."); - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - - MakeAnyLenString(&query, "SELECT id, spellid, type, x, y, z, x_diff, y_diff, z_diff, message " - "FROM blocked_spells WHERE zoneid=%d ORDER BY id asc", zoneid); - if (RunQuery(query, strlen(query), errbuf, &result)) { - safe_delete_array(query); - int32 r; - for(r = 0; (row = mysql_fetch_row(result)); r++) { - if(r >= blockedSpellsCount) { - std::cerr << "Error, Blocked Spells Count of " << blockedSpellsCount << " exceeded." << std::endl; - break; - } - memset(&into[r], 0, sizeof(ZoneSpellsBlocked)); - if(row){ - into[r].spellid = atoi(row[1]); - into[r].type = atoi(row[2]); - into[r].x = atof(row[3]); - into[r].y = atof(row[4]); - into[r].z = atof(row[5]); - into[r].xdiff = atof(row[6]); - into[r].ydiff = atof(row[7]); - into[r].zdiff = atof(row[8]); - strn0cpy(into[r].message, row[9], 255); - } - } - mysql_free_result(result); - } - else - { - std::cerr << "Error in LoadBlockedSpells query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); + std::string query = StringFormat("SELECT id, spellid, type, x, y, z, x_diff, y_diff, z_diff, message " + "FROM blocked_spells WHERE zoneid = %d ORDER BY id ASC", zoneid); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in LoadBlockedSpells query '" << query << "' " << results.ErrorMessage() << std::endl; return false; - } + } + + if (results.RowCount() == 0) + return true; + + int32 index = 0; + for(auto row = results.begin(); row != results.end(); ++row, ++index) { + if(index >= blockedSpellsCount) { + std::cerr << "Error, Blocked Spells Count of " << blockedSpellsCount << " exceeded." << std::endl; + break; + } + + memset(&into[index], 0, sizeof(ZoneSpellsBlocked)); + into[index].spellid = atoi(row[1]); + into[index].type = atoi(row[2]); + into[index].x = atof(row[3]); + into[index].y = atof(row[4]); + into[index].z = atof(row[5]); + into[index].xdiff = atof(row[6]); + into[index].ydiff = atof(row[7]); + into[index].zdiff = atof(row[8]); + strn0cpy(into[index].message, row[9], 255); + } + return true; } From 765eaf7f4f69107b4b6a5a52ceab87298305fcff Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 12:51:09 -0700 Subject: [PATCH 50/67] getZoneShutDownDelay converted to QueryDatabase --- zone/zonedb.cpp | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 0cd0aae9b..815e0fa04 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1840,33 +1840,23 @@ bool ZoneDatabase::LoadBlockedSpells(int32 blockedSpellsCount, ZoneSpellsBlocked int ZoneDatabase::getZoneShutDownDelay(uint32 zoneID, uint32 version) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; + std::string query = StringFormat("SELECT shutdowndelay FROM zone " + "WHERE zoneidnumber = %i AND (version=%i OR version=0) " + "ORDER BY version DESC", zoneID, version); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in getZoneShutDownDelay query '" << query << "' " << results.ErrorMessage().c_str() << std::endl; + return (RuleI(Zone, AutoShutdownDelay)); + } - if (RunQuery(query, MakeAnyLenString(&query, "SELECT shutdowndelay FROM zone WHERE zoneidnumber=%i AND (version=%i OR version=0) ORDER BY version DESC", zoneID, version), errbuf, &result)) - { - if (mysql_num_rows(result) > 0) { - row = mysql_fetch_row(result); - int retVal = atoi(row[0]); + if (results.RowCount() == 0) { + std::cerr << "Error in getZoneShutDownDelay no result '" << query << "' " << std::endl; + return (RuleI(Zone, AutoShutdownDelay)); + } - mysql_free_result(result); - safe_delete_array(query); - return (retVal); - } - else { - std::cerr << "Error in getZoneShutDownDelay no result '" << query << "' " << errbuf << std::endl; - mysql_free_result(result); - safe_delete_array(query); - return (RuleI(Zone, AutoShutdownDelay)); - } - } - else { - std::cerr << "Error in getZoneShutDownDelay query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); - } - return (RuleI(Zone, AutoShutdownDelay)); + auto row = results.begin(); + + return atoi(row[0]); } uint32 ZoneDatabase::GetKarma(uint32 acct_id) From e8c92c6fcc1f29be38b97726243173ef07d7641a Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 13:06:33 -0700 Subject: [PATCH 51/67] GetKarma converted to QueryDatabase --- zone/zonedb.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 815e0fa04..dd4960f60 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1861,27 +1861,14 @@ int ZoneDatabase::getZoneShutDownDelay(uint32 zoneID, uint32 version) uint32 ZoneDatabase::GetKarma(uint32 acct_id) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - uint32 ret_val = 0; - - if (!RunQuery(query,MakeAnyLenString(&query, "select `karma` from `account` where `id`='%i' limit 1", - acct_id),errbuf,&result)) - { - safe_delete_array(query); + std::string query = StringFormat("SELECT `karma` FROM `account` WHERE `id` = '%i' LIMIT 1", acct_id); + auto results = QueryDatabase(query); + if (!results.Success()) return 0; - } - safe_delete_array(query); - row = mysql_fetch_row(result); + auto row = results.begin(); - ret_val = atoi(row[0]); - - mysql_free_result(result); - - return ret_val; + return atoi(row[0]); } void ZoneDatabase::UpdateKarma(uint32 acct_id, uint32 amount) From 46c9fe46e946018183dafc6826a0ed989fc39c9b Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 13:08:57 -0700 Subject: [PATCH 52/67] UpdateKarma converted to QueryDatabase --- zone/zonedb.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index dd4960f60..80ec01038 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1873,16 +1873,11 @@ uint32 ZoneDatabase::GetKarma(uint32 acct_id) void ZoneDatabase::UpdateKarma(uint32 acct_id, uint32 amount) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - uint32 affected_rows = 0; + std::string query = StringFormat("UPDATE account SET karma = %i WHERE id = %i", amount, acct_id); + auto results = QueryDatabase(query); + if (!results.Success()) + std::cerr << "Error in UpdateKarma query '" << query << "' " << results.ErrorMessage().c_str() << std::endl; - if (RunQuery(query, MakeAnyLenString(&query, "UPDATE account set karma=%i where id=%i", amount, acct_id), errbuf, 0, &affected_rows)){ - safe_delete_array(query);} - else { - std::cerr << "Error in UpdateKarma query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); - } } void ZoneDatabase::ListAllInstances(Client* c, uint32 charid) From aab5ed226762f7639815b4aa0a3d81536f9aa93b Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 13:19:37 -0700 Subject: [PATCH 53/67] ListAllInstances converted to QueryDatabase --- zone/zonedb.cpp | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 80ec01038..5f2a746f5 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1880,38 +1880,28 @@ void ZoneDatabase::UpdateKarma(uint32 acct_id, uint32 amount) } -void ZoneDatabase::ListAllInstances(Client* c, uint32 charid) +void ZoneDatabase::ListAllInstances(Client* client, uint32 charid) { - if(!c) + if(!client) return; - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result; - MYSQL_ROW row; + std::string query = StringFormat("SELECT instance_list.id, zone, version " + "FROM instance_list JOIN instance_list_player " + "ON instance_list.id = instance_list_player.id " + "WHERE instance_list_player.charid = %lu", + (unsigned long)charid); + auto results = QueryDatabase(query); + if (!results.Success()) + return; + char name[64]; + database.GetCharName(charid, name); + client->Message(0, "%s is part of the following instances:", name); - if (RunQuery(query,MakeAnyLenString(&query, "SELECT instance_list.id, zone, version FROM instance_list JOIN" - " instance_list_player ON instance_list.id = instance_list_player.id" - " WHERE instance_list_player.charid=%lu", (unsigned long)charid),errbuf,&result)) - { - safe_delete_array(query); - - char name[64]; - database.GetCharName(charid, name); - c->Message(0, "%s is part of the following instances:", name); - while(row = mysql_fetch_row(result)) - { - c->Message(0, "%s - id: %lu, version: %lu", database.GetZoneName(atoi(row[1])), + for (auto row = results.begin(); row != results.end(); ++row) { + client->Message(0, "%s - id: %lu, version: %lu", database.GetZoneName(atoi(row[1])), (unsigned long)atoi(row[0]), (unsigned long)atoi(row[2])); - } - - mysql_free_result(result); - } - else - { - safe_delete_array(query); - } + } } void ZoneDatabase::QGlobalPurge() From b497b07fedfaa90548fcd639e684e571cbb0faf6 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 13:22:21 -0700 Subject: [PATCH 54/67] QGlobalPurge converted to QueryDatabase --- zone/zonedb.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 5f2a746f5..7623ccc39 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1906,11 +1906,8 @@ void ZoneDatabase::ListAllInstances(Client* client, uint32 charid) void ZoneDatabase::QGlobalPurge() { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - database.RunQuery(query, MakeAnyLenString(&query, "DELETE FROM quest_globals WHERE expdate < UNIX_TIMESTAMP()"), - errbuf); - safe_delete_array(query); + const std::string query = "DELETE FROM quest_globals WHERE expdate < UNIX_TIMESTAMP()"; + database.QueryDatabase(query); } void ZoneDatabase::InsertDoor(uint32 ddoordbid, uint16 ddoorid, const char* ddoor_name, float dxpos, float dypos, float dzpos, float dheading, uint8 dopentype, uint16 dguildid, uint32 dlockpick, uint32 dkeyitem, uint8 ddoor_param, uint8 dinvert, int dincline, uint16 dsize){ From 743175d4ff3125f1f285378f9ff4ca7671268d74 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 13:26:38 -0700 Subject: [PATCH 55/67] InsertDoor converted to QueryDatabase --- zone/zonedb.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 7623ccc39..056432a89 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1911,12 +1911,18 @@ void ZoneDatabase::QGlobalPurge() } void ZoneDatabase::InsertDoor(uint32 ddoordbid, uint16 ddoorid, const char* ddoor_name, float dxpos, float dypos, float dzpos, float dheading, uint8 dopentype, uint16 dguildid, uint32 dlockpick, uint32 dkeyitem, uint8 ddoor_param, uint8 dinvert, int dincline, uint16 dsize){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - if (!RunQuery(query, MakeAnyLenString(&query, "replace into doors (id, doorid,zone,version,name,pos_x,pos_y,pos_z,heading,opentype,guild,lockpick,keyitem,door_param,invert_state,incline,size) values('%i','%i','%s','%i', '%s','%f','%f','%f','%f','%i','%i','%i', '%i','%i','%i','%i','%i')", ddoordbid ,ddoorid ,zone->GetShortName(), zone->GetInstanceVersion(), ddoor_name, dxpos, dypos, dzpos, dheading, dopentype, dguildid, dlockpick, dkeyitem, ddoor_param, dinvert, dincline, dsize), errbuf)) { - std::cerr << "Error in InsertDoor" << query << "' " << errbuf << std::endl; - } - safe_delete_array(query); + + std::string query = StringFormat("REPLACE INTO doors (id, doorid, zone, version, name, " + "pos_x, pos_y, pos_z, heading, opentype, guild, lockpick, " + "keyitem, door_param, invert_state, incline, size) " + "VALUES('%i', '%i', '%s', '%i', '%s', '%f', '%f', " + "'%f', '%f', '%i', '%i', '%i', '%i', '%i', '%i', '%i', '%i')", + ddoordbid, ddoorid, zone->GetShortName(), zone->GetInstanceVersion(), + ddoor_name, dxpos, dypos, dzpos, dheading, dopentype, dguildid, + dlockpick, dkeyitem, ddoor_param, dinvert, dincline, dsize); + auto results = QueryDatabase(query); + if (!results.Success()) + std::cerr << "Error in InsertDoor" << query << "' " << results.ErrorMessage() << std::endl; } void ZoneDatabase::LoadAltCurrencyValues(uint32 char_id, std::map ¤cy) { From fc0d589f1289244a3f0099e104a3f45bfda54622 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 13:34:19 -0700 Subject: [PATCH 56/67] LoadAltCurrencyValues converted to QueryDatabase --- zone/zonedb.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 056432a89..a0df3ea7d 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1926,23 +1926,19 @@ void ZoneDatabase::InsertDoor(uint32 ddoordbid, uint16 ddoorid, const char* ddoo } void ZoneDatabase::LoadAltCurrencyValues(uint32 char_id, std::map ¤cy) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT currency_id, amount FROM character_alt_currency where char_id='%u'", char_id), errbuf, &result)) { - safe_delete_array(query); - while ((row = mysql_fetch_row(result))) - { - currency[atoi(row[0])] = atoi(row[1]); - } - mysql_free_result(result); - } - else { - LogFile->write(EQEMuLog::Error, "Error in LoadAltCurrencyValues query '%s': %s", query, errbuf); - safe_delete_array(query); - } + std::string query = StringFormat("SELECT currency_id, amount " + "FROM character_alt_currency " + "WHERE char_id = '%u'", char_id); + auto results = QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in LoadAltCurrencyValues query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); + return; + } + + for (auto row = results.begin(); row != results.end(); ++row) + currency[atoi(row[0])] = atoi(row[1]); + } void ZoneDatabase::UpdateAltCurrencyValue(uint32 char_id, uint32 currency_id, uint32 value) { From cab43f41be1592202fef6644f8a3df621d8e3fb5 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 13:36:01 -0700 Subject: [PATCH 57/67] UpdateAltCurrencyValues converted to QueryDatabase --- zone/zonedb.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index a0df3ea7d..2503aa793 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1942,12 +1942,11 @@ void ZoneDatabase::LoadAltCurrencyValues(uint32 char_id, std::map Date: Thu, 21 Aug 2014 13:42:02 -0700 Subject: [PATCH 58/67] SaveBuffs converted to QueryDatabase --- zone/zonedb.cpp | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 2503aa793..58d1f991c 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1949,29 +1949,33 @@ void ZoneDatabase::UpdateAltCurrencyValue(uint32 char_id, uint32 currency_id, ui } -void ZoneDatabase::SaveBuffs(Client *c) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; +void ZoneDatabase::SaveBuffs(Client *client) { - database.RunQuery(query, MakeAnyLenString(&query, "DELETE FROM `character_buffs` WHERE `character_id`='%u'", c->CharacterID()), - errbuf); + std::string query = StringFormat("DELETE FROM `character_buffs` WHERE `character_id` = '%u'", client->CharacterID()); + database.QueryDatabase(query); + + uint32 buff_count = client->GetMaxBuffSlots(); + Buffs_Struct *buffs = client->GetBuffs(); + + for (int index = 0; index < buff_count; index++) { + if(buffs[index].spellid == SPELL_UNKNOWN) + continue; + + query = StringFormat("INSERT INTO `character_buffs` (character_id, slot_id, spell_id, " + "caster_level, caster_name, ticsremaining, counters, numhits, melee_rune, " + "magic_rune, persistent, dot_rune, caston_x, caston_y, caston_z, ExtraDIChance) " + "VALUES('%u', '%u', '%u', '%u', '%s', '%u', '%u', '%u', '%u', '%u', '%u', '%u', " + "'%i', '%i', '%i', '%i')", client->CharacterID(), index, buffs[index].spellid, + buffs[index].casterlevel, buffs[index].caster_name, buffs[index].ticsremaining, + buffs[index].counters, buffs[index].numhits, buffs[index].melee_rune, + buffs[index].magic_rune, buffs[index].persistant_buff, buffs[index].dot_rune, + buffs[index].caston_x, buffs[index].caston_y, buffs[index].caston_z, + buffs[index].ExtraDIChance); + auto results = QueryDatabase(query); + if (!results.Success()) + LogFile->write(EQEMuLog::Error, "Error in SaveBuffs query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); - uint32 buff_count = c->GetMaxBuffSlots(); - Buffs_Struct *buffs = c->GetBuffs(); - for (int i = 0; i < buff_count; i++) { - if(buffs[i].spellid != SPELL_UNKNOWN) { - if(!database.RunQuery(query, MakeAnyLenString(&query, "INSERT INTO `character_buffs` (character_id, slot_id, spell_id, " - "caster_level, caster_name, ticsremaining, counters, numhits, melee_rune, magic_rune, persistent, dot_rune, " - "caston_x, caston_y, caston_z, ExtraDIChance) VALUES('%u', '%u', '%u', '%u', '%s', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%i', '%i', '%i', '%i')", - c->CharacterID(), i, buffs[i].spellid, buffs[i].casterlevel, buffs[i].caster_name, buffs[i].ticsremaining, - buffs[i].counters, buffs[i].numhits, buffs[i].melee_rune, buffs[i].magic_rune, buffs[i].persistant_buff, - buffs[i].dot_rune, buffs[i].caston_x, buffs[i].caston_y, buffs[i].caston_z, buffs[i].ExtraDIChance), - errbuf)) { - LogFile->write(EQEMuLog::Error, "Error in SaveBuffs query '%s': %s", query, errbuf); - } - } } - safe_delete_array(query); } void ZoneDatabase::LoadBuffs(Client *c) { From 10d384f1310c5aa4a3bba0e938b089cdef8cd02e Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 13:53:54 -0700 Subject: [PATCH 59/67] LoadBuffs converted to QueryDatabase --- zone/zonedb.cpp | 173 ++++++++++++++++++++++-------------------------- 1 file changed, 79 insertions(+), 94 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 58d1f991c..75862b8d8 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -1978,108 +1978,93 @@ void ZoneDatabase::SaveBuffs(Client *client) { } } -void ZoneDatabase::LoadBuffs(Client *c) { - Buffs_Struct *buffs = c->GetBuffs(); - uint32 max_slots = c->GetMaxBuffSlots(); - for(int i = 0; i < max_slots; ++i) { - buffs[i].spellid = SPELL_UNKNOWN; - } +void ZoneDatabase::LoadBuffs(Client *client) { + Buffs_Struct *buffs = client->GetBuffs(); + uint32 max_slots = client->GetMaxBuffSlots(); - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT spell_id, slot_id, caster_level, caster_name, ticsremaining, counters, " - "numhits, melee_rune, magic_rune, persistent, dot_rune, caston_x, caston_y, caston_z, ExtraDIChance FROM `character_buffs` WHERE " - "`character_id`='%u'", - c->CharacterID()), errbuf, &result)) - { - safe_delete_array(query); - while ((row = mysql_fetch_row(result))) - { - uint32 slot_id = atoul(row[1]); - if(slot_id >= c->GetMaxBuffSlots()) { - continue; - } + for(int index = 0; index < max_slots; ++index) + buffs[index].spellid = SPELL_UNKNOWN; - uint32 spell_id = atoul(row[0]); - if(!IsValidSpell(spell_id)) { - continue; - } - - Client *caster = entity_list.GetClientByName(row[3]); - uint32 caster_level = atoi(row[2]); - uint32 ticsremaining = atoul(row[4]); - uint32 counters = atoul(row[5]); - uint32 numhits = atoul(row[6]); - uint32 melee_rune = atoul(row[7]); - uint32 magic_rune = atoul(row[8]); - uint8 persistent = atoul(row[9]); - uint32 dot_rune = atoul(row[10]); - int32 caston_x = atoul(row[11]); - int32 caston_y = atoul(row[12]); - int32 caston_z = atoul(row[13]); - int32 ExtraDIChance = atoul(row[14]); - - buffs[slot_id].spellid = spell_id; - buffs[slot_id].casterlevel = caster_level; - if(caster) { - buffs[slot_id].casterid = caster->GetID(); - strcpy(buffs[slot_id].caster_name, caster->GetName()); - buffs[slot_id].client = true; - } else { - buffs[slot_id].casterid = 0; - strcpy(buffs[slot_id].caster_name, ""); - buffs[slot_id].client = false; - } - - buffs[slot_id].ticsremaining = ticsremaining; - buffs[slot_id].counters = counters; - buffs[slot_id].numhits = numhits; - buffs[slot_id].melee_rune = melee_rune; - buffs[slot_id].magic_rune = magic_rune; - buffs[slot_id].persistant_buff = persistent ? true : false; - buffs[slot_id].dot_rune = dot_rune; - buffs[slot_id].caston_x = caston_x; - buffs[slot_id].caston_y = caston_y; - buffs[slot_id].caston_z = caston_z; - buffs[slot_id].ExtraDIChance = ExtraDIChance; - buffs[slot_id].RootBreakChance = 0; - buffs[slot_id].UpdateClient = false; - - } - mysql_free_result(result); - } - else { - LogFile->write(EQEMuLog::Error, "Error in LoadBuffs query '%s': %s", query, errbuf); - safe_delete_array(query); + std::string query = StringFormat("SELECT spell_id, slot_id, caster_level, caster_name, ticsremaining, " + "counters, numhits, melee_rune, magic_rune, persistent, dot_rune, " + "caston_x, caston_y, caston_z, ExtraDIChance " + "FROM `character_buffs` WHERE `character_id` = '%u'", client->CharacterID()); + auto results = QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in LoadBuffs query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); return; - } + } - max_slots = c->GetMaxBuffSlots(); - for(int i = 0; i < max_slots; ++i) { - if(!IsValidSpell(buffs[i].spellid)) { + for (auto row = results.begin(); row != results.end(); ++row) { + uint32 slot_id = atoul(row[1]); + if(slot_id >= client->GetMaxBuffSlots()) continue; - } - for(int j = 0; j < 12; ++j) { - bool cont = false; - switch(spells[buffs[i].spellid].effectid[j]) { - case SE_Charm: - buffs[i].spellid = SPELL_UNKNOWN; - cont = true; - break; - case SE_Illusion: - if(!buffs[i].persistant_buff) { - buffs[i].spellid = SPELL_UNKNOWN; - cont = true; - } - break; - } + uint32 spell_id = atoul(row[0]); + if(!IsValidSpell(spell_id)) + continue; - if(cont) { - break; + Client *caster = entity_list.GetClientByName(row[3]); + uint32 caster_level = atoi(row[2]); + uint32 ticsremaining = atoul(row[4]); + uint32 counters = atoul(row[5]); + uint32 numhits = atoul(row[6]); + uint32 melee_rune = atoul(row[7]); + uint32 magic_rune = atoul(row[8]); + uint8 persistent = atoul(row[9]); + uint32 dot_rune = atoul(row[10]); + int32 caston_x = atoul(row[11]); + int32 caston_y = atoul(row[12]); + int32 caston_z = atoul(row[13]); + int32 ExtraDIChance = atoul(row[14]); + + buffs[slot_id].spellid = spell_id; + buffs[slot_id].casterlevel = caster_level; + + if(caster) { + buffs[slot_id].casterid = caster->GetID(); + strcpy(buffs[slot_id].caster_name, caster->GetName()); + buffs[slot_id].client = true; + } else { + buffs[slot_id].casterid = 0; + strcpy(buffs[slot_id].caster_name, ""); + buffs[slot_id].client = false; + } + + buffs[slot_id].ticsremaining = ticsremaining; + buffs[slot_id].counters = counters; + buffs[slot_id].numhits = numhits; + buffs[slot_id].melee_rune = melee_rune; + buffs[slot_id].magic_rune = magic_rune; + buffs[slot_id].persistant_buff = persistent? true: false; + buffs[slot_id].dot_rune = dot_rune; + buffs[slot_id].caston_x = caston_x; + buffs[slot_id].caston_y = caston_y; + buffs[slot_id].caston_z = caston_z; + buffs[slot_id].ExtraDIChance = ExtraDIChance; + buffs[slot_id].RootBreakChance = 0; + buffs[slot_id].UpdateClient = false; + + } + + max_slots = client->GetMaxBuffSlots(); + for(int index = 0; index < max_slots; ++index) { + if(!IsValidSpell(buffs[index].spellid)) + continue; + + for(int effectIndex = 0; effectIndex < 12; ++effectIndex) { + + if (spells[buffs[index].spellid].effectid[effectIndex] == SE_Charm) { + buffs[index].spellid = SPELL_UNKNOWN; + break; + } + + if (spells[buffs[index].spellid].effectid[effectIndex] == SE_Illusion) { + if(buffs[index].persistant_buff) + break; + + buffs[index].spellid = SPELL_UNKNOWN; } } } From cf7574d9b8cdae194044ef8ca34dc73cd2dd2531 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 15:30:27 -0700 Subject: [PATCH 60/67] SavePetInfo converted to QueryDatabase --- zone/zonedb.cpp | 153 ++++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 77 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 75862b8d8..f0c2f2afc 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -2070,95 +2070,94 @@ void ZoneDatabase::LoadBuffs(Client *client) { } } -void ZoneDatabase::SavePetInfo(Client *c) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - int i = 0; - PetInfo *petinfo = c->GetPetInfo(0); - PetInfo *suspended = c->GetPetInfo(1); +void ZoneDatabase::SavePetInfo(Client *client) { - if(!database.RunQuery(query, MakeAnyLenString(&query, "DELETE FROM `character_pet_buffs` WHERE `char_id`=%u", c->CharacterID()), - errbuf)) { - safe_delete_array(query); + PetInfo *petinfo = client->GetPetInfo(0); + PetInfo *suspended = client->GetPetInfo(1); + + std::string query = StringFormat("DELETE FROM `character_pet_buffs` WHERE `char_id` = %u", client->CharacterID()); + auto results = database.QueryDatabase(query); + if(!results.Success()) return; - } - safe_delete_array(query); - if (!database.RunQuery(query, MakeAnyLenString(&query, "DELETE FROM `character_pet_inventory` WHERE `char_id`=%u", c->CharacterID()), - errbuf)) { - safe_delete_array(query); - // error report + + query = StringFormat("DELETE FROM `character_pet_buffs` WHERE `char_id` = %u", client->CharacterID()); + results = database.QueryDatabase(query); + if(!results.Success()) return; - } - safe_delete_array(query); - if(!database.RunQuery(query, MakeAnyLenString(&query, - "INSERT INTO `character_pet_info` (`char_id`, `pet`, `petname`, `petpower`, `spell_id`, `hp`, `mana`, `size`) " - "values (%u, 0, '%s', %i, %u, %u, %u, %f) " - "ON DUPLICATE KEY UPDATE `petname`='%s', `petpower`=%i, `spell_id`=%u, `hp`=%u, `mana`=%u, `size`=%f", - c->CharacterID(), petinfo->Name, petinfo->petpower, petinfo->SpellID, petinfo->HP, petinfo->Mana, petinfo->size, - petinfo->Name, petinfo->petpower, petinfo->SpellID, petinfo->HP, petinfo->Mana, petinfo->size), - errbuf)) - { - safe_delete_array(query); + query = StringFormat("INSERT INTO `character_pet_info` " + "(`char_id`, `pet`, `petname`, `petpower`, `spell_id`, `hp`, `mana`, `size`) " + "VALUES (%u, 0, '%s', %i, %u, %u, %u, %f) " + "ON DUPLICATE KEY UPDATE `petname` = '%s', `petpower` = %i, `spell_id` = %u, " + "`hp` = %u, `mana` = %u, `size` = %f", + client->CharacterID(), petinfo->Name, petinfo->petpower, petinfo->SpellID, + petinfo->HP, petinfo->Mana, petinfo->size, petinfo->Name, petinfo->petpower, + petinfo->SpellID, petinfo->HP, petinfo->Mana, petinfo->size); + results = database.QueryDatabase(query); + if(!results.Success()) return; - } - safe_delete_array(query); - for(i=0; i < RuleI(Spells, MaxTotalSlotsPET); i++) { - if (petinfo->Buffs[i].spellid != SPELL_UNKNOWN && petinfo->Buffs[i].spellid != 0) { - database.RunQuery(query, MakeAnyLenString(&query, - "INSERT INTO `character_pet_buffs` (`char_id`, `pet`, `slot`, `spell_id`, `caster_level`, " - "`ticsremaining`, `counters`) values " - "(%u, 0, %u, %u, %u, %u, %d)", - c->CharacterID(), i, petinfo->Buffs[i].spellid, petinfo->Buffs[i].level, petinfo->Buffs[i].duration, - petinfo->Buffs[i].counters), - errbuf); - safe_delete_array(query); - } - if (suspended->Buffs[i].spellid != SPELL_UNKNOWN && suspended->Buffs[i].spellid != 0) { - database.RunQuery(query, MakeAnyLenString(&query, - "INSERT INTO `character_pet_buffs` (`char_id`, `pet`, `slot`, `spell_id`, `caster_level`, " - "`ticsremaining`, `counters`) values " - "(%u, 1, %u, %u, %u, %u, %d)", - c->CharacterID(), i, suspended->Buffs[i].spellid, suspended->Buffs[i].level, suspended->Buffs[i].duration, - suspended->Buffs[i].counters), - errbuf); - safe_delete_array(query); - } + for(int index = 0; index < RuleI(Spells, MaxTotalSlotsPET); index++) { + if (petinfo->Buffs[index].spellid == SPELL_UNKNOWN || petinfo->Buffs[index].spellid == 0) + continue; + + query = StringFormat("INSERT INTO `character_pet_buffs` " + "(`char_id`, `pet`, `slot`, `spell_id`, `caster_level`, " + "`ticsremaining`, `counters`) " + "VALUES (%u, 0, %u, %u, %u, %u, %d)", + client->CharacterID(), index, petinfo->Buffs[index].spellid, + petinfo->Buffs[index].level, petinfo->Buffs[index].duration, + petinfo->Buffs[index].counters); + database.QueryDatabase(query); + } + + for(int index = 0; index < RuleI(Spells, MaxTotalSlotsPET); index++) { + if (petinfo->Buffs[index].spellid == SPELL_UNKNOWN || petinfo->Buffs[index].spellid == 0) + continue; + + query = StringFormat("INSERT INTO `character_pet_buffs` " + "(`char_id`, `pet`, `slot`, `spell_id`, `caster_level`, " + "`ticsremaining`, `counters`) " + "VALUES (%u, 1, %u, %u, %u, %u, %d)", + client->CharacterID(), index, suspended->Buffs[index].spellid, + suspended->Buffs[index].level, suspended->Buffs[index].duration, + suspended->Buffs[index].counters); + database.QueryDatabase(query); } - for (i = EmuConstants::EQUIPMENT_BEGIN; i <= EmuConstants::EQUIPMENT_END; i++) { - if(petinfo->Items[i]) { - database.RunQuery(query, MakeAnyLenString(&query, - "INSERT INTO `character_pet_inventory` (`char_id`, `pet`, `slot`, `item_id`) values (%u, 0, %u, %u)", - c->CharacterID(), i, petinfo->Items[i]), errbuf); - // should check for errors - safe_delete_array(query); - } + for (int index = EmuConstants::EQUIPMENT_BEGIN; index <= EmuConstants::EQUIPMENT_END; index++) { + if(!petinfo->Items[index]) + continue; + + query = StringFormat("INSERT INTO `character_pet_inventory` " + "(`char_id`, `pet`, `slot`, `item_id`) " + "VALUES (%u, 0, %u, %u)", + client->CharacterID(), index, petinfo->Items[index]); + database.QueryDatabase(query); } - - if(!database.RunQuery(query, MakeAnyLenString(&query, - "INSERT INTO `character_pet_info` (`char_id`, `pet`, `petname`, `petpower`, `spell_id`, `hp`, `mana`, `size`) " - "values (%u, 1, '%s', %u, %u, %u, %u, %f) " - "ON DUPLICATE KEY UPDATE `petname`='%s', `petpower`=%i, `spell_id`=%u, `hp`=%u, `mana`=%u, `size`=%f", - c->CharacterID(), suspended->Name, suspended->petpower, suspended->SpellID, suspended->HP, suspended->Mana, suspended->size, - suspended->Name, suspended->petpower, suspended->SpellID, suspended->HP, suspended->Mana, suspended->size), - errbuf)) - { - safe_delete_array(query); + query = StringFormat("INSERT INTO `character_pet_info` " + "(`char_id`, `pet`, `petname`, `petpower`, `spell_id`, `hp`, `mana`, `size`) " + "VALUES (%u, 1, '%s', %u, %u, %u, %u, %f) " + "ON DUPLICATE KEY UPDATE " + "`petname`='%s', `petpower`=%i, `spell_id`=%u, `hp`=%u, `mana`=%u, `size`=%f", + client->CharacterID(), suspended->Name, suspended->petpower, suspended->SpellID, + suspended->HP, suspended->Mana, suspended->size, suspended->Name, suspended->petpower, + suspended->SpellID, suspended->HP, suspended->Mana, suspended->size); + results = database.QueryDatabase(query); + if(!results.Success()) return; - } - safe_delete_array(query); - for (i = EmuConstants::EQUIPMENT_BEGIN; i <= EmuConstants::EQUIPMENT_END; i++) { - if(suspended->Items[i]) { - database.RunQuery(query, MakeAnyLenString(&query, - "INSERT INTO `character_pet_inventory` (`char_id`, `pet`, `slot`, `item_id`) values (%u, 1, %u, %u)", - c->CharacterID(), i, suspended->Items[i]), errbuf); - // should check for errors - safe_delete_array(query); - } + + for (int index = EmuConstants::EQUIPMENT_BEGIN; index <= EmuConstants::EQUIPMENT_END; index++) { + if(!suspended->Items[index]) + continue; + + query = StringFormat("INSERT INTO `character_pet_inventory` " + "(`char_id`, `pet`, `slot`, `item_id`) " + "VALUES (%u, 1, %u, %u)", + client->CharacterID(), index, suspended->Items[index]); + database.QueryDatabase(query); } } From e731cfd48d15f51b81f7466ece7529e1d9d4d611 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 15:32:20 -0700 Subject: [PATCH 61/67] RemoveTempFactions converted to QueryDatabase --- zone/zonedb.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index f0c2f2afc..bfad721e2 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -2162,14 +2162,15 @@ void ZoneDatabase::SavePetInfo(Client *client) { } -void ZoneDatabase::RemoveTempFactions(Client *c){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; +void ZoneDatabase::RemoveTempFactions(Client *client) { + + std::string query = StringFormat("DELETE FROM faction_values " + "WHERE temp = 1 AND char_id = %u", + client->CharacterID()); + auto results = QueryDatabase(query); + if (!results.Success()) + std::cerr << "Error in RemoveTempFactions query '" << query << "' " << results.ErrorMessage() << std::endl; - if (!RunQuery(query, MakeAnyLenString(&query, "DELETE FROM faction_values WHERE temp = 1 AND char_id=%u", c->CharacterID()), errbuf)) { - std::cerr << "Error in RemoveTempFactions query '" << query << "' " << errbuf << std::endl; - } - safe_delete_array(query); } void ZoneDatabase::LoadPetInfo(Client *c) { From 833227f7f68753f982c1b0cfd2819315d6a16f10 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 15:58:11 -0700 Subject: [PATCH 62/67] LoadPetInfo converted to QueryDatabase --- zone/zonedb.cpp | 194 ++++++++++++++++++++++-------------------------- 1 file changed, 87 insertions(+), 107 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index bfad721e2..184f7e5c8 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -2173,129 +2173,109 @@ void ZoneDatabase::RemoveTempFactions(Client *client) { } -void ZoneDatabase::LoadPetInfo(Client *c) { - // Load current pet and suspended pet - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result; - MYSQL_ROW row; +void ZoneDatabase::LoadPetInfo(Client *client) { - PetInfo *petinfo = c->GetPetInfo(0); - PetInfo *suspended = c->GetPetInfo(1); - PetInfo *pi; - uint16 pet; + // Load current pet and suspended pet + PetInfo *petinfo = client->GetPetInfo(0); + PetInfo *suspended = client->GetPetInfo(1); memset(petinfo, 0, sizeof(PetInfo)); memset(suspended, 0, sizeof(PetInfo)); - if(database.RunQuery(query, MakeAnyLenString(&query, - "SELECT `pet`, `petname`, `petpower`, `spell_id`, `hp`, `mana`, `size` from `character_pet_info` where `char_id`=%u", - c->CharacterID()), errbuf, &result)) - { - safe_delete_array(query); - while ((row = mysql_fetch_row(result))) { - pet = atoi(row[0]); - if (pet == 0) - pi = petinfo; - else if (pet == 1) - pi = suspended; - else - continue; - - strncpy(pi->Name,row[1],64); - pi->petpower = atoi(row[2]); - pi->SpellID = atoi(row[3]); - pi->HP = atoul(row[4]); - pi->Mana = atoul(row[5]); - pi->size = atof(row[6]); - } - mysql_free_result(result); - } - else - { - LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query, errbuf); - safe_delete_array(query); + std::string query = StringFormat("SELECT `pet`, `petname`, `petpower`, `spell_id`, " + "`hp`, `mana`, `size` FROM `character_pet_info` " + "WHERE `char_id` = %u", client->CharacterID()); + auto results = database.QueryDatabase(query); + if(!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); return; } + PetInfo *pi; + for (auto row = results.begin(); row != results.end(); ++row) { + uint16 pet = atoi(row[0]); - if (RunQuery(query, MakeAnyLenString(&query, - "SELECT `pet`, `slot`, `spell_id`, `caster_level`, `castername`, " - "`ticsremaining`, `counters` FROM `character_pet_buffs` " - "WHERE `char_id`=%u", - c->CharacterID()), errbuf, &result)) - { - safe_delete_array(query); - while ((row = mysql_fetch_row(result))) - { - pet = atoi(row[0]); - if (pet == 0) - pi = petinfo; - else if (pet == 1) - pi = suspended; - else - continue; + if (pet == 0) + pi = petinfo; + else if (pet == 1) + pi = suspended; + else + continue; - uint32 slot_id = atoul(row[1]); - if(slot_id >= RuleI(Spells, MaxTotalSlotsPET)) { - continue; - } - - uint32 spell_id = atoul(row[2]); - if(!IsValidSpell(spell_id)) { - continue; - } - uint32 caster_level = atoi(row[3]); - int caster_id = 0; - // The castername field is currently unused - //Client *caster = entity_list.GetClientByName(row[4]); - //if (caster) { caster_id = caster->GetID(); } - uint32 ticsremaining = atoul(row[5]); - uint32 counters = atoul(row[6]); - - pi->Buffs[slot_id].spellid = spell_id; - pi->Buffs[slot_id].level = caster_level; - pi->Buffs[slot_id].player_id = caster_id; - pi->Buffs[slot_id].slotid = 2; // Always 2 in buffs struct for real buffs - - pi->Buffs[slot_id].duration = ticsremaining; - pi->Buffs[slot_id].counters = counters; - } - mysql_free_result(result); + strncpy(pi->Name,row[1],64); + pi->petpower = atoi(row[2]); + pi->SpellID = atoi(row[3]); + pi->HP = atoul(row[4]); + pi->Mana = atoul(row[5]); + pi->size = atof(row[6]); } - else { - LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query, errbuf); - safe_delete_array(query); + + query = StringFormat("SELECT `pet`, `slot`, `spell_id`, `caster_level`, `castername`, " + "`ticsremaining`, `counters` FROM `character_pet_buffs` " + "WHERE `char_id` = %u", client->CharacterID()); + results = QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); + return; + } + + for (auto row = results.begin(); row != results.end(); ++row) { + uint16 pet = atoi(row[0]); + if (pet == 0) + pi = petinfo; + else if (pet == 1) + pi = suspended; + else + continue; + + uint32 slot_id = atoul(row[1]); + if(slot_id >= RuleI(Spells, MaxTotalSlotsPET)) + continue; + + uint32 spell_id = atoul(row[2]); + if(!IsValidSpell(spell_id)) + continue; + + uint32 caster_level = atoi(row[3]); + int caster_id = 0; + // The castername field is currently unused + uint32 ticsremaining = atoul(row[5]); + uint32 counters = atoul(row[6]); + + pi->Buffs[slot_id].spellid = spell_id; + pi->Buffs[slot_id].level = caster_level; + pi->Buffs[slot_id].player_id = caster_id; + pi->Buffs[slot_id].slotid = 2; // Always 2 in buffs struct for real buffs + + pi->Buffs[slot_id].duration = ticsremaining; + pi->Buffs[slot_id].counters = counters; + } + + query = StringFormat("SELECT `pet`, `slot`, `item_id` " + "FROM `character_pet_inventory` " + "WHERE `char_id`=%u",client->CharacterID()); + results = database.QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); return; } - if (database.RunQuery(query, MakeAnyLenString(&query, - "SELECT `pet`, `slot`, `item_id` FROM `character_pet_inventory` WHERE `char_id`=%u", - c->CharacterID()), errbuf, &result)) - { - safe_delete_array(query); - while((row = mysql_fetch_row(result))) { - pet = atoi(row[0]); - if (pet == 0) - pi = petinfo; - else if (pet == 1) - pi = suspended; - else - continue; + for(auto row = results.begin(); row != results.end(); ++row) { + uint16 pet = atoi(row[0]); + if (pet == 0) + pi = petinfo; + else if (pet == 1) + pi = suspended; + else + continue; - int slot = atoi(row[1]); - if (slot < EmuConstants::EQUIPMENT_BEGIN || slot > EmuConstants::EQUIPMENT_END) - continue; + int slot = atoi(row[1]); + if (slot < EmuConstants::EQUIPMENT_BEGIN || slot > EmuConstants::EQUIPMENT_END) + continue; + + pi->Items[slot] = atoul(row[2]); + } - pi->Items[slot] = atoul(row[2]); - } - mysql_free_result(result); - } - else { - LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query, errbuf); - safe_delete_array(query); - return; - } } bool ZoneDatabase::GetFactionData(FactionMods* fm, uint32 class_mod, uint32 race_mod, uint32 deity_mod, int32 faction_id) { From 2e847815943ec146d95983cb3282f8a03655a129 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 17:00:50 -0700 Subject: [PATCH 63/67] LoadFactionValues_result converted to MySQLRequestResult --- zone/zonedb.cpp | 8 ++++---- zone/zonedb.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 184f7e5c8..3b8d45e6d 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -2350,11 +2350,11 @@ bool ZoneDatabase::LoadFactionValues(uint32 char_id, faction_map & val_list) { return false; } -bool ZoneDatabase::LoadFactionValues_result(MYSQL_RES* result, faction_map & val_list) { - MYSQL_ROW row; - while((row = mysql_fetch_row(result))) { +bool ZoneDatabase::LoadFactionValues_result(MySQLRequestResult results, faction_map & val_list) { + + for (auto row = results.begin(); row != results.begin(); ++row) val_list[atoi(row[0])] = atoi(row[1]); - } + return true; } diff --git a/zone/zonedb.h b/zone/zonedb.h index cab3e84a9..dae8c6490 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -302,7 +302,7 @@ public: bool SetCharacterFactionLevel(uint32 char_id, int32 faction_id, int32 value, uint8 temp, faction_map &val_list); // rembrant, needed for factions Dec, 16 2001 bool LoadFactionData(); bool LoadFactionValues(uint32 char_id, faction_map & val_list); - bool LoadFactionValues_result(MYSQL_RES* result, faction_map & val_list); + bool LoadFactionValues_result(MySQLRequestResult result, faction_map & val_list); /* * AAs From 2df823d2dbb96ac159f14243070834b5927b33d2 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 17:04:08 -0700 Subject: [PATCH 64/67] LoadFactionValues converted to QueryDatabase --- zone/zonedb.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 3b8d45e6d..f813febfd 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -2333,21 +2333,18 @@ bool ZoneDatabase::GetFactionData(FactionMods* fm, uint32 class_mod, uint32 race return true; } -bool ZoneDatabase::LoadFactionValues(uint32 char_id, faction_map & val_list) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT faction_id,current_value FROM faction_values WHERE char_id = %i",char_id), errbuf, &result)) { - safe_delete_array(query); - bool ret = LoadFactionValues_result(result, val_list); - mysql_free_result(result); - return ret; - } - else { - std::cerr << "Error in LoadFactionValues query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); - } - return false; +bool ZoneDatabase::LoadFactionValues(uint32 char_id, faction_map& val_list) { + + std::string query = StringFormat("SELECT faction_id,current_value " + "FROM faction_values " + "WHERE char_id = %i", char_id); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in LoadFactionValues query '" << query << "' " << results.ErrorMessage() << std::endl; + return false; + } + + return LoadFactionValues_result(std::move(results), val_list); } bool ZoneDatabase::LoadFactionValues_result(MySQLRequestResult results, faction_map & val_list) { From 850d1e7c283d9f5dd75f72e195e651d3f7eedb0f Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 17:08:31 -0700 Subject: [PATCH 65/67] SetCharacterFactionLevel converted to QueryDatabase --- zone/zonedb.cpp | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index f813febfd..e4b74c772 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -2402,23 +2402,18 @@ bool ZoneDatabase::GetNPCFactionList(uint32 npcfaction_id, int32* faction_id, in //o-------------------------------------------------------------- bool ZoneDatabase::SetCharacterFactionLevel(uint32 char_id, int32 faction_id, int32 value, uint8 temp, faction_map &val_list) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - uint32 affected_rows = 0; - if (!RunQuery(query, MakeAnyLenString(&query, - "DELETE FROM faction_values WHERE char_id=%i AND faction_id = %i", - char_id, faction_id), errbuf)) { - std::cerr << "Error in SetCharacterFactionLevel query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); + std::string query = StringFormat("DELETE FROM faction_values " + "WHERE char_id=%i AND faction_id = %i", + char_id, faction_id); + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in SetCharacterFactionLevel query '" << query << "' " << results.ErrorMessage() << std::endl; return false; - } + } if(value == 0) - { - safe_delete_array(query); return true; - } if(temp == 2) temp = 0; @@ -2426,23 +2421,19 @@ bool ZoneDatabase::SetCharacterFactionLevel(uint32 char_id, int32 faction_id, in if(temp == 3) temp = 1; - if (!RunQuery(query, MakeAnyLenString(&query, - "INSERT INTO faction_values (char_id,faction_id,current_value,temp) VALUES (%i,%i,%i,%i)", - char_id, faction_id,value,temp), errbuf, 0, &affected_rows)) { - std::cerr << "Error in SetCharacterFactionLevel query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); + query = StringFormat("INSERT INTO faction_values (char_id, faction_id, current_value, temp) " + "VALUES (%i, %i, %i, %i)", char_id, faction_id, value, temp); + results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in SetCharacterFactionLevel query '" << query << "' " << results.ErrorMessage() << std::endl; return false; } - safe_delete_array(query); - - if (affected_rows == 0) - { + if (results.RowsAffected() == 0) return false; - } val_list[faction_id] = value; - return(true); + return true; } bool ZoneDatabase::LoadFactionData() From 9ff0c414c178c5f4344aac62b3d24435b17c196f Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 17:17:27 -0700 Subject: [PATCH 66/67] LoadFactionData converted to QueryDatabase --- zone/zonedb.cpp | 98 +++++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 60 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index e4b74c772..90b4773f1 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -2438,69 +2438,47 @@ bool ZoneDatabase::SetCharacterFactionLevel(uint32 char_id, int32 faction_id, in bool ZoneDatabase::LoadFactionData() { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - query = new char[256]; - strcpy(query, "SELECT MAX(id) FROM faction_list"); - - if (RunQuery(query, strlen(query), errbuf, &result)) { - safe_delete_array(query); - row = mysql_fetch_row(result); - if (row && row[0]) - { - max_faction = atoi(row[0]); - faction_array = new Faction*[max_faction+1]; - for(unsigned int i=0; iname, row[1], 50); - faction_array[index]->base = atoi(row[2]); - - char sec_errbuf[MYSQL_ERRMSG_SIZE]; - MYSQL_RES *sec_result; - MYSQL_ROW sec_row; - MakeAnyLenString(&query, "SELECT `mod`, `mod_name` FROM `faction_list_mod` WHERE faction_id=%u", index); - if (RunQuery(query, strlen(query), sec_errbuf, &sec_result)) { - while((sec_row = mysql_fetch_row(sec_result))) - { - faction_array[index]->mods[sec_row[1]] = atoi(sec_row[0]); - } - mysql_free_result(sec_result); - } - safe_delete_array(query); - } - mysql_free_result(result); - } - else { - std::cerr << "Error in LoadFactionData '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); - return false; - } - } - else { - mysql_free_result(result); - } - } - else { - std::cerr << "Error in LoadFactionData '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); + std::string query = "SELECT MAX(id) FROM faction_list"; + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in LoadFactionData '" << query << "' " << results.ErrorMessage() << std::endl; return false; } - return true; + + if (results.RowCount() == 0) + return false; + + auto row = results.begin(); + + max_faction = atoi(row[0]); + faction_array = new Faction*[max_faction+1]; + for(unsigned int index=0; indexname, row[1], 50); + faction_array[index]->base = atoi(row[2]); + + + query = StringFormat("SELECT `mod`, `mod_name` FROM `faction_list_mod` WHERE faction_id = %u", index); + auto modResults = QueryDatabase(query); + if (!modResults.Success()) + continue; + + for (auto modRow = modResults.begin(); modRow != modResults.end(); ++modRow) + faction_array[index]->mods[modRow[1]] = atoi(modRow[0]); + + } } bool ZoneDatabase::GetFactionIdsForNPC(uint32 nfl_id, std::list *faction_list, int32* primary_faction) { From 8369570b507242323badaf46613768d0231df1e3 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 21 Aug 2014 17:24:48 -0700 Subject: [PATCH 67/67] GetAccountInfoForLogin_result converted to MySQLRequestResult --- zone/zonedb.cpp | 57 ++++++++++++++++++++++++++----------------------- zone/zonedb.h | 2 +- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 90b4773f1..f0a04515b 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -348,37 +348,40 @@ void ZoneDatabase::UpdateBug(PetitionBug_Struct* bug){ } -bool ZoneDatabase::GetAccountInfoForLogin_result(MYSQL_RES* result, int16* admin, char* account_name, uint32* lsaccountid, uint8* gmspeed, bool* revoked,bool* gmhideme, uint32* account_creation) { - MYSQL_ROW row; - if (mysql_num_rows(result) == 1) { - row = mysql_fetch_row(result); - if (admin) - *admin = atoi(row[0]); - if (account_name) - strcpy(account_name, row[1]); - if (lsaccountid) { +bool ZoneDatabase::GetAccountInfoForLogin_result(MySQLRequestResult results, int16* admin, char* account_name, uint32* lsaccountid, uint8* gmspeed, bool* revoked,bool* gmhideme, uint32* account_creation) { - if (row[2]) - *lsaccountid = atoi(row[2]); - else - *lsaccountid = 0; + if (results.RowCount() != 1) + return false; + auto row = results.begin(); - } - if (gmspeed) - *gmspeed = atoi(row[3]); - if (revoked) - *revoked = atoi(row[4]); - if(gmhideme) - *gmhideme = atoi(row[5]); - if(account_creation) - *account_creation = atoul(row[6]); + if (admin) + *admin = atoi(row[0]); + + if (account_name) + strcpy(account_name, row[1]); + + if (lsaccountid) { + if (row[2]) + *lsaccountid = atoi(row[2]); + else + *lsaccountid = 0; + } + + if (gmspeed) + *gmspeed = atoi(row[3]); + + if (revoked) + *revoked = atoi(row[4]); + + if(gmhideme) + *gmhideme = atoi(row[5]); + + if(account_creation) + *account_creation = atoul(row[6]); + + return true; - return true; - } - else { - return false; - } } diff --git a/zone/zonedb.h b/zone/zonedb.h index dae8c6490..3e5785987 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -246,7 +246,7 @@ public: /* * General Character Related Stuff */ - bool GetAccountInfoForLogin_result(MYSQL_RES* result, int16* admin = 0, char* account_name = 0, + bool GetAccountInfoForLogin_result(MySQLRequestResult results, int16* admin = 0, char* account_name = 0, uint32* lsaccountid = 0, uint8* gmspeed = 0, bool* revoked = 0, bool* gmhideme = nullptr, uint32* account_creation = 0); bool GetCharacterInfoForLogin_result(MYSQL_RES* result, uint32* character_id = 0, char* current_zone = 0,