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. } }