From 3b2963d6fcf9e2fc65c07402bc59062646df7cde Mon Sep 17 00:00:00 2001 From: Dankrushen Date: Wed, 13 Jan 2021 15:05:58 -0500 Subject: [PATCH 1/2] Bump version & remove RestartNextRound --- MultiAdmin/Features/RestartNextRound.cs | 68 ------------------------- MultiAdmin/Program.cs | 2 +- 2 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 MultiAdmin/Features/RestartNextRound.cs diff --git a/MultiAdmin/Features/RestartNextRound.cs b/MultiAdmin/Features/RestartNextRound.cs deleted file mode 100644 index 8348689..0000000 --- a/MultiAdmin/Features/RestartNextRound.cs +++ /dev/null @@ -1,68 +0,0 @@ -using MultiAdmin.Features.Attributes; - -namespace MultiAdmin.Features -{ - [Feature] - internal class RestartNextRound : Feature, ICommand, IEventRoundEnd - { - private bool restart; - - public RestartNextRound(Server server) : base(server) - { - } - - public string GetCommandDescription() - { - return "Restarts the server at the end of this round [Requires Modding]"; - } - - - public void OnCall(string[] args) - { - Server.Write("Server will restart next round"); - restart = true; - } - - public bool PassToGame() - { - return false; - } - - public string GetCommand() - { - return "RESTARTNEXTROUND"; - } - - public string GetUsage() - { - return ""; - } - - public void OnRoundEnd() - { - if (!restart) return; - - Server.SoftRestartServer(); - restart = false; - } - - public override void Init() - { - restart = false; - } - - public override string GetFeatureDescription() - { - return "Restarts the server after the current round ends [Requires Modding]"; - } - - public override string GetFeatureName() - { - return "Restart Next Round"; - } - - public override void OnConfigReload() - { - } - } -} diff --git a/MultiAdmin/Program.cs b/MultiAdmin/Program.cs index 1d3f6ad..d87f37f 100644 --- a/MultiAdmin/Program.cs +++ b/MultiAdmin/Program.cs @@ -15,7 +15,7 @@ namespace MultiAdmin { public static class Program { - public const string MaVersion = "3.3.1.1"; + public const string MaVersion = "3.3.1.2"; public const string RecommendedMonoVersion = "5.18"; private static readonly List InstantiatedServers = new List(); From ece48faf1fa627bdc4ae07417cbc4e30b9695884 Mon Sep 17 00:00:00 2001 From: Dankrushen Date: Wed, 13 Jan 2021 15:51:45 -0500 Subject: [PATCH 2/2] Handle ExitAction OutputCodes correctly --- MultiAdmin/Features/MemoryChecker.cs | 4 +- MultiAdmin/Features/Restart.cs | 2 +- MultiAdmin/Features/RestartRoundCounter.cs | 2 +- MultiAdmin/Features/StopNextRound.cs | 68 ---------------------- MultiAdmin/Server.cs | 25 ++++++-- MultiAdmin/ServerIO/OutputHandler.cs | 29 ++++++--- 6 files changed, 46 insertions(+), 84 deletions(-) delete mode 100644 MultiAdmin/Features/StopNextRound.cs diff --git a/MultiAdmin/Features/MemoryChecker.cs b/MultiAdmin/Features/MemoryChecker.cs index c1e5af0..475981b 100644 --- a/MultiAdmin/Features/MemoryChecker.cs +++ b/MultiAdmin/Features/MemoryChecker.cs @@ -73,7 +73,7 @@ public void OnRoundEnd() Server.Write("Restarting due to low memory (Round End)...", ConsoleColor.Red); - Server.SoftRestartServer(); + Server.RestartServer(); Init(); } @@ -111,7 +111,7 @@ public void OnTick() if (tickCount >= MaxTicks) { Server.Write("Restarting due to low memory...", ConsoleColor.Red); - Server.SoftRestartServer(); + Server.RestartServer(); restart = false; } diff --git a/MultiAdmin/Features/Restart.cs b/MultiAdmin/Features/Restart.cs index ac3947a..67fad4c 100644 --- a/MultiAdmin/Features/Restart.cs +++ b/MultiAdmin/Features/Restart.cs @@ -26,7 +26,7 @@ public string GetUsage() public void OnCall(string[] args) { - Server.SoftRestartServer(); + Server.RestartServer(); } public bool PassToGame() diff --git a/MultiAdmin/Features/RestartRoundCounter.cs b/MultiAdmin/Features/RestartRoundCounter.cs index d9e5a36..a9517e9 100644 --- a/MultiAdmin/Features/RestartRoundCounter.cs +++ b/MultiAdmin/Features/RestartRoundCounter.cs @@ -28,7 +28,7 @@ public void OnRoundEnd() { Server.Write($"{count}/{restartAfter} rounds have passed, restarting..."); - Server.SoftRestartServer(); + Server.RestartServer(); count = 0; } } diff --git a/MultiAdmin/Features/StopNextRound.cs b/MultiAdmin/Features/StopNextRound.cs deleted file mode 100644 index 36a03a8..0000000 --- a/MultiAdmin/Features/StopNextRound.cs +++ /dev/null @@ -1,68 +0,0 @@ -using MultiAdmin.Features.Attributes; - -namespace MultiAdmin.Features -{ - [Feature] - internal class StopNextRound : Feature, ICommand, IEventRoundEnd - { - private bool stop; - - public StopNextRound(Server server) : base(server) - { - stop = false; - } - - public string GetCommandDescription() - { - return "Stops the server at the end of this round [Requires Modding]"; - } - - public void OnCall(string[] args) - { - Server.Write("Server will stop next round"); - stop = true; - } - - public bool PassToGame() - { - return false; - } - - public string GetCommand() - { - return "STOPNEXTROUND"; - } - - public string GetUsage() - { - return ""; - } - - public void OnRoundEnd() - { - if (!stop) return; - - Server.StopServer(); - stop = false; - } - - public override void Init() - { - stop = false; - } - - public override void OnConfigReload() - { - } - - public override string GetFeatureDescription() - { - return "Stops the server after the current round ends [Requires Modding]"; - } - - public override string GetFeatureName() - { - return "Stop Next Round"; - } - } -} diff --git a/MultiAdmin/Server.cs b/MultiAdmin/Server.cs index 720eee6..bf752a6 100644 --- a/MultiAdmin/Server.cs +++ b/MultiAdmin/Server.cs @@ -116,6 +116,19 @@ private set public bool IsLoading { get; set; } + public bool SetServerRequestedStatus(ServerStatus status) + { + // Don't override the console's own requests + if (IsStopping) + { + return false; + } + + Status = status; + + return true; + } + #endregion private string startDateTime; @@ -192,8 +205,7 @@ private void MainLoop() if (Status == ServerStatus.Restarting && CheckRestartTimeout) { Write("Server restart timed out, killing the server process...", ConsoleColor.Red); - if (IsGameProcessRunning) - GameProcess.Kill(); + RestartServer(true); } if (Status == ServerStatus.Stopping && CheckStopTimeout) @@ -398,12 +410,14 @@ public void StartServer(bool restartOnCrash = true) { case ServerStatus.Stopping: case ServerStatus.ForceStopping: + case ServerStatus.ExitActionStop: Status = ServerStatus.Stopped; shouldRestart = false; break; case ServerStatus.Restarting: + case ServerStatus.ExitActionRestart: shouldRestart = true; break; @@ -503,14 +517,13 @@ public void SetRestartStatus() Status = ServerStatus.Restarting; } - public void SoftRestartServer(bool killGame = false) + public void RestartServer(bool killGame = false) { if (!IsRunning) throw new Exceptions.ServerNotRunningException(); SetRestartStatus(); - SendMessage("SOFTRESTART"); - if (killGame && IsGameProcessRunning) + if ((killGame || !SendMessage("SOFTRESTART")) && IsGameProcessRunning) GameProcess.Kill(); } @@ -719,8 +732,10 @@ public enum ServerStatus Starting, Running, Stopping, + ExitActionStop, ForceStopping, Restarting, + ExitActionRestart, Stopped, StoppedUnexpectedly } diff --git a/MultiAdmin/ServerIO/OutputHandler.cs b/MultiAdmin/ServerIO/OutputHandler.cs index 4d92311..e8b9883 100644 --- a/MultiAdmin/ServerIO/OutputHandler.cs +++ b/MultiAdmin/ServerIO/OutputHandler.cs @@ -24,9 +24,13 @@ private enum OutputCodes : byte ExitActionReset = 0x13, ExitActionShutdown = 0x14, ExitActionSilentShutdown = 0x15, - ExitActionRestart = 0x16 + ExitActionRestart = 0x16, + RoundEnd = 0x17 } + // Temporary measure to handle round ends until the game updates to use this + private bool roundEndCodeUsed = false; + public OutputHandler(Server server) { this.server = server; @@ -95,7 +99,8 @@ public void HandleMessage(object source, ServerSocket.MessageEventArgs message) switch (lowerMessage.Trim(TrimChars)) { case "the round is about to restart! please wait": - server.ForEachHandler(roundEnd => roundEnd.OnRoundEnd()); + if (!roundEndCodeUsed) + server.ForEachHandler(roundEnd => roundEnd.OnRoundEnd()); break; /* Replaced by OutputCodes.RoundRestart @@ -133,7 +138,8 @@ public void HandleMessage(object source, ServerSocket.MessageEventArgs message) switch (@event) { case "round-end-event": - server.ForEachHandler(roundEnd => roundEnd.OnRoundEnd()); + if (!roundEndCodeUsed) + server.ForEachHandler(roundEnd => roundEnd.OnRoundEnd()); break; /* Replaced by OutputCodes.RoundRestart @@ -189,20 +195,29 @@ public void HandleAction(object source, byte action) server.ForEachHandler(idleExit => idleExit.OnIdleExit()); break; + // Requests to reset the ExitAction status case OutputCodes.ExitActionReset: - server.SetRestartStatus(); + server.SetServerRequestedStatus(ServerStatus.Running); break; + // Requests the Shutdown ExitAction with the intent to restart at any time in the future case OutputCodes.ExitActionShutdown: - server.SetStopStatus(); + server.SetServerRequestedStatus(ServerStatus.ExitActionStop); break; + // Requests the SilentShutdown ExitAction with the intent to restart at any time in the future case OutputCodes.ExitActionSilentShutdown: - server.SetStopStatus(); + server.SetServerRequestedStatus(ServerStatus.ExitActionStop); break; + // Requests the Restart ExitAction status with the intent to restart at any time in the future case OutputCodes.ExitActionRestart: - server.SetRestartStatus(); + server.SetServerRequestedStatus(ServerStatus.ExitActionRestart); + break; + + case OutputCodes.RoundEnd: + roundEndCodeUsed = true; + server.ForEachHandler(roundEnd => roundEnd.OnRoundEnd()); break; default: