diff options
Diffstat (limited to 'src/server/bnetserver/Main.cpp')
-rw-r--r-- | src/server/bnetserver/Main.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp index e1c0b187c46..8cb5553ea93 100644 --- a/src/server/bnetserver/Main.cpp +++ b/src/server/bnetserver/Main.cpp @@ -51,11 +51,25 @@ using namespace boost::program_options; # define _TRINITY_BNET_CONFIG "bnetserver.conf" #endif +#ifdef _WIN32 +#include "ServiceWin32.h" +char serviceName[] = "bnetserver"; +char serviceLongName[] = "TrinityCore bnet service"; +char serviceDescription[] = "TrinityCore Battle.net emulator authentication 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); static std::unique_ptr<boost::asio::io_service> _ioService; static std::unique_ptr<boost::asio::deadline_timer> _dbPingTimer; @@ -65,11 +79,21 @@ LoginDatabaseWorkerPool LoginDatabase; int main(int argc, char** argv) { std::string configFile = _TRINITY_BNET_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)) { @@ -211,24 +235,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_BNET_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"; } |