remove redundant saving on stop/restart

saving in unload controlled by setting in dedicated config
This commit is contained in:
z__
2022-01-26 10:57:20 +07:00
parent b6d8cf07f8
commit e2cdd803af
2 changed files with 29 additions and 35 deletions

View File

@@ -11,6 +11,7 @@ using System.Threading.Tasks;
using Microsoft.Diagnostics.Runtime; using Microsoft.Diagnostics.Runtime;
using NLog; using NLog;
using Sandbox; using Sandbox;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Multiplayer; using Sandbox.Game.Multiplayer;
using Sandbox.Game.World; using Sandbox.Game.World;
using Torch.API; using Torch.API;
@@ -190,30 +191,25 @@ namespace Torch.Server
{ {
if (Config.DisconnectOnRestart) if (Config.DisconnectOnRestart)
{ {
ModCommunication.SendMessageToClients(new JoinServerMessage("0.0.0.0:25555")); foreach (var member in MyMultiplayer.Static.Members)
{
MyMultiplayer.Static.DisconnectClient(member);
}
Log.Info("Ejected all players from server for restart."); Log.Info("Ejected all players from server for restart.");
} }
if (IsRunning && save) Stop();
Save().ContinueWith(DoRestart, this, TaskContinuationOptions.RunContinuationsAsynchronously); // TODO clone this
else var config = (TorchConfig)Config;
DoRestart(null, this); LogManager.Flush();
void DoRestart(Task<GameSaveResult> task, object torch0) string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe");
{ config.WaitForPID = Environment.ProcessId.ToString();
var torch = (TorchServer)torch0; config.TempAutostart = true;
torch.Stop(); Process.Start(exe, config.ToString());
// TODO clone this
var config = (TorchConfig)torch.Config;
LogManager.Flush();
string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe"); Environment.Exit(0);
config.WaitForPID = Environment.ProcessId.ToString();
config.TempAutostart = true;
Process.Start(exe, config.ToString());
Environment.Exit(0);
}
} }
private void OnSessionStateChanged(ITorchSession session, TorchSessionState newState) private void OnSessionStateChanged(ITorchSession session, TorchSessionState newState)

View File

@@ -171,6 +171,10 @@ namespace Torch.Commands
} }
_stopPending = true; _stopPending = true;
if (!save)
Log.Warn("Stop without save is not possible. Feature is deprecated");
Task.Run(() => Task.Run(() =>
{ {
var countdown = StopCountdown(countdownSeconds, save).GetEnumerator(); var countdown = StopCountdown(countdownSeconds, save).GetEnumerator();
@@ -203,6 +207,9 @@ namespace Torch.Commands
_restartPending = true; _restartPending = true;
if (!save)
Log.Warn("Restart without save is not possible. Feature is deprecated");
Task.Run(() => Task.Run(() =>
{ {
var countdown = RestartCountdown(countdownSeconds, save).GetEnumerator(); var countdown = RestartCountdown(countdownSeconds, save).GetEnumerator();
@@ -272,20 +279,11 @@ namespace Torch.Commands
Log.Info("Saving game before stop."); Log.Info("Saving game before stop.");
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>() Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Saving game before stop."); .SendMessageAsSelf($"Saving game before stop.");
DoSave()?.ContinueWith((a, mod) =>
{
ITorchBase torch = (mod as CommandModule)?.Context?.Torch;
Debug.Assert(torch != null);
torch.Stop();
}, this, TaskContinuationOptions.RunContinuationsAsynchronously);
}
else
{
Log.Info("Stopping server.");
Context.Torch.Invoke(() => Context.Torch.Stop());
}
}
Log.Info("Stopping server.");
Context.Torch.Invoke(() => Context.Torch.Stop());
yield break; yield break;
} }
} }
@@ -298,7 +296,7 @@ namespace Torch.Commands
if (_cancelRestart) if (_cancelRestart)
{ {
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>() Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Restart cancelled."); .SendMessageAsSelf($"Restart cancelled.");
_restartPending = false; _restartPending = false;
_cancelRestart = false; _cancelRestart = false;
@@ -322,9 +320,9 @@ namespace Torch.Commands
{ {
if (save) if (save)
{ {
Log.Info("Savin game before restart."); Log.Info("Saving game before restart.");
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>() Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Saving game before restart."); .SendMessageAsSelf($"Saving game before restart.");
} }
Log.Info("Restarting server."); Log.Info("Restarting server.");