fix out of order check: use remoteTimestamp not local time, and allow == time

This commit is contained in:
mischa 2024-07-20 16:16:36 +02:00
parent a7639243e0
commit 254dc864b1
2 changed files with 12 additions and 8 deletions

View File

@ -1400,18 +1400,20 @@ static void OnEntityStateMessageUnreliable(EntityStateMessageUnreliable message)
// Debug.Log($"NetworkClient.OnUpdateVarsMessage {msg.netId}");
if (spawned.TryGetValue(message.netId, out NetworkIdentity identity) && identity != null)
{
// unreliable state sync messages may arrive out of order, or duplicated.
// unreliable state sync messages may arrive out of order.
// only ever apply state that's newer than the last received state.
if (connection.lastMessageTime <= identity.lastUnreliableStateTime)
// note that we send one EntityStateMessage per Entity,
// so there will be multiple with the same == timestamp.
if (connection.remoteTimeStamp < identity.lastUnreliableStateTime)
{
// debug log to show that it's working.
// can be tested via LatencySimulation scramble easily.
Debug.Log($"Client caught out of order Unreliable state message for {identity.name}. This is fine.\nIdentity timestamp={identity.lastUnreliableStateTime} message timestamp={connection.lastMessageTime}");
Debug.Log($"Client caught out of order Unreliable state message for {identity.name}. This is fine.\nIdentity timestamp={identity.lastUnreliableStateTime} batch remoteTimestamp={connection.remoteTimeStamp}");
return;
}
// set the new last received time for unreliable
identity.lastUnreliableStateTime = connection.lastMessageTime;
identity.lastUnreliableStateTime = connection.remoteTimeStamp;
// iniital is always 'true' because unreliable state sync alwasy serializes full
using (NetworkReaderPooled reader = NetworkReaderPool.Get(message.payload))

View File

@ -421,18 +421,20 @@ static void OnEntityStateMessageUnreliable(NetworkConnectionToClient connection,
// owned by the connection?
if (identity.connectionToClient == connection)
{
// unreliable state sync messages may arrive out of order, or duplicated.
// unreliable state sync messages may arrive out of order.
// only ever apply state that's newer than the last received state.
if (connection.lastMessageTime <= identity.lastUnreliableStateTime)
// note that we send one EntityStateMessage per Entity,
// so there will be multiple with the same == timestamp.
if (connection.remoteTimeStamp < identity.lastUnreliableStateTime)
{
// debug log to show that it's working.
// can be tested via LatencySimulation scramble easily.
Debug.Log($"Server caught out of order Unreliable state message for {identity.name}. This is fine.\nIdentity timestamp={identity.lastUnreliableStateTime} message timestamp={connection.lastMessageTime}");
Debug.Log($"Server caught out of order Unreliable state message for {identity.name}. This is fine.\nIdentity timestamp={identity.lastUnreliableStateTime} batch remoteTimestamp={connection.remoteTimeStamp}");
return;
}
// set the new last received time for unreliable
identity.lastUnreliableStateTime = connection.lastMessageTime;
identity.lastUnreliableStateTime = connection.remoteTimeStamp;
using (NetworkReaderPooled reader = NetworkReaderPool.Get(message.payload))
{