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()); }
public void StartKeepAliveThread() { Thread keepAliveThread = new Thread((threadStart3) => { while (Server.Running) { // Get a Now time for this cycle int now = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; // Loop through the clients for (int i = 0; i < Clients.Count; i++) { // Client SOEClient client = GetClient(i); // Empty space? if (client == null) { continue; } // Idle? if (now > (client.GetLastInteraction() + Server.CLIENT_TIMEOUT)) { Log("Disconnecting Idle client."); client.Disconnect((ushort)SOEDisconnectReasons.Timeout); } } Thread.Sleep(Server.SERVER_THREAD_SLEEP); } }); keepAliveThread.Name = "SOEServer::KeepAliveThread"; keepAliveThread.Start(); }