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,21 +191,17 @@ 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);
else
DoRestart(null, this);
void DoRestart(Task<GameSaveResult> task, object torch0)
{
var torch = (TorchServer)torch0;
torch.Stop();
// TODO clone this // TODO clone this
var config = (TorchConfig)torch.Config; var config = (TorchConfig)Config;
LogManager.Flush(); LogManager.Flush();
string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe"); string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe");
@@ -214,7 +211,6 @@ namespace Torch.Server
Environment.Exit(0); 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."); Log.Info("Stopping server.");
Context.Torch.Invoke(() => Context.Torch.Stop()); Context.Torch.Invoke(() => Context.Torch.Stop());
}
yield break; yield break;
} }
} }
@@ -322,7 +320,7 @@ 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.");
} }