]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Catch replay start and end errors on round restarts (#20565)
authorDrSmugleaf <DrSmugleaf@users.noreply.github.com>
Thu, 28 Sep 2023 22:48:29 +0000 (15:48 -0700)
committerGitHub <noreply@github.com>
Thu, 28 Sep 2023 22:48:29 +0000 (15:48 -0700)
Content.Server/GameTicking/GameTicker.Replays.cs

index 03cf748d09d350fe17d109667918016d1e06e8ca..78a8182ce6f5dd0382341a11b1286de17a76918b 100644 (file)
@@ -23,38 +23,45 @@ public sealed partial class GameTicker
     /// </summary>
     private void ReplayStartRound()
     {
-        if (!_cfg.GetCVar(CCVars.ReplayAutoRecord))
-            return;
-
-        if (_replays.IsRecording)
+        try
         {
-            _sawmillReplays.Warning("Already an active replay recording before the start of the round, not starting automatic recording.");
-            return;
-        }
+            if (!_cfg.GetCVar(CCVars.ReplayAutoRecord))
+                return;
 
-        _sawmillReplays.Debug($"Starting replay recording for round {RoundId}");
+            if (_replays.IsRecording)
+            {
+                _sawmillReplays.Warning("Already an active replay recording before the start of the round, not starting automatic recording.");
+                return;
+            }
 
-        var finalPath = GetAutoReplayPath();
-        var recordPath = finalPath;
-        var tempDir = _cfg.GetCVar(CCVars.ReplayAutoRecordTempDir);
-        ResPath? moveToPath = null;
+            _sawmillReplays.Debug($"Starting replay recording for round {RoundId}");
 
-        if (!string.IsNullOrEmpty(tempDir))
-        {
-            var baseReplayPath = new ResPath(_cfg.GetCVar(CVars.ReplayDirectory)).ToRootedPath();
-            moveToPath = baseReplayPath / finalPath;
+            var finalPath = GetAutoReplayPath();
+            var recordPath = finalPath;
+            var tempDir = _cfg.GetCVar(CCVars.ReplayAutoRecordTempDir);
+            ResPath? moveToPath = null;
 
-            var fileName = finalPath.Filename;
-            recordPath = new ResPath(tempDir) / fileName;
+            if (!string.IsNullOrEmpty(tempDir))
+            {
+                var baseReplayPath = new ResPath(_cfg.GetCVar(CVars.ReplayDirectory)).ToRootedPath();
+                moveToPath = baseReplayPath / finalPath;
 
-            _sawmillReplays.Debug($"Replay will record in temporary position: {recordPath}");
-        }
+                var fileName = finalPath.Filename;
+                recordPath = new ResPath(tempDir) / fileName;
+
+                _sawmillReplays.Debug($"Replay will record in temporary position: {recordPath}");
+            }
 
-        var recordState = new ReplayRecordState(moveToPath);
+            var recordState = new ReplayRecordState(moveToPath);
 
-        if (!_replays.TryStartRecording(_resourceManager.UserData, recordPath.ToString(), state: recordState))
+            if (!_replays.TryStartRecording(_resourceManager.UserData, recordPath.ToString(), state: recordState))
+            {
+                _sawmillReplays.Error("Can't start automatic replay recording!");
+            }
+        }
+        catch (Exception e)
         {
-            _sawmillReplays.Error("Can't start automatic replay recording!");
+            Log.Error($"Error while starting an automatic replay recording:\n{e}");
         }
     }
 
@@ -63,9 +70,16 @@ public sealed partial class GameTicker
     /// </summary>
     private void ReplayEndRound()
     {
-        if (_replays.ActiveRecordingState is ReplayRecordState)
+        try
+        {
+            if (_replays.ActiveRecordingState is ReplayRecordState)
+            {
+                _replays.StopRecording();
+            }
+        }
+        catch (Exception e)
         {
-            _replays.StopRecording();
+            Log.Error($"Error while stopping replay recording:\n{e}");
         }
     }