From 068cc7c06db288cc63cce11482d418c0d602d72c Mon Sep 17 00:00:00 2001 From: TheUbMunster <66451362+TheUbMunster@users.noreply.github.com> Date: Wed, 27 Jul 2022 23:56:50 -0600 Subject: [PATCH] Added restart server command --- Server/Program.cs | 20 ++++++++++++++++++++ Server/Server.cs | 1 + 2 files changed, 21 insertions(+) diff --git a/Server/Program.cs b/Server/Program.cs index 045a05d..72a24a7 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -542,6 +542,26 @@ CommandHandler.RegisterCommand("loadsettings", _ => { return "Loaded settings.json"; }); +CommandHandler.RegisterCommand("restartserver", args => +{ + if (args.Length != 0) + { + return "Usage: restartserver (no arguments)"; + } + else + { + consoleLogger.Info("Received restartserver command"); + string? path = System.Reflection.Assembly.GetEntryAssembly()?.GetName().Name; + const string unableToStartMsg = "Unable to ascertain the executable location, you'll need to re-run the server manually."; + if (path != null) + Console.WriteLine($"Running: {System.Diagnostics.Process.Start(path)?.Id.ToString() ?? unableToStartMsg}"); + else + consoleLogger.Info(unableToStartMsg); + cts.Cancel(); + return "restarting..."; + } +}); + Console.CancelKeyPress += (_, e) => { e.Cancel = true; consoleLogger.Info("Received Ctrl+C"); diff --git a/Server/Server.cs b/Server/Server.cs index f312ea3..9a271cf 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -55,6 +55,7 @@ public class Server { } Logger.Info("Server closed"); + Console.WriteLine("\n\n\n"); //for the sake of the restart command. } }