From 17af679c07a5dda5b374e917a5ba81c3985f2159 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 20 May 2017 00:05:47 +0800 Subject: [PATCH] [Master] Enable RestAPI --- apps/master/main.cpp | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/apps/master/main.cpp b/apps/master/main.cpp index 80855837a..2b2087ffa 100644 --- a/apps/master/main.cpp +++ b/apps/master/main.cpp @@ -2,29 +2,37 @@ #include #include #include "MasterServer.hpp" +#include "RestServer.hpp" using namespace RakNet; using namespace std; +unique_ptr restServer; +unique_ptr masterServer; +bool run = true; + int main() { - MasterServer masterServer(2000, 25560); - - masterServer.Start(); - - /*while(true) - { - if(kbhit()) - { - if(getch() == 'e') - { - cout << endl; - masterServer.Stop(true); - break; - } - } - RakSleep(100); - }*/ - masterServer.Wait(); + masterServer.reset(new MasterServer(2000, 25560)); + restServer.reset(new RestServer(8080, masterServer->GetServers())); + + auto onExit = [](int /*sig*/){ + restServer->stop(); + masterServer->Stop(false); + masterServer->Wait(); + run = false; + }; + + signal(SIGINT, onExit); + signal(SIGTERM, onExit); + signal(SIGSTOP, onExit); + + masterServer->Start(); + + thread server_thread([]() { restServer->start(); }); + + server_thread.join(); + masterServer->Wait(); + return 0; } \ No newline at end of file