Merge remote-tracking branch 'origin/master' into rewrite-lua

This commit is contained in:
Lion Kortlepel
2021-09-17 14:24:12 +02:00
16 changed files with 312 additions and 68 deletions

View File

@@ -4,6 +4,7 @@
#include "CustomAssert.h"
#include "Http.h"
#include "LuaAPI.h"
#include "SignalHandling.h"
#include "TConfig.h"
#include "THeartbeatThread.h"
#include "TLuaEngine.h"
@@ -12,48 +13,18 @@
#include "TResourceManager.h"
#include "TServer.h"
#include <iostream>
#include <thread>
#ifdef __unix
#include <csignal>
void UnixSignalHandler(int sig) {
switch (sig) {
case SIGPIPE:
beammp_warn("ignoring SIGPIPE");
break;
case SIGTERM:
beammp_info("gracefully shutting down via SIGTERM");
Application::GracefullyShutdown();
break;
case SIGINT:
beammp_info("gracefully shutting down via SIGINT");
Application::GracefullyShutdown();
break;
default:
beammp_debug("unhandled signal: " + std::to_string(sig));
break;
}
}
#endif // __unix
// this is provided by the build system, leave empty for source builds
// global, yes, this is ugly, no, it cant be done another way
TSentry Sentry {};
#include <iostream>
int main(int argc, char** argv) try {
#ifdef __unix
trace("registering handlers for SIGINT, SIGTERM, SIGPIPE");
signal(SIGPIPE, UnixSignalHandler);
signal(SIGTERM, UnixSignalHandler);
#ifndef DEBUG
signal(SIGINT, UnixSignalHandler);
#endif // DEBUG
#endif // __unix
setlocale(LC_ALL, "C");
SetupSignalHandlers();
bool Shutdown = false;
Application::RegisterShutdownHandler([&Shutdown] { Shutdown = true; });
Application::RegisterShutdownHandler([] {
@@ -68,7 +39,10 @@ int main(int argc, char** argv) try {
if (Config.Failed()) {
beammp_info("Closing in 10 seconds");
std::this_thread::sleep_for(std::chrono::seconds(10));
// 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;
}
@@ -78,7 +52,6 @@ int main(int argc, char** argv) try {
Sentry.SetupUser();
Sentry.PrintWelcome();
Application::CheckForUpdates();
TResourceManager ResourceManager;
TPPSMonitor PPSMonitor(Server);
THeartbeatThread Heartbeat(ResourceManager, Server);
@@ -86,11 +59,13 @@ int main(int argc, char** argv) try {
LuaEngine.SetNetwork(&Network);
PPSMonitor.SetNetwork(Network);
Application::Console().InitializeLuaConsole(LuaEngine);
Application::CheckForUpdates();
// TODO: replace
while (!Shutdown) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
info("Shutdown.");
} catch (const std::exception& e) {
error(e.what());
Sentry.LogException(e, _file_basename, _line);