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

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
113 if (!loader.Load())
114 return false;
115
116 LOG_INFO("dbimport", "Started database connection pool.");
117 return true;
118}
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

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

Referenced by main().

◆ StopDB()

void StopDB ( )

Close the connection to the database.

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

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

Referenced by main().