-
-
Notifications
You must be signed in to change notification settings - Fork 842
Description
After commit b980ea4 (the Command system rewrite), Commands that include a NetworkConnectionToClient sender parameter no longer receive a valid sender when the Command is executed on a server-owned object (scene object or spawned without an owner), even if the Command was legitimately invoked by a client and requiresAuthority = false.
PR #4063 fixed this for objects that have a valid connectionToClient, but the problem still remains for server-owned objects where connectionToClient is naturally null.
Before the rewrite, this worked correctly:
Commands called by clients on server-owned objects could receive the sender connection.
Reproduction
- Create a server-owned object:
NetworkServer.Spawn(globalObj); // no owner- On each client (and host-client), call a Command from OnStartClient.
public class GlobalManager : NetworkBehaviour
{
public override void OnStartClient()
{
base.OnStartClient();
CmdRegisterClient(); // called from client-side of each client
}
[Command(requiresAuthority = false)]
void CmdRegisterClient(NetworkConnectionToClient sender = null)
{
Debug.Log("Sender = " + sender); // <-- always null for host + server object
}
}- Observe on the server:
Thesenderis alwaysnullbecause the weaver still fills it withthis.connectionToClient, which isnullfor server-owned objects.
This happens even though the Command was called by a real client.
Expected
Commands with requiresAuthority = false should provide the calling client's connection as the sender, same as before commit b980ea4.
Actual
Commands on server-owned objects always receive sender == null after the rewrite.
PR #4063 fixes this only when connectionToClient is non-null (player-owned or client-owned objects), but not for server-owned ones.
P.S. I’m not entirely sure if my understanding of the root cause is 100% correct, and I apologize if any part of this description is inaccurate.