From 7c7b7477ebd9980aa03e54d7694f6854ba5726bd Mon Sep 17 00:00:00 2001 From: Quentin Ritzler Date: Thu, 9 Apr 2026 14:48:31 +0200 Subject: [PATCH 1/2] Move shutdown handler to after LuaEngine initialization --- src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7fb09e6c..1e5c51f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -175,10 +175,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); @@ -195,6 +191,10 @@ int BeamMPServerMain(MainArguments Arguments) { LuaEngine->SetServer(&Server); Application::Console().InitializeLuaConsole(*LuaEngine); LuaEngine->SetNetwork(&Network); + Application::RegisterShutdownHandler([] { + auto Futures = LuaAPI::MP::Engine->TriggerEvent("onShutdown", ""); + TLuaEngine::WaitForAll(Futures, std::chrono::seconds(5)); + }); PPSMonitor.SetNetwork(Network); Application::CheckForUpdates(); From 87e9db5382edade814923565998ddcb5d153c1b2 Mon Sep 17 00:00:00 2001 From: Quentin Ritzler Date: Thu, 9 Apr 2026 16:07:44 +0200 Subject: [PATCH 2/2] Make sure the shutdown kicks players as the first handler --- src/TNetwork.cpp | 9 --------- src/main.cpp | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index d0393e89..8764ed2a 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -62,15 +62,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()) { diff --git a/src/main.cpp b/src/main.cpp index 1e5c51f2..160da0e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ // along with this program. If not, see . #include "ArgsParser.h" +#include "Client.h" #include "Common.h" #include "Http.h" #include "LuaAPI.h" @@ -191,15 +192,25 @@ int BeamMPServerMain(MainArguments Arguments) { LuaEngine->SetServer(&Server); Application::Console().InitializeLuaConsole(*LuaEngine); LuaEngine->SetNetwork(&Network); - Application::RegisterShutdownHandler([] { - auto Futures = LuaAPI::MP::Engine->TriggerEvent("onShutdown", ""); - TLuaEngine::WaitForAll(Futures, std::chrono::seconds(5)); - }); PPSMonitor.SetNetwork(Network); Application::CheckForUpdates(); TPluginMonitor PluginMonitor(fs::path(Application::Settings.getAsString(Settings::Key::General_ResourceFolder)) / "Server", LuaEngine); + Application::RegisterShutdownHandler([] { + auto Futures = LuaAPI::MP::Engine->TriggerEvent("onShutdown", ""); + TLuaEngine::WaitForAll(Futures, std::chrono::seconds(5)); + }); + Application::RegisterShutdownHandler([&Server, &Network] { + beammp_debug("Kicking all players due to shutdown"); + Server.ForEachClient([&Network](std::weak_ptr client) -> bool { + if (!client.expired()) { + Network.ClientKick(*client.lock(), "Server shutdown"); + } + return true; + }); + }); + RegisterThread("Main(Waiting)"); std::set IgnoreSubsystems {