-
Notifications
You must be signed in to change notification settings - Fork 437
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
fix: networkvariable collections can be modified without write permissions [backport] #3126
fix: networkvariable collections can be modified without write permissions [backport] #3126
Conversation
…dified-without-write-permissions-backport
/// until it is done serializing all valid NetworkVariable field deltas (relative to each client). This is invoked | ||
/// after it is done forwarding the deltas at the end of the <see cref="NetworkVariableDeltaMessage.Handle(ref NetworkContext)"/> method. | ||
/// </summary> | ||
internal virtual void PostDeltaRead() |
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.
Should this be empty?
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.
Yes.
The two derived classes (NetworkVariable
and NetworkList
) provide overrides to handle this, but the base class doesn't need to do anything since it is just an abstract class.
@@ -1725,7 +1735,7 @@ public void Deserialize(FastBufferReader reader) | |||
} | |||
} | |||
|
|||
internal void PostNetworkVariableWrite() | |||
internal void PostNetworkVariableWrite(bool forceSend) | |||
{ |
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 method inherited? If not why is the argument added? Should it be passed on to the ChildNetworkBehaviours in the loop?
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.
Good catch you are right about passing it along... that needs to be fixed.
This is a backport of #3081.
This PR resolves the issue where a client or server could modify a collection with no write permissions. The underlying issue is that default .NET collections have no way to be notified when the collection is modified. Since polling each instance is not an option, the lowest risk fix that continues to support standard .NET collections was to:
NetworkVariable.CheckDirtyState
andNetworkVariable.IsDirty
such that the same form of comparison occurs to provide users with an additional way to check collection integrity on clients without write permissions while also being able to control how often the collection is checked.This PR also resolves:
This PR also changes:
NetworkVariableDeltaMessage
now includes the ability for a server to immediately forward delta state updates (to valid clients on a per NetworkVariable field basis) without having to queue them for end of frame (i.e. since messages are processed at the beginning of a frame, this shaves off the state replication time to other clients by close to the total frame time...which depending upon your project could mean 10-16ms faster).Changelog
NetworkVariableDeltaMessage
so the server now forwards delta state updates (owner write permission based from a client) to other clients immediately as opposed to keeping aNetworkVariable
orNetworkList
dirty and processing them at the end of the frame or potentially on the next network tick.NetworkVariable
values always which could cause issues with collections if there were any pending state updates. Now, when initially synchronizing a client, if aNetworkVariable
has a pending state update it will serialize the previously known value(s) to the synchronizing client so when the pending updates are sent they aren't duplicate values on the newly connected client side.NetworkVariable
dirty. Now, it will only mark anyNetworkVariable
with owner read permissions as dirty and will send/flush any pending updates to all clients prior to sending the change in ownership message.NetworkVariable
collections where transferring ownership to another client would not update the new owner's previous value to the most current value which could cause the last/previous added value to be detected as a change when adding or removing an entry (as long as the entry removed was not the last/previously added value).NetworkVariable
using a standard .NET collection type could still modify the collection which could cause various issues depending upon the modification and collection type.Testing and Documentation