From a37260fec5a637d7e310b02c5344711d76c170d8 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Thu, 12 Mar 2020 01:32:25 -0500 Subject: [PATCH] Port import and eport client files to use content database connection [skip ci] --- client_files/export/main.cpp | 33 ++++++++++++++++++++++++------- client_files/import/main.cpp | 38 +++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/client_files/export/main.cpp b/client_files/export/main.cpp index efd8f28c8..a6f3c3bec 100644 --- a/client_files/export/main.cpp +++ b/client_files/export/main.cpp @@ -49,6 +49,8 @@ int main(int argc, char **argv) auto Config = EQEmuConfig::get(); SharedDatabase database; + SharedDatabase content_db; + LogInfo("Connecting to database"); if (!database.Connect( Config->DatabaseHost.c_str(), @@ -61,7 +63,24 @@ int main(int argc, char **argv) return 1; } - /* Register Log System and Settings */ + /** + * Multi-tenancy: Content database + */ + if (!Config->ContentDbHost.empty()) { + if (!content_db.Connect( + Config->ContentDbHost.c_str() , + Config->ContentDbUsername.c_str(), + Config->ContentDbPassword.c_str(), + Config->ContentDbName.c_str(), + Config->ContentDbPort + )) { + LogError("Cannot continue without a content database connection"); + return 1; + } + } else { + content_db.SetMysql(database.getMySQL()); + } + database.LoadLogSettings(LogSys.log_settings); LogSys.StartFileLogs(); @@ -72,15 +91,15 @@ int main(int argc, char **argv) } if (arg_1 == "spells") { - ExportSpells(&database); + ExportSpells(&content_db); return 0; } if (arg_1 == "skills") { - ExportSkillCaps(&database); + ExportSkillCaps(&content_db); return 0; } if (arg_1 == "basedata") { - ExportBaseData(&database); + ExportBaseData(&content_db); return 0; } if (arg_1 == "dbstring") { @@ -88,9 +107,9 @@ int main(int argc, char **argv) return 0; } - ExportSpells(&database); - ExportSkillCaps(&database); - ExportBaseData(&database); + ExportSpells(&content_db); + ExportSkillCaps(&content_db); + ExportBaseData(&content_db); ExportDBStrings(&database); LogSys.CloseFileLogs(); diff --git a/client_files/import/main.cpp b/client_files/import/main.cpp index 109ff4859..3c25fa618 100644 --- a/client_files/import/main.cpp +++ b/client_files/import/main.cpp @@ -46,20 +46,44 @@ int main(int argc, char **argv) { auto Config = EQEmuConfig::get(); SharedDatabase database; + SharedDatabase content_db; + LogInfo("Connecting to database"); - if(!database.Connect(Config->DatabaseHost.c_str(), Config->DatabaseUsername.c_str(), - Config->DatabasePassword.c_str(), Config->DatabaseDB.c_str(), Config->DatabasePort)) { - LogError("Unable to connect to the database, cannot continue without a " - "database connection"); + if (!database.Connect( + Config->DatabaseHost.c_str(), + Config->DatabaseUsername.c_str(), + Config->DatabasePassword.c_str(), + Config->DatabaseDB.c_str(), + Config->DatabasePort + )) { + LogError("Unable to connect to the database, cannot continue without a database connection"); return 1; } + /** + * Multi-tenancy: Content database + */ + if (!Config->ContentDbHost.empty()) { + if (!content_db.Connect( + Config->ContentDbHost.c_str() , + Config->ContentDbUsername.c_str(), + Config->ContentDbPassword.c_str(), + Config->ContentDbName.c_str(), + Config->ContentDbPort + )) { + LogError("Cannot continue without a content database connection"); + return 1; + } + } else { + content_db.SetMysql(database.getMySQL()); + } + database.LoadLogSettings(LogSys.log_settings); LogSys.StartFileLogs(); - ImportSpells(&database); - ImportSkillCaps(&database); - ImportBaseData(&database); + ImportSpells(&content_db); + ImportSkillCaps(&content_db); + ImportBaseData(&content_db); ImportDBStrings(&database); LogSys.CloseFileLogs();