Fix overwriting Sandbox with stale cached version

This commit is contained in:
John Gross
2019-12-07 18:15:48 -08:00
parent 21fd997554
commit 540b17448a
4 changed files with 11 additions and 6 deletions

View File

@@ -198,6 +198,12 @@ namespace Torch.Server.Managers
public void SaveConfig()
{
if (((TorchServer)Torch).HasRun)
{
Log.Warn("Checkpoint cache is stale, not saving dedicated config.");
return;
}
DedicatedConfig.Save(Path.Combine(Torch.Config.InstancePath, CONFIG_NAME));
Log.Info("Saved dedicated config.");
@@ -308,7 +314,7 @@ namespace Torch.Server.Managers
}
OnPropertyChanged(nameof(Checkpoint));
OnPropertyChanged(nameof(WorldConfiguration));
OnPropertyChanged(nameof(WorldConfiguration));
}
}
}

View File

@@ -41,7 +41,6 @@ namespace Torch.Server
{
private bool _canRun;
private TimeSpan _elapsedPlayTime;
private bool _hasRun;
private bool _isRunning;
private float _simRatio;
private ServerState _state;
@@ -65,6 +64,8 @@ namespace Torch.Server
sessionManager.AddFactory(x => new MultiplayerManagerDedicated(this));
}
public bool HasRun { get; private set; }
/// <inheritdoc />
public float SimulationRatio { get => _simRatio; set => SetValue(ref _simRatio, value); }
@@ -120,7 +121,7 @@ namespace Torch.Server
if (State != ServerState.Stopped)
return;
if (_hasRun)
if (IsRunning || HasRun)
{
Restart();
return;
@@ -129,7 +130,6 @@ namespace Torch.Server
State = ServerState.Starting;
IsRunning = true;
CanRun = false;
_hasRun = true;
Log.Info("Starting server.");
MySandboxGame.ConfigDedicated = DedicatedInstance.DedicatedConfig.Model;
@@ -144,6 +144,7 @@ namespace Torch.Server
Log.Error("Server is already stopped");
Log.Info("Stopping server.");
base.Stop();
HasRun = true;
Log.Info("Server stopped.");
State = ServerState.Stopped;