Skip to content

Commit fae38de

Browse files
committed
Changed ConnectedClients API to a list
1 parent 7dcd8c9 commit fae38de

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using MLAPI.Data;
88
using MLAPI.NetworkingManagerComponents.Binary;
99
using MLAPI.NetworkingManagerComponents.Core;
10-
using System.Collections;
1110

1211
namespace MLAPI.MonoBehaviours.Core
1312
{

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ public uint MyClientId
6666
}
6767
internal uint myClientId;
6868
internal readonly Dictionary<uint, NetworkedClient> connectedClients = new Dictionary<uint, NetworkedClient>();
69+
internal readonly List<NetworkedClient> connectedClientsList = new List<NetworkedClient>();
6970
/// <summary>
70-
/// Gets a dictionary of connected clients
71+
/// Gets a list of connected clients
7172
/// </summary>
72-
public Dictionary<uint, NetworkedClient> ConnectedClients
73+
public List<NetworkedClient> ConnectedClients
7374
{
7475
get
7576
{
76-
return connectedClients;
77+
return connectedClientsList;
7778
}
7879
}
7980
internal readonly HashSet<uint> pendingClients = new HashSet<uint>();
@@ -222,6 +223,7 @@ private object Init(bool server)
222223
eventOvershootCounter = 0f;
223224
pendingClients.Clear();
224225
connectedClients.Clear();
226+
connectedClientsList.Clear();
225227
messageBuffer = new byte[NetworkConfig.MessageBufferSize];
226228
diffieHellmanPublicKeys.Clear();
227229
Data.Cache.messageAttributeHashes.Clear();
@@ -607,6 +609,7 @@ public void StartHost(Vector3? pos = null, Quaternion? rot = null)
607609
{
608610
ClientId = hostClientId
609611
});
612+
connectedClientsList.Add(connectedClients[hostClientId]);
610613

611614
if (NetworkConfig.HandleObjectSpawning)
612615
{
@@ -996,6 +999,8 @@ internal void DisconnectClient(uint clientId)
996999

9971000
if (connectedClients.ContainsKey(clientId))
9981001
connectedClients.Remove(clientId);
1002+
1003+
connectedClientsList.RemoveAll(x => x.ClientId == clientId); // :(
9991004

10001005
if (diffieHellmanPublicKeys.ContainsKey(clientId))
10011006
diffieHellmanPublicKeys.Remove(clientId);
@@ -1022,6 +1027,7 @@ internal void OnClientDisconnect(uint clientId)
10221027
Destroy(connectedClients[clientId].OwnedObjects[i].gameObject);
10231028
}
10241029
}
1030+
connectedClientsList.RemoveAll(x => x.ClientId == clientId);
10251031
connectedClients.Remove(clientId);
10261032
}
10271033

@@ -1087,6 +1093,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
10871093
AesKey = aesKey
10881094
};
10891095
connectedClients.Add(clientId, client);
1096+
connectedClientsList.Add(client);
10901097

10911098
if(NetworkConfig.HandleObjectSpawning)
10921099
{

MLAPI/NetworkingManagerComponents/Core/InternalMessageHandler.Receive.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ internal static void HandleConnectionApproved(uint clientId, BitReader reader, i
7777
{
7878
uint _clientId = reader.ReadUInt();
7979
netManager.connectedClients.Add(_clientId, new NetworkedClient() { ClientId = _clientId });
80+
netManager.connectedClientsList.Add(netManager.connectedClients[_clientId]);
8081
}
8182
if (netManager.NetworkConfig.HandleObjectSpawning)
8283
{
@@ -149,6 +150,7 @@ internal static void HandleAddObject(uint clientId, BitReader reader, int channe
149150
if (isPlayerObject)
150151
{
151152
netManager.connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId });
153+
netManager.connectedClientsList.Add(netManager.connectedClients[ownerId]);
152154
GameObject go = SpawnManager.SpawnPlayerObject(ownerId, networkId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot), reader);
153155
go.GetComponent<NetworkedObject>().SetLocalVisibility(visible);
154156
}
@@ -337,6 +339,7 @@ internal static void HandleAddObjects(uint clientId, BitReader reader, int chann
337339
if (isPlayerObject)
338340
{
339341
netManager.connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId });
342+
netManager.connectedClientsList.Add(netManager.connectedClients[ownerId]);
340343
GameObject go = SpawnManager.SpawnPlayerObject(ownerId, networkId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot), reader);
341344

342345
go.GetComponent<NetworkedObject>().SetLocalVisibility(visible);

0 commit comments

Comments
 (0)