From 619d5f47e3d880739009c774ffdc8b8131c5bc0f Mon Sep 17 00:00:00 2001 From: vis2k Date: Tue, 26 Feb 2019 17:08:10 +0100 Subject: [PATCH] Remove hostId from NetworkServer and NetworkConnection because it was only needed for the old LLAPI. Also added comment for NetworkConnection.isConnected which can be removed later. --- Assets/Mirror/Runtime/NetworkClient.cs | 2 +- Assets/Mirror/Runtime/NetworkConnection.cs | 19 +++++++++---------- Assets/Mirror/Runtime/NetworkServer.cs | 14 +++++--------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkClient.cs b/Assets/Mirror/Runtime/NetworkClient.cs index 491718580..d41204e76 100644 --- a/Assets/Mirror/Runtime/NetworkClient.cs +++ b/Assets/Mirror/Runtime/NetworkClient.cs @@ -59,7 +59,7 @@ public void Connect(string ip) NetworkManager.singleton.transport.ClientConnect(ip); // setup all the handlers - connection = new NetworkConnection(serverIp, 0, 0); + connection = new NetworkConnection(serverIp, 0); connection.SetHandlers(handlers); } diff --git a/Assets/Mirror/Runtime/NetworkConnection.cs b/Assets/Mirror/Runtime/NetworkConnection.cs index 94cfe45db..bf359f554 100644 --- a/Assets/Mirror/Runtime/NetworkConnection.cs +++ b/Assets/Mirror/Runtime/NetworkConnection.cs @@ -11,7 +11,6 @@ public class NetworkConnection : IDisposable Dictionary m_MessageHandlers; - public int hostId = -1; public int connectionId = -1; public bool isReady; public string address; @@ -19,17 +18,20 @@ public class NetworkConnection : IDisposable public NetworkIdentity playerController => m_PlayerController; public HashSet clientOwnedObjects; public bool logNetworkMessages; - public bool isConnected => hostId != -1; + + // this is always true for regular connections, false for local + // connections because it's set in the constructor and never reset. + public bool isConnected { get; protected set; } public NetworkConnection(string networkAddress) { address = networkAddress; } - public NetworkConnection(string networkAddress, int networkHostId, int networkConnectionId) + public NetworkConnection(string networkAddress, int networkConnectionId) { address = networkAddress; - hostId = networkHostId; connectionId = networkConnectionId; + isConnected = true; } ~NetworkConnection() @@ -82,11 +84,8 @@ public void Disconnect() NetworkManager.singleton.transport.ServerDisconnect(connectionId); } - // remove observers. original HLAPI has hostId check for that too. - if (hostId != -1) - { - RemoveObservers(); - } + // remove observers + RemoveObservers(); } internal void SetHandlers(Dictionary handlers) @@ -149,7 +148,7 @@ internal virtual bool SendBytes( byte[] bytes, int channelId = Channels.DefaultR public override string ToString() { - return string.Format("hostId: {0} connectionId: {1} isReady: {2}", hostId, connectionId, isReady); + return string.Format("connectionId: {0} isReady: {1}", connectionId, isReady); } internal void AddToVisList(NetworkIdentity identity) diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index c1dcc1774..49d2ede03 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -17,8 +17,6 @@ public static class NetworkServer // => removed it for easier code. use .localConection now! public static NetworkConnection localConnection => s_LocalConnection; - public static int serverHostId { get; private set; } = -1; - // public static Dictionary connections = new Dictionary(); public static Dictionary handlers = new Dictionary(); @@ -46,7 +44,6 @@ public static void Shutdown() else { NetworkManager.singleton.transport.ServerStop(); - serverHostId = -1; } NetworkManager.singleton.transport.OnServerDisconnected.RemoveListener(OnDisconnected); @@ -94,7 +91,6 @@ public static bool Listen(int maxConnections) if (!dontListen) { NetworkManager.singleton.transport.ServerStart(); - serverHostId = 0; // so it doesn't return false if (LogFilter.Debug) { Debug.Log("Server started listening"); } } @@ -278,10 +274,10 @@ static void UpdateServerObjects() // The user should never need to pump the update loop manually internal static void Update() { - if (serverHostId == -1) - return; - - UpdateServerObjects(); + if (active) + { + UpdateServerObjects(); + } } static void OnConnected(int connectionId) @@ -315,7 +311,7 @@ static void OnConnected(int connectionId) string address = NetworkManager.singleton.transport.ServerGetClientAddress(connectionId); // add player info - NetworkConnection conn = new NetworkConnection(address, serverHostId, connectionId); + NetworkConnection conn = new NetworkConnection(address, connectionId); OnConnected(conn); } else