public void AddNewClient(SOEClient newClient) { // Do they exist already? if (SessionID2ClientID.ContainsKey(newClient.GetSessionID())) { // Disconnect the new client Log("[WARNING] Someone tried connecting with the same Session ID!"); newClient.Disconnect((ushort)SOEDisconnectReasons.ConnectFail); // Don't continue adding this connection return; } // Is there already a connection from this endpoint? if (Host2ClientID.ContainsKey(newClient.Client)) { // Disconnect the new client Log("[WARNING] Someone tried connecting from the same endpoint!"); newClient.Disconnect((ushort)SOEDisconnectReasons.ConnectFail); // Don't continue adding this connection return; } // Loop through the Clients list, looking for an open space int newClientId; for (newClientId = 0; newClientId < Clients.Count; newClientId++) { // Is this client nulled? if (Clients[newClientId] == null) { // We've found an empty space! break; } } // Set their Client ID newClient.SetClientID(newClientId); // Add them to the Clients map if (newClientId >= Clients.Count) { Clients.Add(newClient); } else { Clients[newClientId] = newClient; } // Add them to our maps Host2ClientID.Add(newClient.Client, newClientId); SessionID2ClientID.Add(newClient.GetSessionID(), newClientId); // Log Log("New client connection from {0}, (ID: {1})", newClient.GetClientAddress(), newClient.GetClientID()); }