HostMode.cs - to move host mode connection setup out of NetworkClient

This commit is contained in:
vis2k 2022-12-12 14:13:31 +01:00
parent ca3bfed93a
commit def22c864d
3 changed files with 28 additions and 17 deletions

View File

@ -0,0 +1,24 @@
// host mode related helper functions.
// usually they set up both server & client.
// it's cleaner to keep them in one place, instead of only in server / client.
namespace Mirror
{
internal static class HostMode
{
// keep the local connections setup in one function.
// makes host setup easier to follow.
internal static void SetupConnections()
{
// create local connections pair, both are connected
Utils.CreateLocalConnections(
out LocalConnectionToClient connectionToClient,
out LocalConnectionToServer connectionToServer);
// set client connection
NetworkClient.connection = connectionToServer;
// set server connection
NetworkServer.SetLocalConnection(connectionToClient);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d27175a08d5341fc97645b49ee533d5a
timeCreated: 1670849982

View File

@ -212,29 +212,13 @@ public static void Connect(Uri uri)
connection = new NetworkConnectionToServer();
}
// keep the local connections setup in one function.
// makes host setup easier to follow.
// TODO this doesn't need to be in NetworkClient. it sets up both cl/sv.
internal static void SetupHostConnections()
{
// create local connections pair, both are connected
Utils.CreateLocalConnections(
out LocalConnectionToClient connectionToClient,
out LocalConnectionToServer connectionToServer);
connection = connectionToServer;
// create server connection to local client
NetworkServer.SetLocalConnection(connectionToClient);
}
// TODO why are there two connect host methods?
// called from NetworkManager.FinishStartHost()
public static void ConnectHost()
{
Initialize(true);
connectState = ConnectState.Connected;
SetupHostConnections();
HostMode.SetupConnections();
}
/// <summary>Connect host mode</summary>