Migrate adventure database calls [skip ci]

This commit is contained in:
Akkadius 2020-03-11 03:00:08 -05:00
parent dde9b98e4f
commit 7cf52d467e
7 changed files with 105 additions and 46 deletions

View File

@ -632,53 +632,90 @@ AdventureTemplate *AdventureManager::GetAdventureTemplate(int id)
bool AdventureManager::LoadAdventureTemplates() bool AdventureManager::LoadAdventureTemplates()
{ {
std::string query = "SELECT id, zone, zone_version, " std::string query =
"is_hard, min_level, max_level, type, type_data, type_count, assa_x, " SQL (
"assa_y, assa_z, assa_h, text, duration, zone_in_time, win_points, lose_points, " SELECT
"theme, zone_in_zone_id, zone_in_x, zone_in_y, zone_in_object_id, dest_x, dest_y, " id,
"dest_z, dest_h, graveyard_zone_id, graveyard_x, graveyard_y, graveyard_z, " zone,
"graveyard_radius FROM adventure_template"; zone_version,
is_hard,
min_level,
max_level,
type,
type_data,
type_count,
assa_x,
assa_y,
assa_z,
assa_h,
text,
duration,
zone_in_time,
win_points,
lose_points,
theme,
zone_in_zone_id,
zone_in_x,
zone_in_y,
zone_in_object_id,
dest_x,
dest_y,
dest_z,
dest_h,
graveyard_zone_id,
graveyard_x,
graveyard_y,
graveyard_z,
graveyard_radius
FROM
adventure_template
)
;
auto results = database.QueryDatabase(query); auto results = database.QueryDatabase(query);
if (!results.Success()) { if (!results.Success()) {
return false; return false;
} }
for (auto row = results.begin(); row != results.end(); ++row) { for (auto row = results.begin(); row != results.end(); ++row) {
auto aTemplate = new AdventureTemplate; auto adventure_template = new AdventureTemplate;
aTemplate->id = atoi(row[0]); adventure_template->id = atoi(row[0]);
strcpy(aTemplate->zone, row[1]); strcpy(adventure_template->zone, row[1]);
aTemplate->zone_version = atoi(row[2]);
aTemplate->is_hard = atoi(row[3]); adventure_template->zone_version = atoi(row[2]);
aTemplate->min_level = atoi(row[4]); adventure_template->is_hard = atoi(row[3]);
aTemplate->max_level = atoi(row[5]); adventure_template->min_level = atoi(row[4]);
aTemplate->type = atoi(row[6]); adventure_template->max_level = atoi(row[5]);
aTemplate->type_data = atoi(row[7]); adventure_template->type = atoi(row[6]);
aTemplate->type_count = atoi(row[8]); adventure_template->type_data = atoi(row[7]);
aTemplate->assa_x = atof(row[9]); adventure_template->type_count = atoi(row[8]);
aTemplate->assa_y = atof(row[10]); adventure_template->assa_x = atof(row[9]);
aTemplate->assa_z = atof(row[11]); adventure_template->assa_y = atof(row[10]);
aTemplate->assa_h = atof(row[12]); adventure_template->assa_z = atof(row[11]);
strn0cpy(aTemplate->text, row[13], sizeof(aTemplate->text)); adventure_template->assa_h = atof(row[12]);
aTemplate->duration = atoi(row[14]);
aTemplate->zone_in_time = atoi(row[15]); strn0cpy(adventure_template->text, row[13], sizeof(adventure_template->text));
aTemplate->win_points = atoi(row[16]);
aTemplate->lose_points = atoi(row[17]); adventure_template->duration = atoi(row[14]);
aTemplate->theme = atoi(row[18]); adventure_template->zone_in_time = atoi(row[15]);
aTemplate->zone_in_zone_id = atoi(row[19]); adventure_template->win_points = atoi(row[16]);
aTemplate->zone_in_x = atof(row[20]); adventure_template->lose_points = atoi(row[17]);
aTemplate->zone_in_y = atof(row[21]); adventure_template->theme = atoi(row[18]);
aTemplate->zone_in_object_id = atoi(row[22]); adventure_template->zone_in_zone_id = atoi(row[19]);
aTemplate->dest_x = atof(row[23]); adventure_template->zone_in_x = atof(row[20]);
aTemplate->dest_y = atof(row[24]); adventure_template->zone_in_y = atof(row[21]);
aTemplate->dest_z = atof(row[25]); adventure_template->zone_in_object_id = atoi(row[22]);
aTemplate->dest_h = atof(row[26]); adventure_template->dest_x = atof(row[23]);
aTemplate->graveyard_zone_id = atoi(row[27]); adventure_template->dest_y = atof(row[24]);
aTemplate->graveyard_x = atof(row[28]); adventure_template->dest_z = atof(row[25]);
aTemplate->graveyard_y = atof(row[29]); adventure_template->dest_h = atof(row[26]);
aTemplate->graveyard_z = atof(row[30]); adventure_template->graveyard_zone_id = atoi(row[27]);
aTemplate->graveyard_radius = atof(row[31]); adventure_template->graveyard_x = atof(row[28]);
adventure_templates[aTemplate->id] = aTemplate; adventure_template->graveyard_y = atof(row[29]);
} adventure_template->graveyard_z = atof(row[30]);
adventure_template->graveyard_radius = atof(row[31]);
adventure_templates[adventure_template->id] = adventure_template;
}
return true; return true;
} }
@ -686,7 +723,7 @@ bool AdventureManager::LoadAdventureTemplates()
bool AdventureManager::LoadAdventureEntries() bool AdventureManager::LoadAdventureEntries()
{ {
std::string query = "SELECT id, template_id FROM adventure_template_entry"; std::string query = "SELECT id, template_id FROM adventure_template_entry";
auto results = database.QueryDatabase(query); auto results = content_db.QueryDatabase(query);
if (!results.Success()) if (!results.Success())
{ {
return false; return false;

View File

@ -137,6 +137,25 @@ void LoadDatabaseConnections()
std::exit(1); std::exit(1);
} }
/**
* Multi-tenancy: Content database
*/
if (!Config->ContentDbHost.empty()) {
if (!content_db.Connect(
!Config->ContentDbHost.empty() ? Config->ContentDbHost.c_str() : Config->DatabaseHost.c_str(),
!Config->ContentDbUsername.empty() ? Config->ContentDbUsername.c_str() : Config->DatabaseUsername.c_str(),
!Config->ContentDbPassword.empty() ? Config->ContentDbPassword.c_str() : Config->DatabasePassword.c_str(),
!Config->ContentDbName.empty() ? Config->ContentDbName.c_str() : Config->DatabaseDB.c_str(),
Config->ContentDbPort != 0 ? Config->ContentDbPort : Config->DatabasePort
)) {
LogError("Cannot continue without a content database connection");
std::exit(1);
}
} else {
content_db.SetMysql(database.getMySQL());
}
} }
void CheckForXMLConfigUpgrade() void CheckForXMLConfigUpgrade()
@ -587,6 +606,7 @@ int main(int argc, char** argv) {
if (InterserverTimer.Check()) { if (InterserverTimer.Check()) {
InterserverTimer.Start(); InterserverTimer.Start();
database.ping(); database.ping();
content_db.ping();
std::string window_title = StringFormat("World: %s Clients: %i", Config->LongName.c_str(), client_list.GetClientCount()); std::string window_title = StringFormat("World: %s Clients: %i", Config->LongName.c_str(), client_list.GetClientCount());
UpdateWindowTitle(window_title); UpdateWindowTitle(window_title);

View File

@ -27,6 +27,7 @@
#include "sof_char_create_data.h" #include "sof_char_create_data.h"
WorldDatabase database; WorldDatabase database;
WorldDatabase content_db;
extern std::vector<RaceClassAllocation> character_create_allocations; extern std::vector<RaceClassAllocation> character_create_allocations;
extern std::vector<RaceClassCombos> character_create_race_class_combos; extern std::vector<RaceClassCombos> character_create_race_class_combos;

View File

@ -46,5 +46,6 @@ private:
}; };
extern WorldDatabase database; extern WorldDatabase database;
extern WorldDatabase content_db;
#endif /*WORLDDB_H_*/ #endif /*WORLDDB_H_*/

View File

@ -1595,7 +1595,7 @@ bool Mob::CanPurchaseAlternateAdvancementRank(AA::Rank *rank, bool check_price,
void Zone::LoadAlternateAdvancement() { void Zone::LoadAlternateAdvancement() {
LogInfo("Loading Alternate Advancement Data"); LogInfo("Loading Alternate Advancement Data");
if(!database.LoadAlternateAdvancementAbilities(aa_abilities, if(!content_db.LoadAlternateAdvancementAbilities(aa_abilities,
aa_ranks)) aa_ranks))
{ {
aa_abilities.clear(); aa_abilities.clear();

View File

@ -8225,7 +8225,7 @@ void command_npcedit(Client *c, const Seperator *sep)
if (strcasecmp(sep->arg[1], "adventure_template_id") == 0) { if (strcasecmp(sep->arg[1], "adventure_template_id") == 0) {
c->Message(Chat::Yellow,"NPCID %u now has field 'adventure_template_id' set to %s.", npcTypeID, sep->argplus[2]); c->Message(Chat::Yellow,"NPCID %u now has field 'adventure_template_id' set to %s.", npcTypeID, sep->argplus[2]);
std::string query = StringFormat("UPDATE npc_types SET adventure_template_id = '%s' WHERE id = %i", sep->argplus[2],npcTypeID); std::string query = StringFormat("UPDATE npc_types SET adventure_template_id = '%s' WHERE id = %i", sep->argplus[2],npcTypeID);
database.QueryDatabase(query); content_db.QueryDatabase(query);
return; return;
} }

View File

@ -2209,7 +2209,7 @@ void Zone::DeleteQGlobal(std::string name, uint32 npcID, uint32 charID, uint32 z
void Zone::LoadAdventureFlavor() void Zone::LoadAdventureFlavor()
{ {
const std::string query = "SELECT id, text FROM adventure_template_entry_flavor"; const std::string query = "SELECT id, text FROM adventure_template_entry_flavor";
auto results = database.QueryDatabase(query); auto results = content_db.QueryDatabase(query);
if (!results.Success()) { if (!results.Success()) {
return; return;
} }