fix server not closing after detecting an invalid config (fixes #151)

This commit is contained in:
Lion Kortlepel
2022-11-11 19:40:37 +01:00
parent c8ca4564a1
commit 69c2868025
2 changed files with 18 additions and 15 deletions

View File

@@ -160,7 +160,6 @@ TEST_CASE("ParseVehiclePacket") {
}
TServer::TServer(const std::vector<std::string_view>& Arguments) {
beammp_infof("BeamMP Server v{} ({})", Application::ServerVersionString(), BEAMMP_GIT_HASH);
Application::SetSubsystemStatus("Server", Application::Status::Starting);
if (Arguments.size() > 1) {
Application::SetSetting(StrCustomIP, std::string(Arguments[0]));

View File

@@ -112,14 +112,28 @@ int BeamMPServerMain(MainArguments Arguments) {
}
}
Application::Console().Internal().set_prompt("> ");
Application::SetSubsystemStatus("Main", Application::Status::Starting);
Application::Console().StartLoggingToFile();
SetupSignalHandlers();
beammp_infof("BeamMP Server v{} ({})", Application::ServerVersionString(), BEAMMP_GIT_HASH);
TConfig Config(ConfigPath);
if (Config.Failed()) {
beammp_info("Closing in 10 seconds");
// loop to make it possible to ctrl+c instead
Application::SleepSafeSeconds(5);
beammp_info("Closing in 5 seconds");
Application::SleepSafeSeconds(5);
Application::GracefullyShutdown();
return 1;
}
Application::Console().Internal().set_prompt("> ");
Application::Console().StartLoggingToFile();
bool Shutdown = false;
Application::RegisterShutdownHandler([&Shutdown] {
beammp_info("If this takes too long, you can press Ctrl+C repeatedly to force a shutdown.");
@@ -130,22 +144,12 @@ int BeamMPServerMain(MainArguments Arguments) {
auto Futures = LuaAPI::MP::Engine->TriggerEvent("onShutdown", "");
TLuaEngine::WaitForAll(Futures, std::chrono::seconds(5));
});
TServer Server(Arguments.List);
TConfig Config(ConfigPath);
auto LuaEngine = std::make_shared<TLuaEngine>();
LuaEngine->SetServer(&Server);
Application::Console().InitializeLuaConsole(*LuaEngine);
if (Config.Failed()) {
beammp_info("Closing in 10 seconds");
// loop to make it possible to ctrl+c instead
for (size_t i = 0; i < 20; ++i) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
return 1;
}
RegisterThread("Main");
beammp_trace("Running in debug mode on a debug build");