MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / main

Function main

source/server/main.cpp:40–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38 )JSON");
39
40int 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) {

Callers

nothing calls this directly

Calls 15

StringClass · 0.85
HostAddressWithPortClass · 0.85
commandInitOrDieMethod · 0.80
fullyLoadMethod · 0.80
configurationMethod · 0.80
toFloatMethod · 0.80
toStoragePathMethod · 0.80
setListeningTcpMethod · 0.80
toBoolMethod · 0.80
toIntMethod · 0.80
fatalExceptionFunction · 0.50
setHandleFatalMethod · 0.45

Tested by

no test coverage detected