Skip to content

Commit 8ea338a

Browse files
committed
Added error checks on Sync messages
1 parent 5d6114a commit 8ea338a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,21 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
697697
uint netId = messageReader.ReadUInt32(); //NetId the syncvar is from
698698
ushort orderIndex = messageReader.ReadUInt16();
699699
byte fieldIndex = messageReader.ReadByte();
700+
if(!SpawnManager.spawnedObjects.ContainsKey(netId))
701+
{
702+
Debug.LogWarning("MLAPI: Sync message recieved for a non existant object with id: " + netId);
703+
return;
704+
}
705+
else if(SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex) == null)
706+
{
707+
Debug.LogWarning("MLAPI: Sync message recieved for a non existant behaviour");
708+
return;
709+
}
710+
else if(fieldIndex > (SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).syncedFieldTypes.Count - 1))
711+
{
712+
Debug.LogWarning("MLAPI: Sync message recieved for field out of bounds");
713+
return;
714+
}
700715
FieldType type = SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).syncedFieldTypes[fieldIndex];
701716
switch (type)
702717
{

0 commit comments

Comments
 (0)