@@ -959,26 +959,45 @@ internal void ReadSnapshot(ulong clientId, Stream snapshotStream)
959
959
snapshotTick = reader . ReadInt32Packed ( ) ;
960
960
var sequence = reader . ReadUInt16 ( ) ;
961
961
962
- // todo: check we didn't miss any and deal with gaps
963
-
964
- if ( m_ClientData [ clientId ] . ReceivedSequenceMask != 0 )
962
+ if ( sequence >= m_ClientData [ clientId ] . LastReceivedSequence )
965
963
{
966
- // since each bit in ReceivedSequenceMask is relative to the last received sequence
967
- // we need to shift all the bits by the difference in sequence
968
- m_ClientData [ clientId ] . ReceivedSequenceMask <<=
969
- ( sequence - m_ClientData [ clientId ] . LastReceivedSequence ) ;
970
- }
964
+ if ( m_ClientData [ clientId ] . ReceivedSequenceMask != 0 )
965
+ {
966
+ // since each bit in ReceivedSequenceMask is relative to the last received sequence
967
+ // we need to shift all the bits by the difference in sequence
968
+ var shift = sequence - m_ClientData [ clientId ] . LastReceivedSequence ;
969
+ if ( shift < sizeof ( ushort ) * 8 )
970
+ {
971
+ m_ClientData [ clientId ] . ReceivedSequenceMask <<= shift ;
972
+ }
973
+ else
974
+ {
975
+ m_ClientData [ clientId ] . ReceivedSequenceMask = 0 ;
976
+ }
977
+ }
971
978
972
- if ( m_ClientData [ clientId ] . LastReceivedSequence != 0 )
979
+ if ( m_ClientData [ clientId ] . LastReceivedSequence != 0 )
980
+ {
981
+ // because the bit we're adding for the previous ReceivedSequenceMask
982
+ // was implicit, it needs to be shift by one less
983
+ var shift = sequence - 1 - m_ClientData [ clientId ] . LastReceivedSequence ;
984
+ if ( shift < sizeof ( ushort ) * 8 )
985
+ {
986
+ m_ClientData [ clientId ] . ReceivedSequenceMask |= ( ushort ) ( 1 << shift ) ;
987
+ }
988
+ }
989
+
990
+ m_ClientData [ clientId ] . LastReceivedSequence = sequence ;
991
+ }
992
+ else
973
993
{
974
- // because the bit we're adding for the previous ReceivedSequenceMask
975
- // was implicit, it needs to be shift by one less
976
- m_ClientData [ clientId ] . ReceivedSequenceMask +=
977
- ( ushort ) ( 1 << ( ushort ) ( ( sequence - 1 ) - m_ClientData [ clientId ] . LastReceivedSequence ) ) ;
994
+ // todo: Missing: dealing with out-of-order message acknowledgments
995
+ // we should set m_ClientData[clientId].ReceivedSequenceMask accordingly
996
+ // testing this will require a way to reorder SnapshotMessages, which we lack at the moment
997
+ //
998
+ // without this, we incur extra retransmit, not a catastrophic failure
978
999
}
979
1000
980
- m_ClientData [ clientId ] . LastReceivedSequence = sequence ;
981
-
982
1001
var sentinel = reader . ReadUInt16 ( ) ;
983
1002
if ( sentinel != SentinelBefore )
984
1003
{
0 commit comments