fix: #2629 - Revert "NetworkBehaviour.SendCommandInternal: use connectionToServer instead of NetworkClient.readyConnection. reduces dependencies on NetworkClient.readyConnection (which is redundant) and reduces static states. (#2620)"

This reverts commit 64f247fb32.
=> also adding a comment for next time
This commit is contained in:
vis2k 2021-03-12 14:54:09 +08:00
parent 413291a857
commit 73cd1ac72a
2 changed files with 14 additions and 16 deletions

View File

@ -145,21 +145,18 @@ protected void SendCommandInternal(Type invokeClass, string cmdName, NetworkWrit
return;
}
// originally we checked if NetworkClient.readyConnection == null
// instead check connectionToServer and isReady.
if (connectionToServer == null)
// IMPORTANT: can't use .connectionToServer here because calling
// a command on other objects is allowed if requireAuthority is
// false. other objects don't have a .connectionToServer.
// => so we always need to use NetworkClient.connection instead.
// => see also: https://github.com/vis2k/Mirror/issues/2629
if (NetworkClient.readyConnection == null)
{
Debug.LogError("Send command attempted with no client running [client=" + connectionToServer + "].");
return;
}
if (!connectionToServer.isReady)
{
Debug.LogError("Trying to send command, but connectionToServer isn't ready");
return;
}
// send CommandMessage to the server
// construct the message
CommandMessage message = new CommandMessage
{
netId = netId,
@ -170,7 +167,12 @@ protected void SendCommandInternal(Type invokeClass, string cmdName, NetworkWrit
payload = writer.ToArraySegment()
};
connectionToServer.Send(message, channelId);
// IMPORTANT: can't use .connectionToServer here because calling
// a command on other objects is allowed if requireAuthority is
// false. other objects don't have a .connectionToServer.
// => so we always need to use NetworkClient.connection instead.
// => see also: https://github.com/vis2k/Mirror/issues/2629
NetworkClient.readyConnection.Send(message, channelId);
}
protected void SendRPCInternal(Type invokeClass, string rpcName, NetworkWriter writer, int channelId, bool includeOwner)

View File

@ -362,17 +362,13 @@ public void SendCommandInternal()
// won't find it
NetworkIdentity.spawned[identity.netId] = identity;
// calling command if connection isn't ready should not work
// calling command before clientscene has ready connection shouldn't work
// error log is expected
LogAssert.ignoreFailingMessages = true;
identity.connectionToServer.isReady = false;
comp.CallSendCommandInternal();
LogAssert.ignoreFailingMessages = false;
Assert.That(comp.called, Is.EqualTo(0));
// reset ready
identity.connectionToServer.isReady = true;
// clientscene.readyconnection needs to be set for commands
NetworkClient.Ready(connection.connectionToServer);