Commit 632bf35
fix: networkvariable collections can be modified without write permissions and more (#3081)
* fix
Provide additional copy of last known current NetworkVariable.Value to be able to compare against the current local value in order to detect if a client without write permissions has modified a collection.
* test
Updated collections validation tests to spot check the restore known current state when client without write permissions modifies a collection.
* update
added changelog entry
* fix
Changing order of operations within CheckDirtyState for clients without write permissions
* test
Add some spot checks to one of the dictionary tests
* fix
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.
* update
Adding changelog entrry
* update
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.
* test
Adjusting two deferred message tests to not account for a NetworkVariable delta state update message when changing ownership and there are no pending updates.
* update
updating changelog entries
* style
* fix
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.
* test
Just some updates to two integration tests. These are all primarily for debugging purposes.
* update
Adding last change log entry for this PR.
* style
Updated a changelog entry to make it clearer.
* fix
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.
* test
Adding and additional test that validates several of the fixes in this PR.
* test fix
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).
* Update com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs
Co-authored-by: Dominick <[email protected]>
* style
Updating all instances of k_ServerDeltaForwadingAndNetworkDelivery and replacing with k_ServerDeltaForwardingAndNetworkDelivery
---------
Co-authored-by: Dominick <[email protected]>1 parent 6b459a1 commit 632bf35
File tree
14 files changed
+1608
-185
lines changed- com.unity.netcode.gameobjects
- Runtime
- Core
- Messaging/Messages
- NetworkVariable
- Collections
- Spawning
- Tests/Runtime
- NetworkObject
- NetworkVariable
14 files changed
+1608
-185
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| 36 | + | |
| 37 | + | |
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
| |||
Lines changed: 61 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
826 | 826 | | |
827 | 827 | | |
828 | 828 | | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
829 | 836 | | |
830 | 837 | | |
831 | 838 | | |
| |||
1016 | 1023 | | |
1017 | 1024 | | |
1018 | 1025 | | |
1019 | | - | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
1020 | 1032 | | |
1021 | | - | |
| 1033 | + | |
1022 | 1034 | | |
1023 | 1035 | | |
1024 | 1036 | | |
| |||
1069 | 1081 | | |
1070 | 1082 | | |
1071 | 1083 | | |
1072 | | - | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
1073 | 1089 | | |
1074 | 1090 | | |
1075 | 1091 | | |
| |||
1114 | 1130 | | |
1115 | 1131 | | |
1116 | 1132 | | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
1117 | 1153 | | |
1118 | 1154 | | |
1119 | 1155 | | |
| |||
1122 | 1158 | | |
1123 | 1159 | | |
1124 | 1160 | | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
1125 | 1172 | | |
1126 | 1173 | | |
1127 | 1174 | | |
| |||
1172 | 1219 | | |
1173 | 1220 | | |
1174 | 1221 | | |
1175 | | - | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
1176 | 1227 | | |
1177 | 1228 | | |
1178 | | - | |
| 1229 | + | |
1179 | 1230 | | |
1180 | 1231 | | |
1181 | 1232 | | |
1182 | 1233 | | |
1183 | 1234 | | |
1184 | | - | |
1185 | | - | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1186 | 1240 | | |
1187 | 1241 | | |
1188 | 1242 | | |
| |||
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
| |||
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
56 | | - | |
| 61 | + | |
57 | 62 | | |
58 | 63 | | |
59 | 64 | | |
| |||
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
75 | | - | |
| 80 | + | |
76 | 81 | | |
77 | 82 | | |
78 | 83 | | |
| |||
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
88 | 96 | | |
89 | 97 | | |
90 | 98 | | |
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
| 102 | + | |
| 103 | + | |
94 | 104 | | |
95 | 105 | | |
96 | 106 | | |
97 | 107 | | |
98 | 108 | | |
99 | 109 | | |
100 | | - | |
| 110 | + | |
101 | 111 | | |
102 | 112 | | |
103 | 113 | | |
| |||
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2445 | 2445 | | |
2446 | 2446 | | |
2447 | 2447 | | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
2448 | 2456 | | |
2449 | 2457 | | |
2450 | 2458 | | |
| |||
2771 | 2779 | | |
2772 | 2780 | | |
2773 | 2781 | | |
2774 | | - | |
| 2782 | + | |
2775 | 2783 | | |
2776 | 2784 | | |
2777 | 2785 | | |
2778 | | - | |
| 2786 | + | |
2779 | 2787 | | |
2780 | 2788 | | |
2781 | 2789 | | |
| |||
Lines changed: 27 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
258 | 257 | | |
259 | 258 | | |
260 | 259 | | |
261 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
262 | 266 | | |
263 | 267 | | |
264 | | - | |
265 | | - | |
| 268 | + | |
266 | 269 | | |
267 | 270 | | |
268 | 271 | | |
269 | | - | |
270 | 272 | | |
271 | 273 | | |
272 | 274 | | |
| |||
327 | 329 | | |
328 | 330 | | |
329 | 331 | | |
330 | | - | |
| 332 | + | |
331 | 333 | | |
332 | 334 | | |
333 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
334 | 338 | | |
335 | 339 | | |
336 | 340 | | |
| |||
347 | 351 | | |
348 | 352 | | |
349 | 353 | | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | 354 | | |
357 | 355 | | |
358 | 356 | | |
| |||
374 | 372 | | |
375 | 373 | | |
376 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
377 | 391 | | |
378 | 392 | | |
379 | 393 | | |
| |||
0 commit comments