Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MultiAdmin/Features/MemoryChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void OnRoundEnd()

Server.Write("Restarting due to low memory (Round End)...", ConsoleColor.Red);

Server.SoftRestartServer();
Server.RestartServer();

Init();
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion MultiAdmin/Features/Restart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public string GetUsage()

public void OnCall(string[] args)
{
Server.SoftRestartServer();
Server.RestartServer();
}

public bool PassToGame()
Expand Down
68 changes: 0 additions & 68 deletions MultiAdmin/Features/RestartNextRound.cs

This file was deleted.

2 changes: 1 addition & 1 deletion MultiAdmin/Features/RestartRoundCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void OnRoundEnd()
{
Server.Write($"{count}/{restartAfter} rounds have passed, restarting...");

Server.SoftRestartServer();
Server.RestartServer();
count = 0;
}
}
Expand Down
68 changes: 0 additions & 68 deletions MultiAdmin/Features/StopNextRound.cs

This file was deleted.

2 changes: 1 addition & 1 deletion MultiAdmin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Server> InstantiatedServers = new List<Server>();
Expand Down
25 changes: 20 additions & 5 deletions MultiAdmin/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -719,8 +732,10 @@ public enum ServerStatus
Starting,
Running,
Stopping,
ExitActionStop,
ForceStopping,
Restarting,
ExitActionRestart,
Stopped,
StoppedUnexpectedly
}
Expand Down
29 changes: 22 additions & 7 deletions MultiAdmin/ServerIO/OutputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IEventRoundEnd>(roundEnd => roundEnd.OnRoundEnd());
if (!roundEndCodeUsed)
server.ForEachHandler<IEventRoundEnd>(roundEnd => roundEnd.OnRoundEnd());
break;

/* Replaced by OutputCodes.RoundRestart
Expand Down Expand Up @@ -133,7 +138,8 @@ public void HandleMessage(object source, ServerSocket.MessageEventArgs message)
switch (@event)
{
case "round-end-event":
server.ForEachHandler<IEventRoundEnd>(roundEnd => roundEnd.OnRoundEnd());
if (!roundEndCodeUsed)
server.ForEachHandler<IEventRoundEnd>(roundEnd => roundEnd.OnRoundEnd());
break;

/* Replaced by OutputCodes.RoundRestart
Expand Down Expand Up @@ -189,20 +195,29 @@ public void HandleAction(object source, byte action)
server.ForEachHandler<IEventIdleExit>(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<IEventRoundEnd>(roundEnd => roundEnd.OnRoundEnd());
break;

default:
Expand Down