Utils.CreateLocalConnections for use from NetworkClient.ConnectHost & Tests

This commit is contained in:
vis2k 2022-12-12 13:37:41 +01:00
parent 65c73bd158
commit d406a55e49
6 changed files with 20 additions and 19 deletions

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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

View File

@ -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);