Bug: Plugin thinks a native restart is in progress even if cancelled.

I've noticed a bug with how the plugin observes the native Rust restart process.

If a native restart was initiated and then later cancelled prior to restarting, the Smooth Restarter plugin still believes the native restart to be in-progress even if it was already cancelled.

This can cause issues with automatic Oxide updates as the normally automatic restart process will not occur if a restart was previously aborted.

I will look into it, but I believe that at the time of writing the plugin, I've not found any way to detect if the restart is still in progress other than checking it constantly (how'd you cancel the native restart? I don't recall such an option :P)

I usually interrupt restarts by running restart -1, but looking at the code, it seems that rerunning the restart command while a restart is already in progress will interrupt the process:

public static void RestartServer(string strNotice, int iSeconds)
	{
		if (!(SingletonComponent<ServerMgr>.Instance == null))
		{
			if (SingletonComponent<ServerMgr>.Instance.restartCoroutine != null)
			{
				ConsoleNetwork.BroadcastToAllClients("chat.add", 2, 0, "<color=#fff>SERVER</color> Restart interrupted!");
				SingletonComponent<ServerMgr>.Instance.StopCoroutine(SingletonComponent<ServerMgr>.Instance.restartCoroutine);
				SingletonComponent<ServerMgr>.Instance.restartCoroutine = null;
			}
			SingletonComponent<ServerMgr>.Instance.restartCoroutine = SingletonComponent<ServerMgr>.Instance.ServerRestartWarning(strNotice, iSeconds);
			SingletonComponent<ServerMgr>.Instance.StartCoroutine(SingletonComponent<ServerMgr>.Instance.restartCoroutine);
			SingletonComponent<ServerMgr>.Instance.UpdateServerInformation();
		}
	}​


Perhaps this bug would be more easily fixed by having the plugin check whether SingletonComponent<ServerMgr>.Instance.restartCoroutine is null or not?

pQPbyXjY34EMUIp.jpg lowlander

I usually interrupt restarts by running restart -1, but looking at the code, it seems that rerunning the restart command while a restart is already in progress will interrupt the process:

public static void RestartServer(string strNotice, int iSeconds)
	{
		if (!(SingletonComponent<ServerMgr>.Instance == null))
		{
			if (SingletonComponent<ServerMgr>.Instance.restartCoroutine != null)
			{
				ConsoleNetwork.BroadcastToAllClients("chat.add", 2, 0, "<color=#fff>SERVER</color> Restart interrupted!");
				SingletonComponent<ServerMgr>.Instance.StopCoroutine(SingletonComponent<ServerMgr>.Instance.restartCoroutine);
				SingletonComponent<ServerMgr>.Instance.restartCoroutine = null;
			}
			SingletonComponent<ServerMgr>.Instance.restartCoroutine = SingletonComponent<ServerMgr>.Instance.ServerRestartWarning(strNotice, iSeconds);
			SingletonComponent<ServerMgr>.Instance.StartCoroutine(SingletonComponent<ServerMgr>.Instance.restartCoroutine);
			SingletonComponent<ServerMgr>.Instance.UpdateServerInformation();
		}
	}​

Perhaps this bug would be more easily fixed by having the plugin check whether SingletonComponent<ServerMgr>.Instance.restartCoroutine is null or not?

You are not quite correct.
It will interrupt and then re-init it, since it does not have a return statement inside the 2nd if statement.
However, I assume we could check in OnServerInformationUpdated, will try this way.

Ah, I see. It appears that the called ServerRestartWarning function is what processes/ignores the restart when the time value is less than zero:

	private IEnumerator ServerRestartWarning(string info, int iSeconds)
	{
		if (iSeconds < 0)
		{
			yield break;
		}
		if (!string.IsNullOrEmpty(info))
		{
			ConsoleNetwork.BroadcastToAllClients("chat.add", 2, 0, "<color=#fff>SERVER</color> Restarting: " + info);
		}
		for (int i = iSeconds; i > 0; i--)
		{
			if (i == iSeconds || i % 60 == 0 || (i < 300 && i % 30 == 0) || (i < 60 && i % 10 == 0) || i < 10)
			{
				ConsoleNetwork.BroadcastToAllClients("chat.add", 2, 0, $"<color=#fff>SERVER</color> Restarting in {i} seconds ({info})!");
				Debug.Log($"Restarting in {i} seconds");
			}
			yield return CoroutineEx.waitForSeconds(1f);
		}
		ConsoleNetwork.BroadcastToAllClients("chat.add", 2, 0, "<color=#fff>SERVER</color> Restarting (" + info + ")");
		yield return CoroutineEx.waitForSeconds(2f);
		BasePlayer[] array = BasePlayer.activePlayerList.ToArray();
		for (int j = 0; j < array.Length; j++)
		{
			array[j].Kick("Server Restarting");
		}
		yield return CoroutineEx.waitForSeconds(1f);
		ConsoleSystem.Run(ConsoleSystem.Option.Server, "quit");
	}​