Skip to content

Commit

Permalink
fix: adding check for time out of order
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Jan 14, 2024
1 parent 441370e commit 4f01483
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Assets/NetworkPositionSync/Runtime/InterpolationTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public void OnUpdate(float deltaTime)
_clientTime += deltaTime * clientScaleTime;
}

public bool IsMessageOutOfOrder(float newServerTime)
{
return newServerTime < _latestServerTime;
}

/// <summary>
/// Updates <see cref="clientScaleTime"/> to keep <see cref="ClientTime"/> in line with <see cref="LatestServerTime"/>
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions Assets/NetworkPositionSync/Runtime/SyncPositionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,13 @@ internal void ClientHandleNetworkPositionMessage(NetworkPositionMessage msg)
{
var time = packer.UnpackTime(reader);

if (TimeSync.IsMessageOutOfOrder(time))
{
if (logger.LogEnabled()) logger.Log($"Ignoring packet before it was received out of order");
// we dont want old packetes, we only care about most recent data so client can lerp towards it
return;
}

while (packer.TryUnpackNext(reader, out var id, out var pos, out var rot))
{
if (Behaviours.Dictionary.TryGetValue(id, out var behaviour))
Expand Down

0 comments on commit 4f01483

Please sign in to comment.