mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-25 21:40:09 +00:00
change onShutdown to be called before all players are kicked
This commit is contained in:
3 files changed
+13
-13
No files matched your search
@@ -1,6 +1,8 @@
|
|||||||
#include "SignalHandling.h"
|
#include "SignalHandling.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
|
||||||
|
#include "Compat.h"
|
||||||
|
|
||||||
#if defined(BEAMMP_LINUX) || defined(BEAMMP_APPLE)
|
#if defined(BEAMMP_LINUX) || defined(BEAMMP_APPLE)
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
static void UnixSignalHandler(int sig) {
|
static void UnixSignalHandler(int sig) {
|
||||||
|
|||||||
+11
-9
@@ -32,15 +32,6 @@ TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& R
|
|||||||
, mResourceManager(ResourceManager) {
|
, mResourceManager(ResourceManager) {
|
||||||
Application::SetSubsystemStatus("TCPNetwork", Application::Status::Starting);
|
Application::SetSubsystemStatus("TCPNetwork", Application::Status::Starting);
|
||||||
Application::SetSubsystemStatus("UDPNetwork", Application::Status::Starting);
|
Application::SetSubsystemStatus("UDPNetwork", Application::Status::Starting);
|
||||||
Application::RegisterShutdownHandler([&] {
|
|
||||||
beammp_debug("Kicking all players due to shutdown");
|
|
||||||
Server.ForEachClient([&](std::weak_ptr<TClient> client) -> bool {
|
|
||||||
if (!client.expired()) {
|
|
||||||
ClientKick(*client.lock(), "Server shutdown");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Application::RegisterShutdownHandler([&] {
|
Application::RegisterShutdownHandler([&] {
|
||||||
Application::SetSubsystemStatus("UDPNetwork", Application::Status::ShuttingDown);
|
Application::SetSubsystemStatus("UDPNetwork", Application::Status::ShuttingDown);
|
||||||
if (mUDPThread.joinable()) {
|
if (mUDPThread.joinable()) {
|
||||||
@@ -57,6 +48,17 @@ TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& R
|
|||||||
});
|
});
|
||||||
mTCPThread = std::thread(&TNetwork::TCPServerMain, this);
|
mTCPThread = std::thread(&TNetwork::TCPServerMain, this);
|
||||||
mUDPThread = std::thread(&TNetwork::UDPServerMain, 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<TClient> client) -> bool {
|
||||||
|
if (!client.expired()) {
|
||||||
|
ClientKick(*client.lock(), "Server shutdown");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TNetwork::UDPServerMain() {
|
void TNetwork::UDPServerMain() {
|
||||||
|
|||||||
@@ -140,10 +140,6 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
Application::SetSubsystemStatus("Main", Application::Status::ShuttingDown);
|
Application::SetSubsystemStatus("Main", Application::Status::ShuttingDown);
|
||||||
Shutdown = true;
|
Shutdown = true;
|
||||||
});
|
});
|
||||||
Application::RegisterShutdownHandler([] {
|
|
||||||
auto Futures = LuaAPI::MP::Engine->TriggerEvent("onShutdown", "");
|
|
||||||
TLuaEngine::WaitForAll(Futures, std::chrono::seconds(5));
|
|
||||||
});
|
|
||||||
|
|
||||||
TServer Server(Arguments.List);
|
TServer Server(Arguments.List);
|
||||||
auto LuaEngine = std::make_shared<TLuaEngine>();
|
auto LuaEngine = std::make_shared<TLuaEngine>();
|
||||||
|
|||||||
Reference in new issue
Block a user