From a93a363c5ff9231320c02328d13a9d6abfabef7c Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sat, 25 Nov 2023 10:11:24 -0800 Subject: [PATCH] fix: Fixes shutdown+save (#1614) --- Projects/Server/Main.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Projects/Server/Main.cs b/Projects/Server/Main.cs index d3d12556e..6955d647a 100644 --- a/Projects/Server/Main.cs +++ b/Projects/Server/Main.cs @@ -36,6 +36,8 @@ public static class Core { private static readonly ILogger logger = LogFactory.GetLogger(typeof(Core)); + private static bool _performProcessKill; + private static bool _restartOnKill; private static bool _performSnapshot; private static bool _crashed; private static string _baseDirectory; @@ -304,6 +306,12 @@ public static class Core } } + public static void Kill(bool restart = false) + { + _performProcessKill = true; + _restartOnKill = restart; + } + private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.IsTerminating ? "Error:" : "Warning:"); @@ -359,7 +367,7 @@ public static class Core Kill(); } - public static void Kill(bool restart = false) + internal static void DoKill(bool restart = false) { if (Closing) { @@ -569,6 +577,11 @@ public static class Core World.Snapshot(); } + if (_performProcessKill) + { + DoKill(_restartOnKill); + } + _tickCount = 0; _now = DateTime.MinValue;