AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Main.cpp File Reference
#include "Banner.h"
#include "Config.h"
#include "DatabaseEnv.h"
#include "DatabaseLoader.h"
#include "IoContext.h"
#include "Log.h"
#include "MySQLThreading.h"
#include "OpenSSLCrypto.h"
#include "Util.h"
#include <boost/program_options.hpp>
#include <boost/version.hpp>
#include <csignal>
#include <filesystem>
#include <iostream>
#include <openssl/crypto.h>
#include <openssl/opensslv.h>

Go to the source code of this file.

Macros

#define _ACORE_DB_IMPORT_CONFIG   "dbimport.conf"
 

Functions

bool StartDB ()
 Initialize connection to the database. More...
 
void StopDB ()
 Close the connection to the database. More...
 
variables_map GetConsoleArguments (int argc, char **argv, fs::path &configFile)
 
int main (int argc, char **argv)
 Launch the db import server. More...
 

Macro Definition Documentation

◆ _ACORE_DB_IMPORT_CONFIG

#define _ACORE_DB_IMPORT_CONFIG   "dbimport.conf"

Function Documentation

◆ GetConsoleArguments()

variables_map GetConsoleArguments ( int  argc,
char **  argv,
fs::path &  configFile 
)
137{
138 options_description all("Allowed options");
139 all.add_options()
140 ("help,h", "print usage message")
141 ("version,v", "print version build info")
142 ("dry-run,d", "Dry run")
143 ("config,c", value<fs::path>(&configFile)->default_value(fs::path(sConfigMgr->GetConfigPath() + std::string(_ACORE_DB_IMPORT_CONFIG))), "use <arg> as configuration file");
144
145 variables_map variablesMap;
146
147 try
148 {
149 store(command_line_parser(argc, argv).options(all).allow_unregistered().run(), variablesMap);
150 notify(variablesMap);
151 }
152 catch (std::exception const& e)
153 {
154 std::cerr << e.what() << "\n";
155 }
156
157 if (variablesMap.count("help"))
158 {
159 std::cout << all << "\n";
160 }
161 else if (variablesMap.count("dry-run"))
162 {
163 sConfigMgr->setDryRun(true);
164 }
165
166 return variablesMap;
167}
#define sConfigMgr
Definition: Config.h:74
#define _ACORE_DB_IMPORT_CONFIG
Definition: Main.cpp:36

References _ACORE_DB_IMPORT_CONFIG, and sConfigMgr.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Launch the db import server.

48{
49 signal(SIGABRT, &Acore::AbortHandler);
50
51 // Command line parsing
52 auto configFile = fs::path(sConfigMgr->GetConfigPath() + std::string(_ACORE_DB_IMPORT_CONFIG));
53 auto vm = GetConsoleArguments(argc, argv, configFile);
54
55 // exit if help is enabled
56 if (vm.count("help"))
57 return 0;
58
59 // Add file and args in config
60 sConfigMgr->Configure(configFile.generic_string(), std::vector<std::string>(argv, argv + argc));
61
62 if (!sConfigMgr->LoadAppConfigs())
63 return 1;
64
65 std::vector<std::string> overriddenKeys = sConfigMgr->OverrideWithEnvVariablesIfAny();
66
67 // Init logging
68 sLog->Initialize();
69
70 Acore::Banner::Show("dbimport",
71 [](std::string_view text)
72 {
73 LOG_INFO("dbimport", text);
74 },
75 []()
76 {
77 LOG_INFO("dbimport", "> Using configuration file: {}", sConfigMgr->GetFilename());
78 LOG_INFO("dbimport", "> Using SSL version: {} (library: {})", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
79 LOG_INFO("dbimport", "> Using Boost version: {}.{}.{}", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
80 }
81 );
82
83 for (std::string const& key : overriddenKeys)
84 LOG_INFO("dbimport", "Configuration field {} was overridden with environment variable.", key);
85
87
88 std::shared_ptr<void> opensslHandle(nullptr, [](void*) { OpenSSLCrypto::threadsCleanup(); });
89
90 // Initialize the database connection
91 if (!StartDB())
92 return 1;
93
94 std::shared_ptr<void> dbHandle(nullptr, [](void*) { StopDB(); });
95
96 LOG_INFO("dbimport", "Halting process...");
97
98 return 0;
99}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define sLog
Definition: Log.h:126
AC_COMMON_API void AbortHandler(int sigval)
Definition: Errors.cpp:148
AC_COMMON_API void Show(std::string_view applicationName, void(*log)(std::string_view text), void(*logExtraInfo)())
Definition: Banner.cpp:22
AC_COMMON_API void threadsSetup()
Needs to be called before threads using openssl are spawned.
Definition: OpenSSLCrypto.cpp:41
AC_COMMON_API void threadsCleanup()
Needs to be called after threads using openssl are despawned.
Definition: OpenSSLCrypto.cpp:50
bool StartDB()
Initialize connection to the database.
Definition: Main.cpp:102
variables_map GetConsoleArguments(int argc, char **argv, fs::path &configFile)
Definition: Main.cpp:136
void StopDB()
Close the connection to the database.
Definition: Main.cpp:128

References _ACORE_DB_IMPORT_CONFIG, Acore::AbortHandler(), GetConsoleArguments(), LOG_INFO, sConfigMgr, Acore::Banner::Show(), sLog, StartDB(), StopDB(), OpenSSLCrypto::threadsCleanup(), and OpenSSLCrypto::threadsSetup().

◆ StartDB()

bool StartDB ( )

Initialize connection to the database.

103{
105
106 // Load modules conditionally based on what modules are allowed to auto-update or none
107 std::string modules = sConfigMgr->GetOption<std::string>("Updates.AllowedModules", "all");
108 LOG_INFO("dbimport", "Loading modules: {}", modules.empty() ? "none" : modules);
109
110 DatabaseLoader loader =
111 modules.empty() ? DatabaseLoader("dbimport") :
112 (modules == "all") ? DatabaseLoader("dbimport", DatabaseLoader::DATABASE_NONE, AC_MODULES_LIST) :
113 DatabaseLoader("dbimport", DatabaseLoader::DATABASE_NONE, modules);
114
115 loader
116 .AddDatabase(LoginDatabase, "Login")
117 .AddDatabase(CharacterDatabase, "Character")
118 .AddDatabase(WorldDatabase, "World");
119
120 if (!loader.Load())
121 return false;
122
123 LOG_INFO("dbimport", "Started database connection pool.");
124 return true;
125}
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
AC_DATABASE_API void Library_Init()
Definition: MySQLThreading.cpp:21
Definition: DatabaseLoader.h:33
DatabaseLoader & AddDatabase(DatabaseWorkerPool< T > &pool, std::string const &name)
Definition: DatabaseLoader.cpp:35
bool Load()
Definition: DatabaseLoader.cpp:154

References DatabaseLoader::AddDatabase(), CharacterDatabase, DatabaseLoader::DATABASE_NONE, MySQL::Library_Init(), DatabaseLoader::Load(), LOG_INFO, LoginDatabase, sConfigMgr, and WorldDatabase.

Referenced by main().

◆ StopDB()

void StopDB ( )

Close the connection to the database.

129{
130 CharacterDatabase.Close();
131 WorldDatabase.Close();
132 LoginDatabase.Close();
134}
AC_DATABASE_API void Library_End()
Definition: MySQLThreading.cpp:26

References CharacterDatabase, MySQL::Library_End(), LoginDatabase, and WorldDatabase.

Referenced by main().