mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-08 11:44:11 +00:00
fix: signal handling (#1375)
* fix: signal handling * fix: flush WorldServer logger before main loop * fix: consolidate signal code
This commit is contained in:
@@ -88,7 +88,7 @@ namespace Game {
|
||||
RakPeerInterface* chatServer = nullptr;
|
||||
std::mt19937 randomEngine;
|
||||
SystemAddress chatSysAddr;
|
||||
bool shouldShutdown = false;
|
||||
Game::signal_t lastSignal = 0;
|
||||
EntityManager* entityManager = nullptr;
|
||||
dZoneManager* zoneManager = nullptr;
|
||||
std::string projectVersion = PROJECT_VERSION;
|
||||
@@ -124,8 +124,8 @@ int main(int argc, char** argv) {
|
||||
// Triggers the shutdown sequence at application exit
|
||||
std::atexit(WorldShutdownSequence);
|
||||
|
||||
signal(SIGINT, [](int) { WorldShutdownSequence(); });
|
||||
signal(SIGTERM, [](int) { WorldShutdownSequence(); });
|
||||
std::signal(SIGINT, Game::OnSignal);
|
||||
std::signal(SIGTERM, Game::OnSignal);
|
||||
|
||||
uint32_t zoneID = 1000;
|
||||
uint32_t cloneID = 0;
|
||||
@@ -212,7 +212,7 @@ int main(int argc, char** argv) {
|
||||
UserManager::Instance()->Initialize();
|
||||
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(Game::config->GetValue("dont_generate_dcf"))));
|
||||
|
||||
Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, &Game::shouldShutdown, zoneID);
|
||||
Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, &Game::lastSignal, zoneID);
|
||||
|
||||
//Connect to the chat server:
|
||||
uint32_t chatPort = 1501;
|
||||
@@ -313,6 +313,8 @@ int main(int argc, char** argv) {
|
||||
uint32_t saveTime = 10 * 60 * currentFramerate; // 10 minutes in frames
|
||||
uint32_t sqlPingTime = 10 * 60 * currentFramerate; // 10 minutes in frames
|
||||
uint32_t emptyShutdownTime = (cloneID == 0 ? 30 : 5) * 60 * currentFramerate; // 30 minutes for main worlds, 5 for all others.
|
||||
|
||||
Game::logger->Flush(); // once immediately before the main loop
|
||||
while (true) {
|
||||
Metrics::StartMeasurement(MetricVariable::Frame);
|
||||
Metrics::StartMeasurement(MetricVariable::GameLoop);
|
||||
@@ -363,9 +365,9 @@ int main(int argc, char** argv) {
|
||||
if (!Game::server->GetIsConnectedToMaster()) {
|
||||
framesSinceMasterDisconnect++;
|
||||
|
||||
if (framesSinceMasterDisconnect >= noMasterConnectionTimeout && !Game::shouldShutdown) {
|
||||
if (framesSinceMasterDisconnect >= noMasterConnectionTimeout && !Game::ShouldShutdown()) {
|
||||
LOG("Game loop running but no connection to master for %d frames, shutting down", noMasterConnectionTimeout);
|
||||
Game::shouldShutdown = true;
|
||||
Game::lastSignal = -1;
|
||||
}
|
||||
} else framesSinceMasterDisconnect = 0;
|
||||
|
||||
@@ -460,7 +462,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
//If we haven't had any players for a while, time out and shut down:
|
||||
if (framesSinceLastUser >= emptyShutdownTime) {
|
||||
Game::shouldShutdown = true;
|
||||
Game::lastSignal = -1;
|
||||
}
|
||||
} else {
|
||||
framesSinceLastUser = 0;
|
||||
@@ -513,7 +515,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Game::shouldShutdown && !worldShutdownSequenceComplete) {
|
||||
if (Game::ShouldShutdown() && !worldShutdownSequenceComplete) {
|
||||
WorldShutdownProcess(zoneID);
|
||||
break;
|
||||
}
|
||||
@@ -822,7 +824,7 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
case eMasterMessageType::SHUTDOWN: {
|
||||
Game::shouldShutdown = true;
|
||||
Game::lastSignal = -1;
|
||||
LOG("Got shutdown request from master, zone (%i), instance (%i)", Game::server->GetZoneID(), Game::server->GetInstanceID());
|
||||
break;
|
||||
}
|
||||
@@ -1289,9 +1291,9 @@ void WorldShutdownProcess(uint32_t zoneId) {
|
||||
}
|
||||
|
||||
void WorldShutdownSequence() {
|
||||
Game::shouldShutdown = true;
|
||||
Game::lastSignal = -1;
|
||||
#ifndef DARKFLAME_PLATFORM_WIN32
|
||||
if (Game::shouldShutdown || worldShutdownSequenceComplete)
|
||||
if (Game::ShouldShutdown() || worldShutdownSequenceComplete)
|
||||
#endif
|
||||
{
|
||||
return;
|
||||
|
Reference in New Issue
Block a user