mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 21:19:40 +00:00
Merge pull request #532 from nalal/patch-1
[Server] Added functionality for TES3MP server to catch system signals
This commit is contained in:
commit
ad9ee80641
1 changed files with 21 additions and 1 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <Script/API/TimerAPI.hpp>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <csignal>
|
||||
|
||||
#include "Networking.hpp"
|
||||
#include "MasterClient.hpp"
|
||||
|
@ -32,6 +33,7 @@ Networking *Networking::sThis = 0;
|
|||
static int currentMpNum = 0;
|
||||
static bool dataFileEnforcementState = true;
|
||||
static bool scriptErrorIgnoringState = false;
|
||||
bool killLoop = false;
|
||||
|
||||
Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
|
||||
{
|
||||
|
@ -469,12 +471,30 @@ void Networking::stopServer(int code)
|
|||
exitCode = code;
|
||||
}
|
||||
|
||||
void signalHandler(int signum)
|
||||
{
|
||||
cout << "Interrupt signal (" << signum << ") received.\n";
|
||||
//15 is SIGTERM(Normal OS stop call), 2 is SIGINT(Ctrl+C)
|
||||
if(signum == 15 or signum == 2)
|
||||
{
|
||||
killLoop = true;
|
||||
}
|
||||
}
|
||||
|
||||
int Networking::mainLoop()
|
||||
{
|
||||
RakNet::Packet *packet;
|
||||
|
||||
while (running)
|
||||
struct sigaction sigIntHandler;
|
||||
|
||||
sigIntHandler.sa_handler = signalHandler;
|
||||
sigemptyset(&sigIntHandler.sa_mask);
|
||||
sigIntHandler.sa_flags = 0;
|
||||
|
||||
while (running and !killLoop)
|
||||
{
|
||||
sigaction(SIGTERM, &sigIntHandler, NULL);
|
||||
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||
if (kbhit() && getch() == '\n')
|
||||
break;
|
||||
for (packet=peer->Receive(); packet; peer->DeallocatePacket(packet), packet=peer->Receive())
|
||||
|
|
Loading…
Reference in a new issue