From d406a55e49dbf530a7d709da4863b56509c15499 Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 12 Dec 2022 13:37:41 +0100 Subject: [PATCH] Utils.CreateLocalConnections for use from NetworkClient.ConnectHost & Tests --- Assets/Mirror/Core/NetworkClient.cs | 9 ++++----- Assets/Mirror/Core/Tools/Utils.cs | 11 +++++++++++ Assets/Mirror/Tests/Common/MirrorTest.cs | 9 --------- Assets/Mirror/Tests/Editor/LocalConnectionTest.cs | 2 +- Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs | 2 +- Assets/Mirror/Tests/Editor/NetworkServerTest.cs | 6 +++--- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Assets/Mirror/Core/NetworkClient.cs b/Assets/Mirror/Core/NetworkClient.cs index 6a8dbc174..58e1c408b 100644 --- a/Assets/Mirror/Core/NetworkClient.cs +++ b/Assets/Mirror/Core/NetworkClient.cs @@ -220,11 +220,10 @@ public static void ConnectHost() connectState = ConnectState.Connected; - // create local connection objects and connect them - LocalConnectionToServer connectionToServer = new LocalConnectionToServer(); - LocalConnectionToClient connectionToClient = new LocalConnectionToClient(); - connectionToServer.connectionToClient = connectionToClient; - connectionToClient.connectionToServer = connectionToServer; + // create local connections pair, both are connected + Utils.CreateLocalConnections( + out LocalConnectionToClient connectionToClient, + out LocalConnectionToServer connectionToServer); connection = connectionToServer; diff --git a/Assets/Mirror/Core/Tools/Utils.cs b/Assets/Mirror/Core/Tools/Utils.cs index 229e25bec..48d0316c0 100644 --- a/Assets/Mirror/Core/Tools/Utils.cs +++ b/Assets/Mirror/Core/Tools/Utils.cs @@ -166,5 +166,16 @@ public static Rect KeepInScreen(Rect rect) return rect; } + + // create local connections pair and connect them + public static void CreateLocalConnections( + out LocalConnectionToClient connectionToClient, + out LocalConnectionToServer connectionToServer) + { + connectionToServer = new LocalConnectionToServer(); + connectionToClient = new LocalConnectionToClient(); + connectionToServer.connectionToClient = connectionToClient; + connectionToClient.connectionToServer = connectionToServer; + } } } diff --git a/Assets/Mirror/Tests/Common/MirrorTest.cs b/Assets/Mirror/Tests/Common/MirrorTest.cs index 16f7098af..acfaddee0 100644 --- a/Assets/Mirror/Tests/Common/MirrorTest.cs +++ b/Assets/Mirror/Tests/Common/MirrorTest.cs @@ -654,14 +654,5 @@ protected void ProcessMessages() // update transport so sent messages are received UpdateTransport(); } - - // helper function to create local connection pair - protected void CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient, out LocalConnectionToServer connectionToServer) - { - connectionToClient = new LocalConnectionToClient(); - connectionToServer = new LocalConnectionToServer(); - connectionToClient.connectionToServer = connectionToServer; - connectionToServer.connectionToClient = connectionToClient; - } } } diff --git a/Assets/Mirror/Tests/Editor/LocalConnectionTest.cs b/Assets/Mirror/Tests/Editor/LocalConnectionTest.cs index 9fe986b94..be967e8dc 100644 --- a/Assets/Mirror/Tests/Editor/LocalConnectionTest.cs +++ b/Assets/Mirror/Tests/Editor/LocalConnectionTest.cs @@ -14,7 +14,7 @@ public override void SetUp() { base.SetUp(); - CreateLocalConnectionPair(out connectionToClient, out connectionToServer); + Utils.CreateLocalConnections(out connectionToClient, out connectionToServer); // set up server/client connections so message handling works NetworkClient.connection = connectionToServer; diff --git a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs index f1b0b9d49..156c1013c 100644 --- a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs @@ -527,7 +527,7 @@ public void AssignAndRemoveClientAuthority() }; // create connections - CreateLocalConnectionPair(out LocalConnectionToClient owner, out LocalConnectionToServer clientConnection); + Utils.CreateLocalConnections(out LocalConnectionToClient owner, out LocalConnectionToServer clientConnection); owner.isReady = true; // setup NetworkServer/Client connections so messages are handled diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index 52443e1b3..0e1439cf4 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -214,7 +214,7 @@ public void RemoveLocalConnection() NetworkServer.Listen(1); // set local connection - CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient, out _); + Utils.CreateLocalConnections(out LocalConnectionToClient connectionToClient, out _); NetworkServer.SetLocalConnection(connectionToClient); // remove local connection @@ -1221,7 +1221,7 @@ public void HasExternalConnections_WithConnections() [Test] public void HasExternalConnections_WithHostOnly() { - CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient, out _); + Utils.CreateLocalConnections(out LocalConnectionToClient connectionToClient, out _); NetworkServer.SetLocalConnection(connectionToClient); NetworkServer.connections.Add(0, connectionToClient); @@ -1235,7 +1235,7 @@ public void HasExternalConnections_WithHostOnly() [Test] public void HasExternalConnections_WithHostAndConnection() { - CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient, out _); + Utils.CreateLocalConnections(out LocalConnectionToClient connectionToClient, out _); NetworkServer.SetLocalConnection(connectionToClient); NetworkServer.connections.Add(0, connectionToClient);