| 38 | )JSON"); |
| 39 | |
| 40 | int main(int argc, char** argv) { |
| 41 | try { |
| 42 | #if defined STAR_SYSTEM_WINDOWS |
| 43 | unsigned long exceptionStackSize = 131072; |
| 44 | SetThreadStackGuarantee(&exceptionStackSize); |
| 45 | #endif |
| 46 | RootLoader rootLoader({{}, AdditionalDefaultConfiguration, String("starbound_server.log"), LogLevel::Info, false, String("starbound_server.config")}); |
| 47 | RootUPtr root = rootLoader.commandInitOrDie(argc, argv).first; |
| 48 | root->fullyLoad(); |
| 49 | |
| 50 | SignalHandler signalHandler; |
| 51 | signalHandler.setHandleFatal(true); |
| 52 | signalHandler.setHandleInterrupt(true); |
| 53 | |
| 54 | auto configuration = root->configuration(); |
| 55 | { |
| 56 | Logger::info("OpenStarbound Server v{} for v{} ({}) Source ID: {} Protocol: {}", OpenStarVersionString, StarVersionString, StarArchitectureString, StarSourceIdentifierString, StarProtocolVersion); |
| 57 | |
| 58 | float updateRate = 1.0f / GlobalTimestep; |
| 59 | if (auto jUpdateRate = configuration->get("updateRate")) { |
| 60 | updateRate = jUpdateRate.toFloat(); |
| 61 | ServerGlobalTimestep = GlobalTimestep = 1.0f / updateRate; |
| 62 | Logger::info("Configured tick rate is {:4.2f}hz", updateRate); |
| 63 | } |
| 64 | |
| 65 | UniverseServerUPtr server = make_unique<UniverseServer>(root->toStoragePath("universe")); |
| 66 | server->setListeningTcp(true); |
| 67 | server->start(); |
| 68 | |
| 69 | ServerQueryThreadUPtr queryServer; |
| 70 | if (configuration->get("runQueryServer").toBool()) { |
| 71 | queryServer = make_unique<ServerQueryThread>(server.get(), HostAddressWithPort(configuration->get("queryServerBind").toString(), configuration->get("queryServerPort").toInt())); |
| 72 | queryServer->start(); |
| 73 | } |
| 74 | |
| 75 | ServerRconThreadUPtr rconServer; |
| 76 | if (configuration->get("runRconServer").toBool()) { |
| 77 | rconServer = make_unique<ServerRconThread>(server.get(), HostAddressWithPort(configuration->get("rconServerBind").toString(), configuration->get("rconServerPort").toInt())); |
| 78 | rconServer->start(); |
| 79 | } |
| 80 | |
| 81 | while (server->isRunning()) { |
| 82 | if (signalHandler.interruptCaught()) { |
| 83 | Logger::info("Interrupt caught!"); |
| 84 | server->stop(); |
| 85 | break; |
| 86 | } |
| 87 | Thread::sleep(100); |
| 88 | } |
| 89 | |
| 90 | server->join(); |
| 91 | |
| 92 | if (queryServer) { |
| 93 | queryServer->stop(); |
| 94 | queryServer->join(); |
| 95 | } |
| 96 | |
| 97 | if (rconServer) { |
nothing calls this directly
no test coverage detected