-
Notifications
You must be signed in to change notification settings - Fork 450
feat!: remove client network permissions [MTT-1019] #1051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -543,8 +543,7 @@ private void NetworkVariableUpdate(ulong clientId, int behaviourIndex) | |
|
||
// if I'm dirty AND a client, write (server always has all permissions) | ||
// if I'm dirty AND the server AND the client can read me, send. | ||
bool shouldWrite = isDirty && | ||
(!IsServer || NetworkVariableFields[k].CanClientRead(clientId)); | ||
bool shouldWrite = isDirty && IsServer && NetworkVariableFields[k].CanClientRead(clientId); | ||
|
||
if (NetworkManager.NetworkConfig.EnsureNetworkVariableLengthSafety) | ||
{ | ||
|
@@ -653,7 +652,7 @@ internal static void HandleNetworkVariableDeltas(List<INetworkVariable> networkV | |
} | ||
} | ||
|
||
if (networkManager.IsServer && !networkVariableList[i].CanClientWrite(clientId)) | ||
if (networkManager.IsServer)// ?? && !networkVariableList[i].CanClientWrite(clientId)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this even needed anymore? because essentially its checking to see if the client can actually write to this value and if not log it... I am not sure this would be possible anymore correct? |
||
{ | ||
if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety) | ||
{ | ||
|
@@ -722,94 +721,6 @@ internal static void HandleNetworkVariableDeltas(List<INetworkVariable> networkV | |
} | ||
} | ||
|
||
internal static void HandleNetworkVariableUpdate(List<INetworkVariable> networkVariableList, Stream stream, ulong clientId, NetworkBehaviour logInstance, NetworkManager networkManager) | ||
{ | ||
using (var reader = PooledNetworkReader.Get(stream)) | ||
{ | ||
for (int i = 0; i < networkVariableList.Count; i++) | ||
{ | ||
ushort varSize = 0; | ||
|
||
if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety) | ||
{ | ||
varSize = reader.ReadUInt16Packed(); | ||
|
||
if (varSize == 0) | ||
{ | ||
continue; | ||
} | ||
} | ||
else | ||
{ | ||
if (!reader.ReadBool()) | ||
{ | ||
continue; | ||
} | ||
} | ||
|
||
if (networkManager.IsServer && !networkVariableList[i].CanClientWrite(clientId)) | ||
{ | ||
if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety) | ||
{ | ||
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) | ||
{ | ||
NetworkLog.LogWarning($"Client wrote to {typeof(NetworkVariable<>).Name} without permission. => {(logInstance != null ? ($"{nameof(NetworkObjectId)}: {logInstance.NetworkObjectId} - {nameof(NetworkObject.GetNetworkBehaviourOrderIndex)}(): {logInstance.NetworkObject.GetNetworkBehaviourOrderIndex(logInstance)} - VariableIndex: {i}") : string.Empty)}"); | ||
} | ||
|
||
stream.Position += varSize; | ||
continue; | ||
} | ||
|
||
//This client wrote somewhere they are not allowed. This is critical | ||
//We can't just skip this field. Because we don't actually know how to dummy read | ||
//That is, we don't know how many bytes to skip. Because the interface doesn't have a | ||
//Read that gives us the value. Only a Read that applies the value straight away | ||
//A dummy read COULD be added to the interface for this situation, but it's just being too nice. | ||
//This is after all a developer fault. A critical error should be fine. | ||
// - TwoTen | ||
if (NetworkLog.CurrentLogLevel <= LogLevel.Error) | ||
{ | ||
NetworkLog.LogError($"Client wrote to {typeof(NetworkVariable<>).Name} without permission. No more variables can be read. This is critical. => {(logInstance != null ? ($"{nameof(NetworkObjectId)}: {logInstance.NetworkObjectId} - {nameof(NetworkObject.GetNetworkBehaviourOrderIndex)}(): {logInstance.NetworkObject.GetNetworkBehaviourOrderIndex(logInstance)} - VariableIndex: {i}") : string.Empty)}"); | ||
} | ||
|
||
return; | ||
} | ||
|
||
long readStartPos = stream.Position; | ||
|
||
networkVariableList[i].ReadField(stream); | ||
|
||
if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety) | ||
{ | ||
if (stream is NetworkBuffer networkBuffer) | ||
{ | ||
networkBuffer.SkipPadBits(); | ||
} | ||
|
||
if (stream.Position > (readStartPos + varSize)) | ||
{ | ||
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) | ||
{ | ||
NetworkLog.LogWarning($"Var update read too far. {stream.Position - (readStartPos + varSize)} bytes. => {(logInstance != null ? ($"{nameof(NetworkObjectId)}: {logInstance.NetworkObjectId} - {nameof(NetworkObject.GetNetworkBehaviourOrderIndex)}(): {logInstance.NetworkObject.GetNetworkBehaviourOrderIndex(logInstance)} - VariableIndex: {i}") : string.Empty)}"); | ||
} | ||
|
||
stream.Position = readStartPos + varSize; | ||
} | ||
else if (stream.Position < (readStartPos + varSize)) | ||
{ | ||
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) | ||
{ | ||
NetworkLog.LogWarning($"Var update read too little. {(readStartPos + varSize) - stream.Position} bytes. => {(logInstance != null ? ($"{nameof(NetworkObjectId)}: {logInstance.NetworkObjectId} - {nameof(NetworkObject.GetNetworkBehaviourOrderIndex)}(): {logInstance.NetworkObject.GetNetworkBehaviourOrderIndex(logInstance)} - VariableIndex: {i}") : string.Empty)}"); | ||
} | ||
|
||
stream.Position = readStartPos + varSize; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
internal static void WriteNetworkVariableData(List<INetworkVariable> networkVariableList, Stream stream, ulong clientId, NetworkManager networkManager) | ||
{ | ||
if (networkVariableList.Count == 0) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment still valid?