AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Main.cpp File Reference
#include "Banner.h"
#include "Config.h"
#include "DBUpdater.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.
 
void StopDB ()
 Close the connection to the database.
 
variables_map GetConsoleArguments (int argc, char **argv, fs::path &configFile)
 
int main (int argc, char **argv)
 Launch the db import server.
 

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 
)
144{
145 options_description all("Allowed options");
146 all.add_options()
147 ("help,h", "print usage message")
148 ("version,v", "print version build info")
149 ("dry-run,d", "Dry run")
150 ("config,c", value<fs::path>(&configFile)->default_value(fs::path(sConfigMgr->GetConfigPath() + std::string(_ACORE_DB_IMPORT_CONFIG))), "use <arg> as configuration file")
151 ("config-policy", value<std::string>()->value_name("policy"), "override config severity policy (e.g. default=skip,critical_option=fatal)");
152
153 variables_map variablesMap;
154
155 try
156 {
157 store(command_line_parser(argc, argv).options(all).allow_unregistered().run(), variablesMap);
158 notify(variablesMap);
159 }
160 catch (std::exception const& e)
161 {
162 std::cerr << e.what() << "\n";
163 }
164
165 if (variablesMap.count("help"))
166 {
167 std::cout << all << "\n";
168 }
169 else if (variablesMap.count("dry-run"))
170 {
171 sConfigMgr->setDryRun(true);
172 }
173
174 return variablesMap;
175}
#define sConfigMgr
Definition Config.h:93
#define _ACORE_DB_IMPORT_CONFIG
Definition Main.cpp:37

References _ACORE_DB_IMPORT_CONFIG, and sConfigMgr.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Launch the db import server.

49{
50 signal(SIGABRT, &Acore::AbortHandler);
51
52 // Command line parsing
53 auto configFile = fs::path(sConfigMgr->GetConfigPath() + std::string(_ACORE_DB_IMPORT_CONFIG));
54 auto vm = GetConsoleArguments(argc, argv, configFile);
55
56 // exit if help is enabled
57 if (vm.count("help"))
58 return 0;
59
60 // Add file and args in config
61 sConfigMgr->Configure(configFile.generic_string(), std::vector<std::string>(argv, argv + argc));
62
63 if (!sConfigMgr->LoadAppConfigs())
64 return 1;
65
66 std::vector<std::string> overriddenKeys = sConfigMgr->OverrideWithEnvVariablesIfAny();
67
68 // Init logging
69 sLog->Initialize();
70
71 Acore::Banner::Show("dbimport",
72 [](std::string_view text)
73 {
74 LOG_INFO("dbimport", text);
75 },
76 []()
77 {
78 LOG_INFO("dbimport", "> Using configuration file: {}", sConfigMgr->GetFilename());
79 LOG_INFO("dbimport", "> Using SSL version: {} (library: {})", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
80 LOG_INFO("dbimport", "> Using Boost version: {}.{}.{}", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
81 }
82 );
83
84 for (std::string const& key : overriddenKeys)
85 LOG_INFO("dbimport", "Configuration field {} was overridden with environment variable.", key);
86
88
89 std::shared_ptr<void> opensslHandle(nullptr, [](void*) { OpenSSLCrypto::threadsCleanup(); });
90
91 // Initialize the database connection
92 if (!StartDB())
93 return 1;
94
95 std::shared_ptr<void> dbHandle(nullptr, [](void*) { StopDB(); });
96
97 LOG_INFO("dbimport", "Halting process...");
98
100 {
101 LOG_FATAL("dbimport", "{} update file(s) failed to apply!", failed);
102 return 1;
103 }
104
105 return 0;
106}
std::uint32_t uint32
Definition Define.h:107
#define LOG_FATAL(filterType__,...)
Definition Log.h:141
#define LOG_INFO(filterType__,...)
Definition Log.h:153
#define sLog
Definition Log.h:127
static uint32 GetFailedUpdateCount()
Definition DBUpdater.cpp:79
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 AbortHandler(int sigval)
Definition Errors.cpp:148
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:109
variables_map GetConsoleArguments(int argc, char **argv, fs::path &configFile)
Definition Main.cpp:143
void StopDB()
Close the connection to the database.
Definition Main.cpp:135

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

◆ StartDB()

bool StartDB ( )

Initialize connection to the database.

110{
112
113 // Load modules conditionally based on what modules are allowed to auto-update or none
114 std::string modules = sConfigMgr->GetOption<std::string>("Updates.AllowedModules", "all");
115 LOG_INFO("dbimport", "Loading modules: {}", modules.empty() ? "none" : modules);
116
117 DatabaseLoader loader =
118 modules.empty() ? DatabaseLoader("dbimport") :
119 (modules == "all") ? DatabaseLoader("dbimport", DatabaseLoader::DATABASE_MASK_ALL, AC_MODULES_LIST) :
120 DatabaseLoader("dbimport", DatabaseLoader::DATABASE_MASK_ALL, modules);
121
122 loader
123 .AddDatabase(LoginDatabase, "Login")
124 .AddDatabase(CharacterDatabase, "Character")
125 .AddDatabase(WorldDatabase, "World");
126
127 if (!loader.Load())
128 return false;
129
130 LOG_INFO("dbimport", "Started database connection pool.");
131 return true;
132}
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
Definition DatabaseLoader.h:33
DatabaseLoader & AddDatabase(DatabaseWorkerPool< T > &pool, std::string const &name)
Definition DatabaseLoader.cpp:53
bool Load()
Definition DatabaseLoader.cpp:173
AC_DATABASE_API void Library_Init()
Definition MySQLThreading.cpp:21

References CharacterDatabase, DatabaseLoader::DATABASE_MASK_ALL, MySQL::Library_Init(), LOG_INFO, LoginDatabase, sConfigMgr, and WorldDatabase.

Referenced by main().

◆ StopDB()

void StopDB ( )

Close the connection to the database.

136{
137 CharacterDatabase.Close();
138 WorldDatabase.Close();
139 LoginDatabase.Close();
141}
AC_DATABASE_API void Library_End()
Definition MySQLThreading.cpp:26

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

Referenced by main().