0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-25 20:55:18 +00:00

Added restart server command

This commit is contained in:
TheUbMunster 2022-07-27 23:56:50 -06:00
parent 66114bdecb
commit 068cc7c06d
2 changed files with 21 additions and 0 deletions

View file

@ -542,6 +542,26 @@ CommandHandler.RegisterCommand("loadsettings", _ => {
return "Loaded settings.json"; 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) => { Console.CancelKeyPress += (_, e) => {
e.Cancel = true; e.Cancel = true;
consoleLogger.Info("Received Ctrl+C"); consoleLogger.Info("Received Ctrl+C");

View file

@ -55,6 +55,7 @@ public class Server {
} }
Logger.Info("Server closed"); Logger.Info("Server closed");
Console.WriteLine("\n\n\n"); //for the sake of the restart command.
} }
} }