#include #include #include #include #include void ConsoleLoop(Nz::Application& app, blitz::server::Server& server) { std::string line; while (true) { getline(std::cin, line); if (line == "stop") { std::cout << "Exiting ...\n"; server.CloseServer(); app.Quit(); break; } } } static std::uint16_t DefaultPort = 25565; int main(int argc, char* args[]) { Nz::Application app(argc, args); const auto& params = app.GetCommandLineParameters(); std::string_view portString; std::uint16_t port = DefaultPort; if (params.GetParameter("port", &portString)) { std::cout << "Selected port : " << portString << "\n"; bool ok; port = Nz::StringToNumber(portString, 10, &ok); if (!ok) { std::cerr << "Failed to parse port !\n"; port = DefaultPort; } } auto& ecs = app.AddComponent(); auto& serverWorld = ecs.AddWorld(); blitz::server::Server server(port, serverWorld); std::cout << "Server running on port " << port << " ...\n"; std::jthread consoleThread([&app, &server]() { ConsoleLoop(app, server); }); // tick 20 times per seconds app.AddUpdaterFunc([]() { std::this_thread::sleep_for(std::chrono::milliseconds(50)); }); return app.Run(); }