/// <summary> /// Called when the given client failed to login due to the given reason. /// Delays, fires the LoginFailed event and sends the reply. /// </summary> /// <param name="client"></param> /// <param name="error"></param> public static void OnLoginError(IAuthClient client, AccountStatus error, bool silent) { if (!silent) { s_log.Debug("Client {0} failed to login: {1}", client, error); } LoginFailInfo failInfo; if (!failedLogins.TryGetValue(client.ClientAddress, out failInfo)) { failedLogins.Add(client.ClientAddress, failInfo = new LoginFailInfo(DateTime.Now)); } else { failInfo.LastAttempt = DateTime.Now; failInfo.Count++; // TODO: Ban, if trying too often? } // delay the reply ThreadPool.RegisterWaitForSingleObject(failInfo.Handle, (state, timedOut) => { if (client.IsConnected) { var evt = LoginFailed; if (evt != null) { evt(client, error); } SendAuthProofErrorReply(client, error); } }, null, FailedLoginDelay, true); }