From 4e6bcf02d2192992fcea57be7d8dcf6a439d31f3 Mon Sep 17 00:00:00 2001 From: uramer Date: Sun, 1 Mar 2020 18:30:00 +0100 Subject: [PATCH 1/5] [Server] Pass stdin to a Lua event, fix Ctrl+C on Windows --- apps/openmw-mp/Networking.cpp | 27 ++++++++++++++++++----- apps/openmw-mp/Script/ScriptFunctions.hpp | 3 ++- apps/openmw-mp/handleInput.cpp | 24 ++++++++++++++++++++ apps/openmw-mp/handleInput.hpp | 3 +++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 apps/openmw-mp/handleInput.cpp create mode 100644 apps/openmw-mp/handleInput.hpp diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index c3067f58c..e034b6394 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -25,6 +25,8 @@ #include "processors/ObjectProcessor.hpp" #include "processors/WorldstateProcessor.hpp" +#include "handleInput.hpp" + using namespace mwmp; using namespace std; @@ -496,6 +498,20 @@ void signalHandler(int signum) } } +#ifdef _WIN32 +BOOL WINAPI sigIntHandler(_In_ DWORD dwCtrlType) { + switch (dwCtrlType) + { + case CTRL_C_EVENT: + signalHandler(15); + return TRUE; + default: + // Pass signal on to the next handler + return FALSE; + } +} +#endif + int Networking::mainLoop() { RakNet::Packet *packet; @@ -506,16 +522,15 @@ int Networking::mainLoop() sigIntHandler.sa_handler = signalHandler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; + sigaction(SIGTERM, &sigIntHandler, NULL); + sigaction(SIGINT, &sigIntHandler, NULL); +#else + SetConsoleCtrlHandler(sigIntHandler, TRUE); #endif while (running and !killLoop) { -#ifndef _WIN32 - sigaction(SIGTERM, &sigIntHandler, NULL); - sigaction(SIGINT, &sigIntHandler, NULL); -#endif - if (kbhit() && getch() == '\n') - break; + mwmp_input::handler(); for (packet=peer->Receive(); packet; peer->DeallocatePacket(packet), packet=peer->Receive()) { if (getMasterClient()->Process(packet)) diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index fe04c739f..a1d539410 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -214,7 +214,8 @@ public: {"OnWorldWeather", Callback()}, {"OnClientScriptGlobal", Callback()}, {"OnMpNumIncrement", Callback()}, - {"OnRequestDataFileList", Callback<>()} + {"OnRequestDataFileList", Callback<>()}, + {"OnServerWindowInput", Callback()} }; }; diff --git a/apps/openmw-mp/handleInput.cpp b/apps/openmw-mp/handleInput.cpp new file mode 100644 index 000000000..cbc00f5df --- /dev/null +++ b/apps/openmw-mp/handleInput.cpp @@ -0,0 +1,24 @@ +#include