From 8b05eff17907a5364123e5301b7e6c6f7a8cdef0 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 15:39:03 -0700 Subject: [PATCH] LoadAdventureEntries converted to QueryDatabase --- world/AdventureManager.cpp | 72 ++++++++++++++------------------------ 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/world/AdventureManager.cpp b/world/AdventureManager.cpp index 4aac0c91c..97264ca7c 100644 --- a/world/AdventureManager.cpp +++ b/world/AdventureManager.cpp @@ -693,54 +693,36 @@ bool AdventureManager::LoadAdventureTemplates() bool AdventureManager::LoadAdventureEntries() { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - - if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT id, template_id FROM adventure_template_entry"), errbuf, &result)) + std::string query = "SELECT id, template_id FROM adventure_template_entry"; + auto results = database.QueryDatabase(query); + if (!results.Success()) { - while((row = mysql_fetch_row(result))) - { - int id = atoi(row[0]); - int template_id = atoi(row[1]); - AdventureTemplate* tid = nullptr; - - std::map::iterator t_iter = adventure_templates.find(template_id); - if(t_iter == adventure_templates.end()) - { - continue; - } - else - { - tid = adventure_templates[template_id]; - } - - std::list temp; - std::map >::iterator iter = adventure_entries.find(id); - if(iter == adventure_entries.end()) - { - temp.push_back(tid); - adventure_entries[id] = temp; - } - else - { - temp = adventure_entries[id]; - temp.push_back(tid); - adventure_entries[id] = temp; - } - } - mysql_free_result(result); - safe_delete_array(query); - return true; - } - else - { - LogFile->write(EQEMuLog::Error, "Error in AdventureManager:::LoadAdventureEntries: %s (%s)", query, errbuf); - safe_delete_array(query); + LogFile->write(EQEMuLog::Error, "Error in AdventureManager:::LoadAdventureEntries: %s (%s)", query.c_str(), results.ErrorMessage().c_str()); return false; } - return false; + + for (auto row = results.begin(); row != results.end(); ++row) + { + int id = atoi(row[0]); + int template_id = atoi(row[1]); + AdventureTemplate* tid = nullptr; + + auto t_iter = adventure_templates.find(template_id); + if(t_iter == adventure_templates.end()) + continue; + + tid = adventure_templates[template_id]; + + std::list temp; + auto iter = adventure_entries.find(id); + if(iter == adventure_entries.end()) + temp = adventure_entries[id]; + + temp.push_back(tid); + adventure_entries[id] = temp; + } + + return true; } void AdventureManager::PlayerClickedDoor(const char *player, int zone_id, int door_id)