mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
baselineTick safety chekc moved into DeserializeServerDelta
This commit is contained in:
parent
6529756c91
commit
22bc5f3fbd
@ -261,13 +261,23 @@ void SerializeServerDelta(NetworkWriter writer, byte baselineTick, Vector3? posi
|
|||||||
if (syncScale) writer.WriteVector3(scale.Value);
|
if (syncScale) writer.WriteVector3(scale.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeserializeServerDelta(NetworkReader reader, out byte baselineTick, out Vector3? position, out Quaternion? rotation, out Vector3? scale)
|
bool DeserializeServerDelta(NetworkReader reader, out byte baselineTick, out Vector3? position, out Quaternion? rotation, out Vector3? scale)
|
||||||
{
|
{
|
||||||
baselineTick = reader.ReadByte();
|
|
||||||
position = null;
|
position = null;
|
||||||
rotation = null;
|
rotation = null;
|
||||||
scale = null;
|
scale = null;
|
||||||
|
|
||||||
|
baselineTick = reader.ReadByte();
|
||||||
|
|
||||||
|
// unreliable messages may arrive out of order.
|
||||||
|
// ensure this is for the intended baseline.
|
||||||
|
// we don't want to put a delta onto an old baseline.
|
||||||
|
if (baselineTick != lastDeserializedBaselineTick)
|
||||||
|
{
|
||||||
|
Debug.Log($"[{name}] Client discarding unreliable delta for baseline #{baselineTick} because we already received #{lastDeserializedBaselineTick}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (syncPosition)
|
if (syncPosition)
|
||||||
{
|
{
|
||||||
position = reader.ReadVector3();
|
position = reader.ReadVector3();
|
||||||
@ -280,6 +290,8 @@ void DeserializeServerDelta(NetworkReader reader, out byte baselineTick, out Vec
|
|||||||
{
|
{
|
||||||
scale = reader.ReadVector3();
|
scale = reader.ReadVector3();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmd /////////////////////////////////////////////////////////////////
|
// cmd /////////////////////////////////////////////////////////////////
|
||||||
@ -359,10 +371,12 @@ void RpcServerToClientDeltaSync(ArraySegment<byte> message)
|
|||||||
{
|
{
|
||||||
using (NetworkReaderPooled reader = NetworkReaderPool.Get(message))
|
using (NetworkReaderPooled reader = NetworkReaderPool.Get(message))
|
||||||
{
|
{
|
||||||
DeserializeServerDelta(reader, out byte baselineTick, out Vector3? position, out Quaternion? rotation, out Vector3? scale);
|
if (DeserializeServerDelta(reader, out byte baselineTick, out Vector3? position, out Quaternion? rotation, out Vector3? scale))
|
||||||
|
{
|
||||||
OnServerToClientDeltaSync(baselineTick, position, rotation, scale);
|
OnServerToClientDeltaSync(baselineTick, position, rotation, scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// server broadcasts sync message to all clients
|
// server broadcasts sync message to all clients
|
||||||
protected virtual void OnServerToClientDeltaSync(byte baselineTick, Vector3? position, Quaternion? rotation, Vector3? scale)
|
protected virtual void OnServerToClientDeltaSync(byte baselineTick, Vector3? position, Quaternion? rotation, Vector3? scale)
|
||||||
@ -378,15 +392,6 @@ protected virtual void OnServerToClientDeltaSync(byte baselineTick, Vector3? pos
|
|||||||
// don't apply for local player with authority
|
// don't apply for local player with authority
|
||||||
if (IsClientWithAuthority) return;
|
if (IsClientWithAuthority) return;
|
||||||
|
|
||||||
// unreliable messages may arrive out of order.
|
|
||||||
// ensure this is for the intended baseline.
|
|
||||||
// we don't want to put a delta onto an old baseline.
|
|
||||||
if (baselineTick != lastDeserializedBaselineTick)
|
|
||||||
{
|
|
||||||
Debug.Log($"[{name}] Client discarding unreliable delta for baseline #{baselineTick} because we already received #{lastDeserializedBaselineTick}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.Log($"[{name}] Client: received delta for baseline #{baselineTick}");
|
Debug.Log($"[{name}] Client: received delta for baseline #{baselineTick}");
|
||||||
|
|
||||||
// on the client, we receive rpcs for all entities.
|
// on the client, we receive rpcs for all entities.
|
||||||
|
Loading…
Reference in New Issue
Block a user