fix: Call hooks when initializing objects OnStartServer on host (#1249)

This commit is contained in:
Paul Pacheco 2019-11-29 00:12:06 -06:00 committed by vis2k
parent 7119dd15f8
commit 7aa7815754
3 changed files with 14 additions and 16 deletions

View File

@ -90,10 +90,7 @@ public static void Connect(string address)
connection.SetHandlers(handlers);
}
/// <summary>
/// connect host mode
/// </summary>
internal static void ConnectLocalServer()
internal static void SetupLocalConnection()
{
if (LogFilter.Debug) Debug.Log("Client Connect Local Server");
@ -112,7 +109,15 @@ internal static void ConnectLocalServer()
// create server connection to local client
NetworkServer.SetLocalConnection(connectionToClient);
connectionToClient.Send(new ConnectMessage());
}
/// <summary>
/// connect host mode
/// </summary>
internal static void ConnectLocalServer()
{
NetworkServer.OnConnected(NetworkServer.localConnection);
NetworkServer.localConnection.Send(new ConnectMessage());
}
/// <summary>

View File

@ -360,6 +360,7 @@ public void StartClient()
public virtual void StartHost()
{
OnStartHost();
NetworkClient.SetupLocalConnection();
if (StartServer())
{
ConnectLocalClient();
@ -530,8 +531,8 @@ void ConnectLocalClient()
networkAddress = "localhost";
NetworkServer.ActivateLocalClientScene();
NetworkClient.ConnectLocalServer();
RegisterClientMessages();
NetworkClient.ConnectLocalServer();
}
void RegisterClientMessages()

View File

@ -55,7 +55,7 @@ public static class NetworkServer
/// <para>True is a local client is currently active on the server.</para>
/// <para>This will be true for "Hosts" on hosted server games.</para>
/// </summary>
public static bool localClientActive { get; private set; }
public static bool localClientActive => localConnection != null;
// cache the Send(connectionIds) list to avoid allocating each time
static readonly List<int> connectionIdsCache = new List<int>();
@ -185,7 +185,6 @@ internal static void SetLocalConnection(ULocalConnectionToClient conn)
}
localConnection = conn;
OnConnected(localConnection);
}
internal static void RemoveLocalConnection()
@ -195,17 +194,11 @@ internal static void RemoveLocalConnection()
localConnection.Disconnect();
localConnection = null;
}
localClientActive = false;
RemoveConnection(0);
}
internal static void ActivateLocalClientScene()
{
if (localClientActive)
return;
// ClientScene for a local connection is becoming active. any spawned objects need to be started as client objects
localClientActive = true;
foreach (NetworkIdentity identity in NetworkIdentity.spawned.Values)
{
if (!identity.isClient)
@ -432,7 +425,6 @@ public static void DisconnectAll()
localConnection = null;
active = false;
localClientActive = false;
}
/// <summary>
@ -512,7 +504,7 @@ static void OnConnected(int connectionId)
}
}
static void OnConnected(NetworkConnectionToClient conn)
internal static void OnConnected(NetworkConnectionToClient conn)
{
if (LogFilter.Debug) Debug.Log("Server accepted client:" + conn);