Skip to content

Commit

Permalink
Make the replay has error use the ReplayIgnoreErrors cvar (space-wiza…
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr authored Mar 17, 2024
1 parent c8cb13f commit 0245c37
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
25 changes: 10 additions & 15 deletions Robust.Client/Replays/Loading/ReplayLoadManager.Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,21 @@ public async Task<ReplayData> LoadReplayAsync(IReplayFileReader fileReader, Load
return parsed.FirstOrDefault()?.Root as MappingDataNode;
}

private (MappingDataNode YamlData, HashSet<string> CVars, TimeSpan Duration, TimeSpan StartTime, bool ClientSide)
private (MappingDataNode YamlData, HashSet<string> CVars, TimeSpan? Duration, TimeSpan StartTime, bool ClientSide)
LoadMetadata(IReplayFileReader fileReader)
{
_sawmill.Info($"Reading replay metadata");
var data = LoadYamlMetadata(fileReader);
if (data == null)
throw new Exception("Failed to load yaml metadata");

TimeSpan duration;
var finalData = LoadYamlFinalMetadata(fileReader);
if (finalData == null)
{
var msg = "Failed to load final yaml metadata";
if (!_confMan.GetCVar(CVars.ReplayIgnoreErrors))
throw new Exception(msg);
TimeSpan? duration = finalData == null
? null
: TimeSpan.Parse(((ValueDataNode) finalData[MetaFinalKeyDuration]).Value);

_sawmill.Error(msg);
duration = TimeSpan.FromDays(1);
}
else
{
duration = TimeSpan.Parse(((ValueDataNode) finalData[MetaFinalKeyDuration]).Value);
}
if (finalData == null)
_sawmill.Warning("Failed to load final yaml metadata. Partial/incomplete replay?");

var typeHashString = ((ValueDataNode) data[MetaKeyTypeHash]).Value;
var typeHash = Convert.FromHexString(typeHashString);
Expand All @@ -163,7 +155,10 @@ public async Task<ReplayData> LoadReplayAsync(IReplayFileReader fileReader, Load

if (!typeHash.SequenceEqual(_serializer.GetSerializableTypesHash()))
{
_sawmill.Warning($"RobustSerializer hash mismatch. Replay may fail to load!!! Our hash: {_serializer.GetSerializableTypesHashString()}, replay hash: {typeHashString}");
if (!_confMan.GetCVar(CVars.ReplayIgnoreErrors))
throw new Exception($"RobustSerializer hash mismatch. do not match. Client hash: {_serializer.GetSerializableTypesHashString()}, replay hash: {typeHashString}.");

_sawmill.Warning($"RobustSerializer hash mismatch. Replay may fail to load!");
}

using var stringFile = fileReader.Open(FileStrings);
Expand Down
5 changes: 3 additions & 2 deletions Robust.Client/Replays/UI/ReplayControlWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected override void FrameUpdate(FrameEventArgs args)
var maxIndex = Math.Max(1, replay.States.Count - 1);
var state = replay.States[index];
var replayTime = TimeSpan.FromSeconds(TickSlider.Value);
var end = replay.Duration == null ? "N/A" : replay.Duration.Value.ToString(TimeFormat);

IndexLabel.Text = Loc.GetString("replay-time-box-index-label",
("current", index), ("total", maxIndex), ("percentage", percentage));
Expand All @@ -98,10 +99,10 @@ protected override void FrameUpdate(FrameEventArgs args)
("current", state.ToSequence), ("total", replay.States[^1].ToSequence), ("percentage", percentage));

TimeLabel.Text = Loc.GetString("replay-time-box-replay-time-label",
("current", replayTime.ToString(TimeFormat)), ("end", replay.Duration.ToString(TimeFormat)), ("percentage", percentage));
("current", replayTime.ToString(TimeFormat)), ("end", end), ("percentage", percentage));

var serverTime = (replayTime + replay.StartTime).ToString(TimeFormat);
var duration = (replay.Duration + replay.StartTime).ToString(TimeFormat);
string duration = replay.Duration == null ? "N/A" : (replay.Duration + replay.StartTime).Value.ToString(TimeFormat);
ServerTimeLabel.Text = Loc.GetString("replay-time-box-server-time-label",
("current", serverTime), ("end", duration), ("percentage", percentage));

Expand Down
3 changes: 2 additions & 1 deletion Robust.Shared/CVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,8 @@ protected CVars()
/// original exception rather than sending people on a wild-goose chase to find a non-existent bug.
/// </remarks>
public static readonly CVarDef<bool> ReplayIgnoreErrors =
CVarDef.Create("replay.ignore_errors", false, CVar.CLIENTONLY | CVar.ARCHIVE);
CVarDef.Create("replay.ignore_errors", false, CVar.CLIENTONLY);

/*
* CFG
*/
Expand Down
4 changes: 2 additions & 2 deletions Robust.Shared/Replays/ReplayData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public sealed class ReplayData
/// <summary>
/// The length of this recording.
/// </summary>
public readonly TimeSpan Duration;
public readonly TimeSpan? Duration;

/// <summary>
/// Array of checkpoint states. These are full game states that make it faster to jump around in time.
Expand Down Expand Up @@ -95,7 +95,7 @@ public ReplayData(List<GameState> states,
TimeSpan[] replayTime,
GameTick tickOffset,
TimeSpan startTime,
TimeSpan duration,
TimeSpan? duration,
CheckpointState[] checkpointStates,
ReplayMessage? initData,
bool clientSideRecording,
Expand Down

0 comments on commit 0245c37

Please sign in to comment.