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 NLog;
using Sandbox;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.World;
using Torch.API;
@@ -190,21 +191,17 @@ namespace Torch.Server
{
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.");
}
if (IsRunning && save)
Save().ContinueWith(DoRestart, this, TaskContinuationOptions.RunContinuationsAsynchronously);
else
DoRestart(null, this);
void DoRestart(Task<GameSaveResult> task, object torch0)
{
var torch = (TorchServer)torch0;
torch.Stop();
Stop();
// TODO clone this
var config = (TorchConfig)torch.Config;
var config = (TorchConfig)Config;
LogManager.Flush();
string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe");
@@ -214,7 +211,6 @@ namespace Torch.Server
Environment.Exit(0);
}
}
private void OnSessionStateChanged(ITorchSession session, TorchSessionState newState)
{

View File

@@ -171,6 +171,10 @@ namespace Torch.Commands
}
_stopPending = true;
if (!save)
Log.Warn("Stop without save is not possible. Feature is deprecated");
Task.Run(() =>
{
var countdown = StopCountdown(countdownSeconds, save).GetEnumerator();
@@ -203,6 +207,9 @@ namespace Torch.Commands
_restartPending = true;
if (!save)
Log.Warn("Restart without save is not possible. Feature is deprecated");
Task.Run(() =>
{
var countdown = RestartCountdown(countdownSeconds, save).GetEnumerator();
@@ -272,20 +279,11 @@ namespace Torch.Commands
Log.Info("Saving game before stop.");
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.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());
}
yield break;
}
}
@@ -322,7 +320,7 @@ namespace Torch.Commands
{
if (save)
{
Log.Info("Savin game before restart.");
Log.Info("Saving game before restart.");
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
.SendMessageAsSelf($"Saving game before restart.");
}