Core/Auth: Implemented starting authserver as a windows service

This commit is contained in:
Shauren
2015-06-06 13:04:31 +02:00
parent 3aa1774100
commit ee4ace8c34

View File

@@ -46,11 +46,25 @@ using namespace boost::program_options;
# define _TRINITY_REALM_CONFIG "authserver.conf"
#endif
#ifdef _WIN32
#include "ServiceWin32.h"
char serviceName[] = "authserver";
char serviceLongName[] = "TrinityCore auth service";
char serviceDescription[] = "TrinityCore World of Warcraft emulator auth service";
/*
* -1 - not in service mode
* 0 - stopped
* 1 - running
* 2 - paused
*/
int m_ServiceStatus = -1;
#endif
bool StartDB();
void StopDB();
void SignalHandler(const boost::system::error_code& error, int signalNumber);
void KeepDatabaseAliveHandler(const boost::system::error_code& error);
variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile);
variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile, std::string& configService);
boost::asio::io_service _ioService;
boost::asio::deadline_timer _dbPingTimer(_ioService);
@@ -60,11 +74,21 @@ LoginDatabaseWorkerPool LoginDatabase;
int main(int argc, char** argv)
{
std::string configFile = _TRINITY_REALM_CONFIG;
auto vm = GetConsoleArguments(argc, argv, configFile);
std::string configService;
auto vm = GetConsoleArguments(argc, argv, configFile, configService);
// exit if help is enabled
if (vm.count("help"))
return 0;
#ifdef _WIN32
if (configService.compare("install") == 0)
return WinServiceInstall() == true ? 0 : 1;
else if (configService.compare("uninstall") == 0)
return WinServiceUninstall() == true ? 0 : 1;
else if (configService.compare("run") == 0)
WinServiceRun();
#endif
std::string configError;
if (!sConfigMgr->LoadInitial(configFile, configError))
{
@@ -189,26 +213,34 @@ void KeepDatabaseAliveHandler(const boost::system::error_code& error)
}
}
variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile)
variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile, std::string& configService)
{
options_description all("Allowed options");
all.add_options()
("help,h", "print usage message")
("config,c", value<std::string>(&configFile)->default_value(_TRINITY_REALM_CONFIG), "use <arg> as configuration file")
;
#ifdef _WIN32
options_description win("Windows platform specific options");
win.add_options()
("service,s", value<std::string>(&configService)->default_value(""), "Windows service options: [install | uninstall]")
;
all.add(win);
#endif
variables_map variablesMap;
try
{
store(command_line_parser(argc, argv).options(all).allow_unregistered().run(), variablesMap);
notify(variablesMap);
}
catch (std::exception& e) {
catch (std::exception& e)
{
std::cerr << e.what() << "\n";
}
if (variablesMap.count("help")) {
if (variablesMap.count("help"))
std::cout << all << "\n";
}
return variablesMap;
}