Merge branch '0.7.1-window-input' into 0.7.1

pull/565/head
David Cernat 5 years ago
commit 94f5b169e6

@ -25,6 +25,8 @@
#include "processors/ObjectProcessor.hpp" #include "processors/ObjectProcessor.hpp"
#include "processors/WorldstateProcessor.hpp" #include "processors/WorldstateProcessor.hpp"
#include "handleInput.cpp"
using namespace mwmp; using namespace mwmp;
using namespace std; 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() int Networking::mainLoop()
{ {
RakNet::Packet *packet; RakNet::Packet *packet;
@ -506,16 +522,15 @@ int Networking::mainLoop()
sigIntHandler.sa_handler = signalHandler; sigIntHandler.sa_handler = signalHandler;
sigemptyset(&sigIntHandler.sa_mask); sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0; sigIntHandler.sa_flags = 0;
sigaction(SIGTERM, &sigIntHandler, NULL);
sigaction(SIGINT, &sigIntHandler, NULL);
#else
SetConsoleCtrlHandler(sigIntHandler, TRUE);
#endif #endif
while (running and !killLoop) while (running and !killLoop)
{ {
#ifndef _WIN32 mwmp_input::handler();
sigaction(SIGTERM, &sigIntHandler, NULL);
sigaction(SIGINT, &sigIntHandler, NULL);
#endif
if (kbhit() && getch() == '\n')
break;
for (packet=peer->Receive(); packet; peer->DeallocatePacket(packet), packet=peer->Receive()) for (packet=peer->Receive(); packet; peer->DeallocatePacket(packet), packet=peer->Receive())
{ {
if (getMasterClient()->Process(packet)) if (getMasterClient()->Process(packet))

@ -214,7 +214,8 @@ public:
{"OnWorldWeather", Callback<unsigned short>()}, {"OnWorldWeather", Callback<unsigned short>()},
{"OnClientScriptGlobal", Callback<unsigned short>()}, {"OnClientScriptGlobal", Callback<unsigned short>()},
{"OnMpNumIncrement", Callback<int>()}, {"OnMpNumIncrement", Callback<int>()},
{"OnRequestDataFileList", Callback<>()} {"OnRequestDataFileList", Callback<>()},
{"OnServerWindowInput", Callback<const char *>()}
}; };
}; };

@ -0,0 +1,27 @@
using namespace std;
namespace mwmp_input {
string windowInputBuffer;
void handler() {
char c;
#ifndef WIN32
while (kbhit()) {
c = getch();
#else // on Windows conio.h getch() and kbhit() are deprecated, use _getch() and _kbhit() instead
while (_kbhit()) {
c = _getch();
#endif
cout << c << flush;
if (c == '\n' || c == '\r') { // handle carriage return as new line on Windows
cout << endl;
Script::Call<Script::CallbackIdentity("OnServerWindowInput")>(windowInputBuffer.c_str());
windowInputBuffer.assign("");
}
else if (c == '\b') {
auto size = windowInputBuffer.size();
if (size > 0)
windowInputBuffer.erase(size - 1);
}
else windowInputBuffer += c;
}
}
}
Loading…
Cancel
Save