/// <summary> /// Looks for clients that are connected but not doing anything and removes them. /// </summary> private void CheckForSolicitors() { for (int i = 0; i < clients.Count; i++) { if (clients[i].ConnectionTime != null && clients[i].LoggedInTime == null) { TimeSpan span = DateTime.Now - clients[i].ConnectionTime.Value; // If client has connected, but hasn't logged in within 3 seconds // then refuse the client. if (span.TotalMilliseconds > solicitorThreshold) { const ConnectionRefusedReason REASON = ConnectionRefusedReason.NoLogin; var content = new ConnectionRefusedContent(REASON, clients[i].Name); clients[i].SendPackageAsync((int)BaseCommand.ConnectionRefused, content); OnConnectionRefused(content); clientNames.Remove(clients[i].Name); clients[i].Dispose(); clients.RemoveAt(i); i--; if (clients.Count == 0) { break; } } } } }
/// <summary> /// Initializes a new instance of the <see cref="ConnectionRefusedContent"/> class /// with the specified arguments. /// </summary> /// <param name="reason">The reason in which the indicated client has been refused.</param> /// <param name="clientName">The name of the client that has been refused.</param> public ConnectionRefusedContent(ConnectionRefusedReason reason, string clientName) { Reason = reason; ClientName = clientName; }