AzeorthCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Main.cpp File Reference
#include "Banner.h"
#include "Common.h"
#include "Config.h"
#include "DatabaseEnv.h"
#include "DatabaseLoader.h"
#include "IoContext.h"
#include "Log.h"
#include "MySQLThreading.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 
)
121{
122 options_description all("Allowed options");
123 all.add_options()
124 ("help,h", "print usage message")
125 ("version,v", "print version build info")
126 ("dry-run,d", "Dry run")
127 ("config,c", value<fs::path>(&configFile)->default_value(fs::path(sConfigMgr->GetConfigPath() + std::string(_ACORE_DB_IMPORT_CONFIG))), "use <arg> as configuration file");
128
129 variables_map variablesMap;
130
131 try
132 {
133 store(command_line_parser(argc, argv).options(all).allow_unregistered().run(), variablesMap);
134 notify(variablesMap);
135 }
136 catch (std::exception const& e)
137 {
138 std::cerr << e.what() << "\n";
139 }
140
141 if (variablesMap.count("help"))
142 {
143 std::cout << all << "\n";
144 }
145 else if (variablesMap.count("dry-run"))
146 {
147 sConfigMgr->setDryRun(true);
148 }
149
150 return variablesMap;
151}
#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, SSLeay_version(SSLEAY_VERSION));
77 LOG_INFO("dbimport", "> Using Boost version: {}.{}.{}", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
78 }
79 );
80
81 // Initialize the database connection
82 if (!StartDB())
83 return 1;
84
85 std::shared_ptr<void> dbHandle(nullptr, [](void*) { StopDB(); });
86
87 LOG_INFO("dbimport", "Halting process...");
88
89 return 0;
90}
#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:27
bool StartDB()
Initialize connection to the database.
Definition: Main.cpp:93
variables_map GetConsoleArguments(int argc, char **argv, fs::path &configFile)
Definition: Main.cpp:120
void StopDB()
Close the connection to the database.
Definition: Main.cpp:112

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

◆ StartDB()

bool StartDB ( )

Initialize connection to the database.

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

113{
114 CharacterDatabase.Close();
115 WorldDatabase.Close();
116 LoginDatabase.Close();
118}
AC_DATABASE_API void Library_End()
Definition: MySQLThreading.cpp:26

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

Referenced by main().