//std #include #include //thread #include #include // Vendor #include // Own #include "GameServer.h" // Windows #ifdef _WIN32 #include #endif using namespace yojimbo; static GameServer *serv; void interrupt_handler(int /*dummy*/) { serv->dispatchCommand("stop"); } void ReadCin(std::atomic &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[]) { //--- Setup CMD #ifdef _WIN32 HANDLE hInput; DWORD prev_mode; hInput = GetStdHandle(STD_INPUT_HANDLE); GetConsoleMode(hInput, &prev_mode); prev_mode &= ~ENABLE_QUICK_EDIT_MODE; SetConsoleMode(hInput, prev_mode); #endif if (!InitializeYojimbo()) { std::cout << "error: failed to initialize Yojimbo!" << std::endl; ; return 1; } yojimbo_log_level(YOJIMBO_LOG_LEVEL_INFO); std::cout << "Yojimbo lives!" << std::endl; signal(SIGINT, interrupt_handler); yojimbo::Address addr(127, 0, 0, 1, 9999); GameServer server(addr); serv = &server; //For interrupt std::atomic run(true); std::thread cinThread(ReadCin, std::ref(run)); server.Run(); run.store(false); cinThread.join(); ShutdownYojimbo(); return EXIT_SUCCESS; }