mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
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:
parent
413291a857
commit
73cd1ac72a
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user