diff --git a/Torch.Server/Managers/InstanceManager.cs b/Torch.Server/Managers/InstanceManager.cs index d52197b..92f14e9 100644 --- a/Torch.Server/Managers/InstanceManager.cs +++ b/Torch.Server/Managers/InstanceManager.cs @@ -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)); } } } diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs index 389e2f8..5cd83ce 100644 --- a/Torch.Server/TorchServer.cs +++ b/Torch.Server/TorchServer.cs @@ -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; } + /// 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; diff --git a/Torch/Commands/TorchCommands.cs b/Torch/Commands/TorchCommands.cs index 52d52ed..2e4ee66 100644 --- a/Torch/Commands/TorchCommands.cs +++ b/Torch/Commands/TorchCommands.cs @@ -272,7 +272,6 @@ namespace Torch.Commands Debug.Assert(torch != null); torch.Stop(); }, this, TaskContinuationOptions.RunContinuationsAsynchronously); - } else { diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs index 8ad7f16..0658a60 100644 --- a/Torch/TorchBase.cs +++ b/Torch/TorchBase.cs @@ -230,7 +230,6 @@ namespace Torch MySandboxGame.Static.Invoke(action, caller); } - /// [MethodImpl(MethodImplOptions.NoInlining)] public void InvokeBlocking(Action action, int timeoutMs = -1, [CallerMemberName] string caller = "")