aboutsummaryrefslogtreecommitdiff
path: root/src/server/bnetserver/Main.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2015-06-10 00:21:55 +0200
committerShauren <shauren.trinity@gmail.com>2015-06-10 00:21:55 +0200
commit50848e4dacde7c402d5a7c1f548573e63845079a (patch)
treee3ad22507a9403c6603f027d8829b340271ccf04 /src/server/bnetserver/Main.cpp
parentd4ad3843e9203ba6fabe4ea4177d5eba5e7e563f (diff)
Core/Bnet: Fixed bnetserver not shutting down correctly when started as windows service
Diffstat (limited to 'src/server/bnetserver/Main.cpp')
-rw-r--r--src/server/bnetserver/Main.cpp59
1 files changed, 47 insertions, 12 deletions
diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp
index 8cb5553ea93..86590bfa3f5 100644
--- a/src/server/bnetserver/Main.cpp
+++ b/src/server/bnetserver/Main.cpp
@@ -51,7 +51,7 @@ using namespace boost::program_options;
# define _TRINITY_BNET_CONFIG "bnetserver.conf"
#endif
-#ifdef _WIN32
+#if PLATFORM == PLATFORM_WINDOWS
#include "ServiceWin32.h"
char serviceName[] = "bnetserver";
char serviceLongName[] = "TrinityCore bnet service";
@@ -63,6 +63,9 @@ char serviceDescription[] = "TrinityCore Battle.net emulator authentication serv
* 2 - paused
*/
int m_ServiceStatus = -1;
+
+static boost::asio::deadline_timer* _serviceStatusWatchTimer;
+void ServiceStatusWatcher(boost::system::error_code const& error);
#endif
bool StartDB();
@@ -71,8 +74,8 @@ 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, std::string& configService);
-static std::unique_ptr<boost::asio::io_service> _ioService;
-static std::unique_ptr<boost::asio::deadline_timer> _dbPingTimer;
+static boost::asio::io_service* _ioService;
+static boost::asio::deadline_timer* _dbPingTimer;
static uint32 _dbPingInterval;
LoginDatabaseWorkerPool LoginDatabase;
@@ -85,13 +88,13 @@ int main(int argc, char** argv)
if (vm.count("help"))
return 0;
-#ifdef _WIN32
+#if PLATFORM == PLATFORM_WINDOWS
if (configService.compare("install") == 0)
- return WinServiceInstall() == true ? 0 : 1;
+ return WinServiceInstall() ? 0 : 1;
else if (configService.compare("uninstall") == 0)
- return WinServiceUninstall() == true ? 0 : 1;
+ return WinServiceUninstall() ? 0 : 1;
else if (configService.compare("run") == 0)
- WinServiceRun();
+ return WinServiceRun() ? 0 : 1;
#endif
std::string configError;
@@ -133,7 +136,7 @@ int main(int argc, char** argv)
sIpcContext->Initialize();
- _ioService.reset(new boost::asio::io_service());
+ _ioService = new boost::asio::io_service();
// Get the list of realms for the server
sRealmList->Initialize(*_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10), worldListenPort);
@@ -144,6 +147,7 @@ int main(int argc, char** argv)
{
TC_LOG_ERROR("server.bnetserver", "Specified battle.net port (%d) out of allowed range (1-65535)", bnport);
StopDB();
+ delete _ioService;
return 1;
}
@@ -163,13 +167,22 @@ int main(int argc, char** argv)
// Enabled a timed callback for handling the database keep alive ping
_dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
- _dbPingTimer.reset(new boost::asio::deadline_timer(*_ioService));
+ _dbPingTimer = new boost::asio::deadline_timer(*_ioService);
_dbPingTimer->expires_from_now(boost::posix_time::minutes(_dbPingInterval));
_dbPingTimer->async_wait(KeepDatabaseAliveHandler);
sComponentMgr->Load();
sModuleMgr->Load();
+#if PLATFORM == PLATFORM_WINDOWS
+ if (m_ServiceStatus != -1)
+ {
+ _serviceStatusWatchTimer = new boost::asio::deadline_timer(*_ioService);
+ _serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1));
+ _serviceStatusWatchTimer->async_wait(ServiceStatusWatcher);
+ }
+#endif
+
// Start the io service worker loop
_ioService->run();
@@ -186,9 +199,10 @@ int main(int argc, char** argv)
TC_LOG_INFO("server.bnetserver", "Halting process...");
- signals.clear();
+ signals.cancel();
- _ioService.reset();
+ delete _dbPingTimer;
+ delete _ioService;
return 0;
}
@@ -235,14 +249,35 @@ void KeepDatabaseAliveHandler(const boost::system::error_code& error)
}
}
+#if PLATFORM == PLATFORM_WINDOWS
+void ServiceStatusWatcher(boost::system::error_code const& error)
+{
+ if (!error)
+ {
+ if (m_ServiceStatus == 0)
+ {
+ _ioService->stop();
+ delete _serviceStatusWatchTimer;
+ }
+ else
+ {
+ _serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1));
+ _serviceStatusWatchTimer->async_wait(ServiceStatusWatcher);
+ }
+ }
+}
+#endif
+
variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile, std::string& configService)
{
+ (void)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
+#if PLATFORM == PLATFORM_WINDOWS
options_description win("Windows platform specific options");
win.add_options()
("service,s", value<std::string>(&configService)->default_value(""), "Windows service options: [install | uninstall]")