-
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 and more #3081
Merged
NoelStephensUnity
merged 25 commits into
develop-2.0.0
from
fix/networkvariable-collections-can-be-modified-without-write-permissions
Oct 16, 2024
Merged
fix: networkvariable collections can be modified without write permissions and more #3081
NoelStephensUnity
merged 25 commits into
develop-2.0.0
from
fix/networkvariable-collections-can-be-modified-without-write-permissions
Oct 16, 2024
Conversation
This file contains 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
NoelStephensUnity
added
the
type:backport-release-1.0.0
This PR should be backported to 1.0.0
label
Sep 27, 2024
Fixing issue where upon a client gaining ownership of a NetworkObject that has one or more owner write permission NetworkVariables using a collection type with keyed indices (like a dictionary) can resend already synchronized entries when making a change to the collection causing non-owner clients to throw a key already exists exception.
Adjusted when the NetworkVariable update for ownership change is invoked to account for updates to owner write NetworkVariables within the OnGainedOwnership callback. When changing ownership: - Marking any owner read permissions NetworkVariables as dirty when sending to the new owner (both within NetworkSpawnManager for server-side update and within the NetworkVariableDeltaMessage). - Sending any pending updates to all clients prior to sending the change in ownership message to assure pending updates are synchronized as the owner. When initially synchronizing a client, if a NetworkVariable has a pending state update then send serialize the previously known value(s) to the synchronizing client so when the pending updates are sent they don't duplicate values.
NoelStephensUnity
changed the title
fix: networkvariable collections can be modified without write permissions
fix: networkvariable collections can be modified without write permissions and more
Sep 30, 2024
This includes additional fixes for NetworkVariable collections that ended up requiring a different approach to how a server forwards NetworkVariable deltas. Now, NetworkVariableDeltaMessage forwards NetworkVariable field deltas immediately after a server has finished processing the deltas (i.e. the keeping a NetworkVariable dirty concept is not used from this point forward). I went ahead and kept the compatibility of this functionality. NetworkVariableDeltaMessage has had its Version incremented as we now send the NetworkDelivery type in order to be able to handle this (it seemed less risky to include this than to try and bubble up this property to all message types). This also separates the duplication of the "original internal value" and the "previous value" until after processing all deltas. If the server has to foward, it forwards first then invokes the PostDeltaRead method that performs the duplication. This includes some minor adjustments to NetworkList in order to adjust to this new order of operations while also preserving the legacy approach. This also includes some adjustments to NetworkBehaviourUpdater where it can force a send (flush) any pending dirty fields when changing ownership. This includes some minor modifications to NetworkObject.PostNetworkVariableWrite.
…-be-modified-without-write-permissions
…-be-modified-without-write-permissions
…-be-modified-without-write-permissions
…-be-modified-without-write-permissions
…-be-modified-without-write-permissions
DAHost fixes: Fixed issue where it was possible to ignore forwarding a change in ownership message to the destination owner if the original owner changed ownership. Fixed issue where it was possible to re-send a change in ownership message back to the original owner if the original owner sent the message.
DSchroer
reviewed
Oct 16, 2024
com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs
Outdated
Show resolved
Hide resolved
Removing the DAHost testfixture that wasn't supposed to be added. Fixing an issue with the NetworkObjectOwnershipTests when running in DAHost mode. It was passing because the DAHost was sending the ChangeOwnershipMessage back to the owner that changed ownership to another client (without the fix for that in this PR it would send the message to the authority/owner which is why the test was passing).
…rkVariableDeltaMessage.cs Co-authored-by: Dominick <[email protected]>
NoelStephensUnity
deleted the
fix/networkvariable-collections-can-be-modified-without-write-permissions
branch
October 16, 2024 20:24
NoelStephensUnity
added a commit
that referenced
this pull request
Nov 15, 2024
NoelStephensUnity
added a commit
that referenced
this pull request
Nov 15, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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).fix: #3070
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
NetworkVariableCollectionsTests
.