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.
 
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 
)
132{
133 options_description all("Allowed options");
134 all.add_options()
135 ("help,h", "print usage message")
136 ("version,v", "print version build info")
137 ("dry-run,d", "Dry run")
138 ("config,c", value<fs::path>(&configFile)->default_value(fs::path(sConfigMgr->GetConfigPath() + std::string(_ACORE_DB_IMPORT_CONFIG))), "use <arg> as configuration file");
139
140 variables_map variablesMap;
141
142 try
143 {
144 store(command_line_parser(argc, argv).options(all).allow_unregistered().run(), variablesMap);
145 notify(variablesMap);
146 }
147 catch (std::exception const& e)
148 {
149 std::cerr << e.what() << "\n";
150 }
151
152 if (variablesMap.count("help"))
153 {
154 std::cout << all << "\n";
155 }
156 else if (variablesMap.count("dry-run"))
157 {
158 sConfigMgr->setDryRun(true);
159 }
160
161 return variablesMap;
162}
#define sConfigMgr
Definition: Config.h:95
#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:167
#define sLog
Definition: Log.h:128
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:63
AC_COMMON_API void threadsCleanup()
Needs to be called after threads using openssl are despawned.
Definition: OpenSSLCrypto.cpp:87
bool StartDB()
Initialize connection to the database.
Definition: Main.cpp:102
variables_map GetConsoleArguments(int argc, char **argv, fs::path &configFile)
Definition: Main.cpp:131
void StopDB()
Close the connection to the database.
Definition: Main.cpp:123

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 databases
107 DatabaseLoader loader("dbimport");
108 loader
109 .AddDatabase(LoginDatabase, "Login")
110 .AddDatabase(CharacterDatabase, "Character")
111 .AddDatabase(WorldDatabase, "World")
112 .AddDatabase(DBCDatabase, "DBC")
113 .AddDatabase(ModuleDatabase, "Module");
114
115 if (!loader.Load())
116 return false;
117
118 LOG_INFO("dbimport", "Started database connection pool.");
119 return true;
120}
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
DatabaseWorkerPool< ModuleDatabaseConnection > ModuleDatabase
Accessor to the module database.
Definition: DatabaseEnv.cpp:24
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
DatabaseWorkerPool< DBCDatabaseConnection > DBCDatabase
Accessor to the DBC database.
Definition: DatabaseEnv.cpp:23
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

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

Referenced by main().

◆ StopDB()

void StopDB ( )

Close the connection to the database.

124{
125 CharacterDatabase.Close();
126 WorldDatabase.Close();
127 LoginDatabase.Close();
129}
AC_DATABASE_API void Library_End()
Definition: MySQLThreading.cpp:26

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

Referenced by main().