/// <summary> /// Tries to remove a ban from an account. /// </summary> /// <param name="accountID">The account to remove the ban from.</param> /// <param name="issuedBy">The name of the user or source that issued the unban.</param> /// <param name="failReason">When this method returns false, contains the reason why the unban failed to be added.</param> /// <returns> /// True if the unban was successfully added; otherwise false. /// </returns> public bool TryRemoveAccountBan(TAccountID accountID, string issuedBy, out BanManagerFailReason failReason) { // Check the parameters if (string.IsNullOrEmpty(issuedBy)) { failReason = BanManagerFailReason.NoIssuerProvided; if (log.IsInfoEnabled) { log.InfoFormat("Failed to unban account `{0}`: {1}", accountID, failReason.GetDetailedString()); } return(false); } // Try to remove the ban try { if (!TryRemoveBanInternal(accountID, issuedBy, out failReason)) { if (log.IsInfoEnabled) { log.InfoFormat("Failed to unban account `{0}`: {1}", accountID, failReason.GetDetailedString()); } return(false); } } catch (Exception ex) { failReason = BanManagerFailReason.ExceptionOccured; if (log.IsInfoEnabled) { log.InfoFormat("Failed to unban account `{0}`: {1}. Exception: {2}", accountID, failReason.GetDetailedString(), ex); } return(false); } // Raise the event OnAccountUnBanned(accountID); if (AccountUnBanned != null) { AccountUnBanned.Raise(this, BanningManagerAccountUnBannedEventArgs.Create(accountID, issuedBy)); } if (log.IsInfoEnabled) { log.InfoFormat("Successfully unbanned account `{0}` (issuedBy: {1}).", accountID, issuedBy); } failReason = BanManagerFailReason.Unknown; return(true); }
/// <summary> /// Tries to remove a ban from an account by specifying the user's name. /// </summary> /// <param name="userName">The name of the user to unban.</param> /// <param name="issuedBy">The name of the user or source that issued the unban.</param> /// <param name="failReason">When this method returns false, contains the reason why the ban failed to be removed.</param> /// <returns> /// True if the ban was successfully removed; otherwise false. /// </returns> public bool TryRemoveUserBan(string userName, string issuedBy, out BanManagerFailReason failReason) { // Get the account ID TAccountID accountID; if (!TryGetAccountIDFromUserName(userName, out accountID)) { const string errmsg = "Failed to unban user `{0}`: {1}"; failReason = BanManagerFailReason.InvalidUser; if (log.IsInfoEnabled) { log.InfoFormat(errmsg, userName, failReason.GetDetailedString()); } return(false); } // UnBan the account by ID return(TryRemoveAccountBan(accountID, issuedBy, out failReason)); }
/// <summary> /// Tries to add a ban to an account. /// </summary> /// <param name="accountName">The name of the account to ban.</param> /// <param name="length">How long the ban will last.</param> /// <param name="reason">The reason for the ban.</param> /// <param name="issuedBy">The name of the user or source that issued the ban.</param> /// <param name="failReason">When this method returns false, contains the reason why the ban failed to be added.</param> /// <returns> /// True if the ban was successfully added; otherwise false. /// </returns> public bool TryAddAccountBan(string accountName, TimeSpan length, string reason, string issuedBy, out BanManagerFailReason failReason) { // Get the account ID TAccountID accountID; if (!TryGetAccountIDFromAccountName(accountName, out accountID)) { const string errmsg = "Failed to ban account `{0}`: {1}"; failReason = BanManagerFailReason.InvalidAccount; if (log.IsInfoEnabled) { log.InfoFormat(errmsg, accountName, failReason.GetDetailedString()); } return(false); } // Ban the account by ID return(TryAddAccountBan(accountID, length, reason, issuedBy, out failReason)); }
/// <summary> /// Tries to add a ban to an account. /// </summary> /// <param name="accountID">The account to add the ban to.</param> /// <param name="length">How long the ban will last.</param> /// <param name="reason">The reason for the ban.</param> /// <param name="issuedBy">The name of the user or source that issued the ban.</param> /// <param name="failReason">When this method returns false, contains the reason why the ban failed to be added.</param> /// <returns> /// True if the ban was successfully added; otherwise false. /// </returns> public bool TryAddAccountBan(TAccountID accountID, TimeSpan length, string reason, string issuedBy, out BanManagerFailReason failReason) { // Check the parameters if (length.TotalMilliseconds < 0) { failReason = BanManagerFailReason.NegativeBanDuration; if (log.IsInfoEnabled) { log.InfoFormat("Failed to ban account `{0}`: {1}", accountID, failReason.GetDetailedString()); } return(false); } if (string.IsNullOrEmpty(reason)) { failReason = BanManagerFailReason.NoReasonProvided; if (log.IsInfoEnabled) { log.InfoFormat("Failed to ban account `{0}`: {1}", accountID, failReason.GetDetailedString()); } return(false); } if (string.IsNullOrEmpty(issuedBy)) { failReason = BanManagerFailReason.NoIssuerProvided; if (log.IsInfoEnabled) { log.InfoFormat("Failed to ban account `{0}`: {1}", accountID, failReason.GetDetailedString()); } return(false); } // Try to add the ban try { if (!TryAddBanInternal(accountID, length, reason, issuedBy, out failReason)) { if (log.IsInfoEnabled) { log.InfoFormat("Failed to ban account `{0}`: {1}", accountID, failReason.GetDetailedString()); } return(false); } } catch (Exception ex) { failReason = BanManagerFailReason.ExceptionOccured; if (log.IsInfoEnabled) { log.InfoFormat("Failed to ban account `{0}`: {1}. Exception: {2}", accountID, failReason.GetDetailedString(), ex); } return(false); } // Raise the event OnAccountBanned(accountID); if (AccountBanned != null) { AccountBanned.Raise(this, BanningManagerAccountBannedEventArgs.Create(accountID, length, reason, issuedBy)); } if (log.IsInfoEnabled) { log.InfoFormat("Successfully banned account `{0}` (length: {1}; reason: {2}; issuedBy: {3}).", accountID, length, reason, issuedBy); } failReason = BanManagerFailReason.Unknown; return(true); }