diff --git a/QuantumUNET/Components/QNetworkIdentity.cs b/QuantumUNET/Components/QNetworkIdentity.cs index 83d10b32..069e6531 100644 --- a/QuantumUNET/Components/QNetworkIdentity.cs +++ b/QuantumUNET/Components/QNetworkIdentity.cs @@ -631,14 +631,12 @@ namespace QuantumUNET.Components } } - foreach (var networkConnection2 in QNetworkServer.localConnections) + var networkConnection2 = QNetworkServer.localConnection; + if (networkConnection2 != null) { - if (networkConnection2 != null) + if (networkConnection2.isReady) { - if (networkConnection2.isReady) - { - AddObserver(networkConnection2); - } + AddObserver(networkConnection2); } } } @@ -674,12 +672,10 @@ namespace QuantumUNET.Components if (initialize) { - foreach (var connection in QNetworkServer.localConnections) + var connection = QNetworkServer.localConnection; + if (!hashSet.Contains(connection)) { - if (!hashSet.Contains(connection)) - { - OnSetLocalVisibility(false); - } + OnSetLocalVisibility(false); } } diff --git a/QuantumUNET/QLocalClient.cs b/QuantumUNET/QLocalClient.cs index 63882036..9d230abf 100644 --- a/QuantumUNET/QLocalClient.cs +++ b/QuantumUNET/QLocalClient.cs @@ -17,7 +17,7 @@ namespace QuantumUNET } m_AsyncConnect = ConnectState.Disconnected; - m_LocalServer.RemoveLocalClient(m_Connection); + m_LocalServer.RemoveLocalClient(); } internal void InternalConnectLocalServer(bool generateConnectMsg) diff --git a/QuantumUNET/QNetworkServer.cs b/QuantumUNET/QNetworkServer.cs index 417de46a..8d7c7ff0 100644 --- a/QuantumUNET/QNetworkServer.cs +++ b/QuantumUNET/QNetworkServer.cs @@ -22,7 +22,7 @@ namespace QuantumUNET m_SimpleServerSimple = new ServerSimpleWrapper(this); } - public static List localConnections => instance.m_LocalConnectionsFakeList; + public static QNetworkConnection localConnection => instance.m_LocalConnection; public static int listenPort => instance.m_SimpleServerSimple.listenPort; @@ -151,7 +151,7 @@ namespace QuantumUNET internal int AddLocalClient(QLocalClient localClient) { int result; - if (m_LocalConnectionsFakeList.Count != 0) + if (m_LocalConnection != null) { QLog.Error("Local Connection already exists"); result = -1; @@ -163,7 +163,6 @@ namespace QuantumUNET connectionId = 0 }; m_SimpleServerSimple.SetConnectionAtIndex(m_LocalConnection); - m_LocalConnectionsFakeList.Add(m_LocalConnection); m_LocalConnection.InvokeHandlerNoData(32); result = 0; } @@ -171,17 +170,8 @@ namespace QuantumUNET return result; } - internal void RemoveLocalClient(QNetworkConnection localClientConnection) + internal void RemoveLocalClient() { - for (var i = 0; i < m_LocalConnectionsFakeList.Count; i++) - { - if (m_LocalConnectionsFakeList[i].connectionId == localClientConnection.connectionId) - { - m_LocalConnectionsFakeList.RemoveAt(i); - break; - } - } - if (m_LocalConnection != null) { m_LocalConnection.Disconnect(); @@ -1351,8 +1341,6 @@ namespace QuantumUNET private bool m_LocalClientActive; - private readonly List m_LocalConnectionsFakeList = new(); - private QULocalConnectionToClient m_LocalConnection; private readonly QNetworkScene m_NetworkScene;