From 71c2af12245ae4c91ec393a8037c1a6fb01d6e90 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 11 Jul 2021 20:27:35 +0200 Subject: [PATCH] TNetwork: kick everyone before shutdown in the future this can be used to show a message to the clients that the server is shutting down --- src/TNetwork.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 9cd1251..dc4dfd6 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -9,6 +9,15 @@ TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& R : mServer(Server) , mPPSMonitor(PPSMonitor) , mResourceManager(ResourceManager) { + Application::RegisterShutdownHandler([&] { + 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([&] { if (mUDPThread.joinable()) { debug("shutting down TCPServer");