Skip to content

Commit a8ce784

Browse files
committed
Implemented checks for NetworkedVar Write permission
1 parent 6dea85a commit a8ce784

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,24 +993,50 @@ internal void NetworkedVarUpdate()
993993
}
994994
}
995995

996-
internal void HandleNetworkedVarDeltas(BitReader reader)
996+
internal void HandleNetworkedVarDeltas(BitReader reader, uint clientId)
997997
{
998998
for (int i = 0; i < networkedVarFields.Count; i++)
999999
{
10001000
if (!reader.ReadBool())
10011001
continue;
10021002

1003+
if (isServer && !networkedVarFields[i].CanClientWrite(clientId))
1004+
{
1005+
//This client wrote somewhere they are not allowed. This is critical
1006+
//We can't just skip this field. Because we don't actually know how to dummy read
1007+
//That is, we don't know how many bytes to skip. Because the interface doesn't have a
1008+
//Read that gives us the value. Only a Read that applies the value straight away
1009+
//A dummy read COULD be added to the interface for this situation, but it's just being too nice.
1010+
//This is after all a developer fault. A critical error should be fine.
1011+
// - TwoTen
1012+
if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("Client wrote to NetworkedVar without permission. No more variables can be read. This is critical");
1013+
return;
1014+
}
1015+
10031016
networkedVarFields[i].SetDeltaFromReader(reader);
10041017
}
10051018
}
10061019

1007-
internal void HandleNetworkedVarUpdate(BitReader reader)
1020+
internal void HandleNetworkedVarUpdate(BitReader reader, uint clientId)
10081021
{
10091022
for (int i = 0; i < networkedVarFields.Count; i++)
10101023
{
10111024
if (!reader.ReadBool())
10121025
continue;
10131026

1027+
if (isServer && !networkedVarFields[i].CanClientWrite(clientId))
1028+
{
1029+
//This client wrote somewhere they are not allowed. This is critical
1030+
//We can't just skip this field. Because we don't actually know how to dummy read
1031+
//That is, we don't know how many bytes to skip. Because the interface doesn't have a
1032+
//Read that gives us the value. Only a Read that applies the value straight away
1033+
//A dummy read COULD be added to the interface for this situation, but it's just being too nice.
1034+
//This is after all a developer fault. A critical error should be fine.
1035+
// - TwoTen
1036+
if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("Client wrote to NetworkedVar without permission. No more variables can be read. This is critical");
1037+
return;
1038+
}
1039+
10141040
networkedVarFields[i].SetFieldFromReader(reader);
10151041
}
10161042
}

MLAPI/NetworkingManagerComponents/Core/InternalMessageHandler.Receive.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ internal static void HandleNetworkedVarDelta(uint clientId, BitReader reader, in
378378
return;
379379
}
380380

381-
SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).HandleNetworkedVarDeltas(reader);
381+
SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).HandleNetworkedVarDeltas(reader, clientId);
382382
}
383383

384384
internal static void HandleNetworkedVarUpdate(uint clientId, BitReader reader, int channelId)
@@ -397,7 +397,7 @@ internal static void HandleNetworkedVarUpdate(uint clientId, BitReader reader, i
397397
return;
398398
}
399399

400-
SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).HandleNetworkedVarUpdate(reader);
400+
SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).HandleNetworkedVarUpdate(reader, clientId);
401401
}
402402
}
403403
}

0 commit comments

Comments
 (0)