From 0411ba533d166fc82a945942be795ed957e8f3f3 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 11 Nov 2022 21:28:20 +0100 Subject: [PATCH] change onShutdown to be called before all players are kicked --- src/SignalHandling.cpp | 2 ++ src/TNetwork.cpp | 20 +++++++++++--------- src/main.cpp | 4 ---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/SignalHandling.cpp b/src/SignalHandling.cpp index 2b5070e..711bdab 100644 --- a/src/SignalHandling.cpp +++ b/src/SignalHandling.cpp @@ -1,6 +1,8 @@ #include "SignalHandling.h" #include "Common.h" +#include "Compat.h" + #if defined(BEAMMP_LINUX) || defined(BEAMMP_APPLE) #include static void UnixSignalHandler(int sig) { diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 593f62b..c8155e6 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -32,15 +32,6 @@ TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& R , mResourceManager(ResourceManager) { Application::SetSubsystemStatus("TCPNetwork", Application::Status::Starting); Application::SetSubsystemStatus("UDPNetwork", Application::Status::Starting); - Application::RegisterShutdownHandler([&] { - beammp_debug("Kicking all players due to shutdown"); - Server.ForEachClient([&](std::weak_ptr client) -> bool { - if (!client.expired()) { - ClientKick(*client.lock(), "Server shutdown"); - } - return true; - }); - }); Application::RegisterShutdownHandler([&] { Application::SetSubsystemStatus("UDPNetwork", Application::Status::ShuttingDown); if (mUDPThread.joinable()) { @@ -57,6 +48,17 @@ TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& R }); mTCPThread = std::thread(&TNetwork::TCPServerMain, this); mUDPThread = std::thread(&TNetwork::UDPServerMain, this); + Application::RegisterShutdownHandler([&] { + auto Futures = LuaAPI::MP::Engine->TriggerEvent("onShutdown", ""); + TLuaEngine::WaitForAll(Futures, std::chrono::seconds(60)); + beammp_debug("Kicking all players due to shutdown"); + Server.ForEachClient([&](std::weak_ptr client) -> bool { + if (!client.expired()) { + ClientKick(*client.lock(), "Server shutdown"); + } + return true; + }); + }); } void TNetwork::UDPServerMain() { diff --git a/src/main.cpp b/src/main.cpp index 4513420..d93f124 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -140,10 +140,6 @@ int BeamMPServerMain(MainArguments Arguments) { Application::SetSubsystemStatus("Main", Application::Status::ShuttingDown); Shutdown = true; }); - Application::RegisterShutdownHandler([] { - auto Futures = LuaAPI::MP::Engine->TriggerEvent("onShutdown", ""); - TLuaEngine::WaitForAll(Futures, std::chrono::seconds(5)); - }); TServer Server(Arguments.List); auto LuaEngine = std::make_shared();