com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

NetworkList permissions and behaviour

Open ezoray opened this issue 3 years ago • 1 comments

Description

I wanted to share some testing I've done and to get an idea on what should and shouldn't be expected in different scenarios of writing to a network list with different permissions.

I have a client and server/host setup spawning a network object that contains a list of integers. It also has a network variable with owner permissions which is relevant in scenario 3.

  1. Server spawns object without ownership and populates list: Server can write to list, changes are sent to client Client can write to list, changes remain local

  2. Server spawns object without ownership, populates list, list has WritePermission.Owner: Server can write to list, changes are not sent to client Client can write to list, changes remain local

  3. Server spawns object with client ownership and populates list: Server can write to list, changes are sent to client Client can write to list, changes remain local If the client writes to the network variable this triggers a send from the server of all the list values in the form of OnListChanged events so the client ends up with a list twice as large as the server.

  4. Server spawns object with client ownership, populates list, list has WritePermission.Owner. Server can write to list, changes remain local Client can write to list, changes are sent to server

From the testing there looks to be inconsistency in how writing to NetworkLists and NetworkVariables you don't own are handled, with the former it's allowed and with the latter an exception is thrown. There is also the weird issue of the server resending the list values in scenario 3.

I've attached the files from the testing in case you want to try it yourself. To run add StartScene and NetworkListSpawnScene to your project build settings.

Environment

ezoray avatar Aug 26 '22 12:08 ezoray

Backlog: MTT-4519

ashwinimurt avatar Aug 29 '22 22:08 ashwinimurt

Server spawns object without ownership and populates list: Client can write to list, changes remain local

This is unexpected. An Exception should be thrown as this client write is not permitted. I'll have a PR to address this.

Server spawns object without ownership, populates list, list has WritePermission.Owner: Client can write to list, changes remain local

This is also unexpected. An Exception should be thrown as this client write is not permitted. I'll have a PR to address this.

Server spawns object with client ownership, populates list, list has WritePermission.Owner. Server can write to list, changes remain local

Same as above two. Same expected result: exception. Same PR will address this.

Server spawns object with client ownership and populates list: Client can write to list, changes remain local

Same.

If the client writes to the network variable this triggers a send from the server of all the list values in the form of OnListChanged events so the client ends up with a list twice as large as the server.

I'm still getting to repro this in our test suite. That would be a definite bug, though. Probably the same PR.

All-in-all, thanks for the report, I'm working on this.

Thanks, Jeffrey.

jeffreyrainy avatar Oct 04 '22 01:10 jeffreyrainy

Thanks @jeffreyrainy, that last issue stopped happening a little while ago so may have been fixed inadvertently by another update. There was one situation where it still happened in my main project but I wasn't able to reproduce it in testing and I've done away with that code since then.

ezoray avatar Oct 04 '22 08:10 ezoray

Addressed in https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/pull/2233 . That will be in the next release. Thanks again for the report, will close this.

jeffreyrainy avatar Oct 07 '22 17:10 jeffreyrainy