mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Utils.CreateLocalConnections for use from NetworkClient.ConnectHost & Tests
This commit is contained in:
parent
65c73bd158
commit
d406a55e49
@ -220,11 +220,10 @@ public static void ConnectHost()
|
|||||||
|
|
||||||
connectState = ConnectState.Connected;
|
connectState = ConnectState.Connected;
|
||||||
|
|
||||||
// create local connection objects and connect them
|
// create local connections pair, both are connected
|
||||||
LocalConnectionToServer connectionToServer = new LocalConnectionToServer();
|
Utils.CreateLocalConnections(
|
||||||
LocalConnectionToClient connectionToClient = new LocalConnectionToClient();
|
out LocalConnectionToClient connectionToClient,
|
||||||
connectionToServer.connectionToClient = connectionToClient;
|
out LocalConnectionToServer connectionToServer);
|
||||||
connectionToClient.connectionToServer = connectionToServer;
|
|
||||||
|
|
||||||
connection = connectionToServer;
|
connection = connectionToServer;
|
||||||
|
|
||||||
|
@ -166,5 +166,16 @@ public static Rect KeepInScreen(Rect rect)
|
|||||||
|
|
||||||
return 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -654,14 +654,5 @@ protected void ProcessMessages()
|
|||||||
// update transport so sent messages are received
|
// update transport so sent messages are received
|
||||||
UpdateTransport();
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public override void SetUp()
|
|||||||
{
|
{
|
||||||
base.SetUp();
|
base.SetUp();
|
||||||
|
|
||||||
CreateLocalConnectionPair(out connectionToClient, out connectionToServer);
|
Utils.CreateLocalConnections(out connectionToClient, out connectionToServer);
|
||||||
|
|
||||||
// set up server/client connections so message handling works
|
// set up server/client connections so message handling works
|
||||||
NetworkClient.connection = connectionToServer;
|
NetworkClient.connection = connectionToServer;
|
||||||
|
@ -527,7 +527,7 @@ public void AssignAndRemoveClientAuthority()
|
|||||||
};
|
};
|
||||||
|
|
||||||
// create connections
|
// create connections
|
||||||
CreateLocalConnectionPair(out LocalConnectionToClient owner, out LocalConnectionToServer clientConnection);
|
Utils.CreateLocalConnections(out LocalConnectionToClient owner, out LocalConnectionToServer clientConnection);
|
||||||
owner.isReady = true;
|
owner.isReady = true;
|
||||||
|
|
||||||
// setup NetworkServer/Client connections so messages are handled
|
// setup NetworkServer/Client connections so messages are handled
|
||||||
|
@ -214,7 +214,7 @@ public void RemoveLocalConnection()
|
|||||||
NetworkServer.Listen(1);
|
NetworkServer.Listen(1);
|
||||||
|
|
||||||
// set local connection
|
// set local connection
|
||||||
CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient, out _);
|
Utils.CreateLocalConnections(out LocalConnectionToClient connectionToClient, out _);
|
||||||
NetworkServer.SetLocalConnection(connectionToClient);
|
NetworkServer.SetLocalConnection(connectionToClient);
|
||||||
|
|
||||||
// remove local connection
|
// remove local connection
|
||||||
@ -1221,7 +1221,7 @@ public void HasExternalConnections_WithConnections()
|
|||||||
[Test]
|
[Test]
|
||||||
public void HasExternalConnections_WithHostOnly()
|
public void HasExternalConnections_WithHostOnly()
|
||||||
{
|
{
|
||||||
CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient, out _);
|
Utils.CreateLocalConnections(out LocalConnectionToClient connectionToClient, out _);
|
||||||
|
|
||||||
NetworkServer.SetLocalConnection(connectionToClient);
|
NetworkServer.SetLocalConnection(connectionToClient);
|
||||||
NetworkServer.connections.Add(0, connectionToClient);
|
NetworkServer.connections.Add(0, connectionToClient);
|
||||||
@ -1235,7 +1235,7 @@ public void HasExternalConnections_WithHostOnly()
|
|||||||
[Test]
|
[Test]
|
||||||
public void HasExternalConnections_WithHostAndConnection()
|
public void HasExternalConnections_WithHostAndConnection()
|
||||||
{
|
{
|
||||||
CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient, out _);
|
Utils.CreateLocalConnections(out LocalConnectionToClient connectionToClient, out _);
|
||||||
|
|
||||||
NetworkServer.SetLocalConnection(connectionToClient);
|
NetworkServer.SetLocalConnection(connectionToClient);
|
||||||
NetworkServer.connections.Add(0, connectionToClient);
|
NetworkServer.connections.Add(0, connectionToClient);
|
||||||
|
Loading…
Reference in New Issue
Block a user