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 
)
125{
126 options_description all("Allowed options");
127 all.add_options()
128 ("help,h", "print usage message")
129 ("version,v", "print version build info")
130 ("dry-run,d", "Dry run")
131 ("config,c", value<fs::path>(&configFile)->default_value(fs::path(sConfigMgr->GetConfigPath() + std::string(_ACORE_DB_IMPORT_CONFIG))), "use <arg> as configuration file");
132
133 variables_map variablesMap;
134
135 try
136 {
137 store(command_line_parser(argc, argv).options(all).allow_unregistered().run(), variablesMap);
138 notify(variablesMap);
139 }
140 catch (std::exception const& e)
141 {
142 std::cerr << e.what() << "\n";
143 }
144
145 if (variablesMap.count("help"))
146 {
147 std::cout << all << "\n";
148 }
149 else if (variablesMap.count("dry-run"))
150 {
151 sConfigMgr->setDryRun(true);
152 }
153
154 return variablesMap;
155}
#define sConfigMgr
Definition: Config.h:92
#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 // Init logging
66 sLog->Initialize();
67
68 Acore::Banner::Show("dbimport",
69 [](std::string_view text)
70 {
71 LOG_INFO("dbimport", text);
72 },
73 []()
74 {
75 LOG_INFO("dbimport", "> Using configuration file: {}", sConfigMgr->GetFilename());
76 LOG_INFO("dbimport", "> Using SSL version: {} (library: {})", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
77 LOG_INFO("dbimport", "> Using Boost version: {}.{}.{}", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
78 }
79 );
80
82
83 std::shared_ptr<void> opensslHandle(nullptr, [](void*) { OpenSSLCrypto::threadsCleanup(); });
84
85 // Initialize the database connection
86 if (!StartDB())
87 return 1;
88
89 std::shared_ptr<void> dbHandle(nullptr, [](void*) { StopDB(); });
90
91 LOG_INFO("dbimport", "Halting process...");
92
93 return 0;
94}
#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:97
variables_map GetConsoleArguments(int argc, char **argv, fs::path &configFile)
Definition: Main.cpp:124
void StopDB()
Close the connection to the database.
Definition: Main.cpp:116

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.

98{
100
101 // Load databases
102 DatabaseLoader loader("dbimport");
103 loader
104 .AddDatabase(LoginDatabase, "Login")
105 .AddDatabase(CharacterDatabase, "Character")
106 .AddDatabase(WorldDatabase, "World");
107
108 if (!loader.Load())
109 return false;
110
111 LOG_INFO("dbimport", "Started database connection pool.");
112 return true;
113}
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.

117{
118 CharacterDatabase.Close();
119 WorldDatabase.Close();
120 LoginDatabase.Close();
122}
AC_DATABASE_API void Library_End()
Definition: MySQLThreading.cpp:26

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

Referenced by main().