Add internal command interpretation
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
|
||||
//std
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
|
||||
//thread
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
// Vendor
|
||||
#include <yojimbo.h>
|
||||
|
||||
@@ -18,7 +24,22 @@ static GameServer *serv;
|
||||
|
||||
void interrupt_handler(int /*dummy*/)
|
||||
{
|
||||
serv->m_running = false;
|
||||
serv->dispatchCommand("stop");
|
||||
}
|
||||
|
||||
void ReadCin(std::atomic<bool> &run)
|
||||
{
|
||||
std::string buffer;
|
||||
|
||||
while (run.load())
|
||||
{
|
||||
std::getline(std::cin, buffer);
|
||||
serv->dispatchCommand(buffer);
|
||||
if (buffer == "stop")
|
||||
{
|
||||
run.store(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -29,12 +50,13 @@ int main(int argc, char *argv[])
|
||||
DWORD prev_mode;
|
||||
hInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
GetConsoleMode(hInput, &prev_mode);
|
||||
SetConsoleMode(hInput, prev_mode & ENABLE_EXTENDED_FLAGS);
|
||||
prev_mode &= ~ENABLE_QUICK_EDIT_MODE;
|
||||
SetConsoleMode(hInput, prev_mode);
|
||||
#endif
|
||||
|
||||
if (!InitializeYojimbo())
|
||||
{
|
||||
printf("error: failed to initialize Yojimbo!\n");
|
||||
std::cout << "error: failed to initialize Yojimbo!" << std::endl;
|
||||
;
|
||||
return 1;
|
||||
}
|
||||
yojimbo_log_level(YOJIMBO_LOG_LEVEL_INFO);
|
||||
@@ -45,8 +67,15 @@ int main(int argc, char *argv[])
|
||||
yojimbo::Address addr(127, 0, 0, 1, 9999);
|
||||
GameServer server(addr);
|
||||
serv = &server; //For interrupt
|
||||
|
||||
std::atomic<bool> run(true);
|
||||
std::thread cinThread(ReadCin, std::ref(run));
|
||||
|
||||
server.Run();
|
||||
|
||||
run.store(false);
|
||||
cinThread.join();
|
||||
|
||||
ShutdownYojimbo();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user