#[QUESTION] Valid method for confirming Client Authority?

4 messages · Page 1 of 1 (latest)

unreal ginkgo
#

Hey all, I got a simple scenario with two players (Host and Client) and some scene objects. Lets say I call AssignClientAuthority for every scene object passing over the LocalConnectionToClient of the Host so it has control/authority over these objects.

I had a look at the variable isOwned - which does not help as it's only set on player objects.
I looked at the variable "authority" but it utilizes sync direction which I never change and I can't find it relevant for me, I only want to know the connection that has control.

I wrote this simple helper method, but not seeing it already on the framework makes me think there might be a reason for it. Is there any?

/// <summary>
 /// If the current client has control over this object.
 /// </summary>
 /// <returns></returns>
 public bool HasControlOfId()
 {
     return netIdentity.connectionToClient == connectionToClient;
 }

Based on the method "SetClientOwner" the variable connectionToClient would only be equal to the local client connection if it owned the object. Thanks in advance!

fallow phoenix
#

Second, assigning everything in the scene to the host client is not a good idea. Treat host client as if it was a remote client, as if the server wasn't there. Keep server work separate always. If you don't adhere to this, your game will shatter all over if you ever run it headless or as Server Only.

#

Third, connectionToClient is meaningless on clients. Only server knows about that. It's only not null for the host client because it happens to live on the server, but again, don't exploit that or make special cases / code for host client. Treat it as a remote.