Adjust behavior of restarts. Closes #337
This commit is contained in:
@@ -104,7 +104,7 @@ namespace Torch.API
|
||||
/// <summary>
|
||||
/// Restart the Torch instance, blocking until the restart has been performed.
|
||||
/// </summary>
|
||||
void Restart();
|
||||
void Restart(bool save = true);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a save of the game.
|
||||
|
@@ -152,14 +152,15 @@ namespace Torch.Server
|
||||
/// <summary>
|
||||
/// Restart the program.
|
||||
/// </summary>
|
||||
public override void Restart()
|
||||
public override void Restart(bool save = true)
|
||||
{
|
||||
if (Config.DisconnectOnRestart)
|
||||
{
|
||||
ModCommunication.SendMessageToClients(new JoinServerMessage("0.0.0.0:25555"));
|
||||
Log.Info("Ejected all players from server for restart.");
|
||||
}
|
||||
|
||||
if (IsRunning)
|
||||
if (IsRunning && save)
|
||||
Save().ContinueWith(DoRestart, this, TaskContinuationOptions.RunContinuationsAsynchronously);
|
||||
else
|
||||
DoRestart(null, this);
|
||||
|
@@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using NLog;
|
||||
using Sandbox.Game.Multiplayer;
|
||||
using Sandbox.ModAPI;
|
||||
using Steamworks;
|
||||
@@ -28,6 +29,7 @@ namespace Torch.Commands
|
||||
{
|
||||
private static bool _restartPending = false;
|
||||
private static bool _cancelRestart = false;
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[Command("whatsmyip")]
|
||||
[Permission(MyPromoteLevel.None)]
|
||||
@@ -176,6 +178,7 @@ namespace Torch.Commands
|
||||
}
|
||||
|
||||
_restartPending = true;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var countdown = RestartCountdown(countdownSeconds, save).GetEnumerator();
|
||||
@@ -232,15 +235,18 @@ namespace Torch.Commands
|
||||
else
|
||||
{
|
||||
if (save)
|
||||
Context.Torch.Save().ContinueWith(x => Restart());
|
||||
else
|
||||
Restart();
|
||||
{
|
||||
Log.Info("Savin game before restart.");
|
||||
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
|
||||
.SendMessageAsSelf($"Saving game before restart.");
|
||||
}
|
||||
|
||||
Log.Info("Restarting server.");
|
||||
Context.Torch.Invoke(() => Context.Torch.Restart(save));
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
|
||||
void Restart() => Context.Torch.Invoke(() => Context.Torch.Restart());
|
||||
}
|
||||
|
||||
private string Pluralize(int num)
|
||||
|
@@ -427,7 +427,7 @@ namespace Torch
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract void Restart();
|
||||
public abstract void Restart(bool save = true);
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Init(object gameInstance)
|
||||
|
Reference in New Issue
Block a user