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:
parent
66114bdecb
commit
068cc7c06d
2 changed files with 21 additions and 0 deletions
|
@ -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");
|
||||||
|
|
|
@ -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.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue