mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Bnet: Fixed crash on shutdown happening when there were still players connected
This commit is contained in:
@@ -57,8 +57,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);
|
||||
|
||||
boost::asio::io_service _ioService;
|
||||
boost::asio::deadline_timer _dbPingTimer(_ioService);
|
||||
std::unique_ptr<boost::asio::io_service> _ioService;
|
||||
std::unique_ptr<boost::asio::deadline_timer> _dbPingTimer;
|
||||
uint32 _dbPingInterval;
|
||||
LoginDatabaseWorkerPool LoginDatabase;
|
||||
|
||||
@@ -109,8 +109,10 @@ int main(int argc, char** argv)
|
||||
|
||||
sIpcContext->Initialize();
|
||||
|
||||
_ioService.reset(new boost::asio::io_service());
|
||||
|
||||
// Get the list of realms for the server
|
||||
sRealmList->Initialize(_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10), worldListenPort);
|
||||
sRealmList->Initialize(*_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10), worldListenPort);
|
||||
|
||||
// Start the listening port (acceptor) for auth connections
|
||||
int32 bnport = sConfigMgr->GetIntDefault("BattlenetPort", 1119);
|
||||
@@ -123,10 +125,10 @@ int main(int argc, char** argv)
|
||||
|
||||
std::string bindIp = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
|
||||
|
||||
sSessionMgr.StartNetwork(_ioService, bindIp, bnport);
|
||||
sSessionMgr.StartNetwork(*_ioService, bindIp, bnport);
|
||||
|
||||
// Set signal handlers
|
||||
boost::asio::signal_set signals(_ioService, SIGINT, SIGTERM);
|
||||
boost::asio::signal_set signals(*_ioService, SIGINT, SIGTERM);
|
||||
#if PLATFORM == PLATFORM_WINDOWS
|
||||
signals.add(SIGBREAK);
|
||||
#endif
|
||||
@@ -137,14 +139,19 @@ int main(int argc, char** argv)
|
||||
|
||||
// Enabled a timed callback for handling the database keep alive ping
|
||||
_dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
|
||||
_dbPingTimer.expires_from_now(boost::posix_time::minutes(_dbPingInterval));
|
||||
_dbPingTimer.async_wait(KeepDatabaseAliveHandler);
|
||||
_dbPingTimer.reset(new boost::asio::deadline_timer(*_ioService));
|
||||
_dbPingTimer->expires_from_now(boost::posix_time::minutes(_dbPingInterval));
|
||||
_dbPingTimer->async_wait(KeepDatabaseAliveHandler);
|
||||
|
||||
sComponentMgr->Load();
|
||||
sModuleMgr->Load();
|
||||
|
||||
// Start the io service worker loop
|
||||
_ioService.run();
|
||||
_ioService->run();
|
||||
|
||||
_dbPingTimer->cancel();
|
||||
|
||||
sSessionMgr.StopNetwork();
|
||||
|
||||
sIpcContext->Close();
|
||||
|
||||
@@ -153,6 +160,8 @@ int main(int argc, char** argv)
|
||||
// Close the Database Pool and library
|
||||
StopDB();
|
||||
|
||||
_ioService.reset();
|
||||
|
||||
TC_LOG_INFO("server.bnetserver", "Halting process...");
|
||||
return 0;
|
||||
}
|
||||
@@ -186,7 +195,7 @@ void StopDB()
|
||||
void SignalHandler(const boost::system::error_code& error, int /*signalNumber*/)
|
||||
{
|
||||
if (!error)
|
||||
_ioService.stop();
|
||||
_ioService->stop();
|
||||
}
|
||||
|
||||
void KeepDatabaseAliveHandler(const boost::system::error_code& error)
|
||||
@@ -196,8 +205,8 @@ void KeepDatabaseAliveHandler(const boost::system::error_code& error)
|
||||
TC_LOG_INFO("server.bnetserver", "Ping MySQL to keep connection alive");
|
||||
LoginDatabase.KeepAlive();
|
||||
|
||||
_dbPingTimer.expires_from_now(boost::posix_time::minutes(_dbPingInterval));
|
||||
_dbPingTimer.async_wait(KeepDatabaseAliveHandler);
|
||||
_dbPingTimer->expires_from_now(boost::posix_time::minutes(_dbPingInterval));
|
||||
_dbPingTimer->async_wait(KeepDatabaseAliveHandler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user