fCraft.IPBanList.Add C# (CSharp) Method

Add() public static method

Adds a new IP Ban.
public static Add ( [ ban, bool raiseEvent ) : bool
ban [ Ban information
raiseEvent bool Whether AddingIPBan and AddedIPBan events should be raised.
return bool
        public static bool Add( [NotNull] IPBanInfo ban, bool raiseEvent )
        {
            if ( ban == null )
                throw new ArgumentNullException( "ban" );
            lock ( BanListLock ) {
                if ( Bans.ContainsKey( ban.Address.ToString() ) )
                    return false;
                if ( raiseEvent ) {
                    if ( RaiseAddingIPBanEvent( ban ) )
                        return false;
                    Bans.Add( ban.Address.ToString(), ban );
                    RaiseAddedIPBanEvent( ban );
                } else {
                    Bans.Add( ban.Address.ToString(), ban );
                }
                Save();
                return true;
            }
        }

Usage Example

Example #1
0
 internal static void RecoverIPBans()
 {
     PlayerInfo[] playerInfoListCache = PlayerInfoList;
     for (int i = 0; i < playerInfoListCache.Length; i++)
     {
         PlayerInfo p = playerInfoListCache[i];
         if (p.Banned && p.BanReason.EndsWith("~BanAll", StringComparison.OrdinalIgnoreCase) && IPBanList.Get(p.LastIP) == null)
         {
             IPBanList.Add(new IPBanInfo(p.LastIP, p.Name, p.BannedBy, p.BanReason));
             Logger.Log("PlayerDB.RecoverIPBans: Banned {0} by association with {1}. Banned by {2}. Reason: {3}", LogType.SystemActivity,
                        p.LastIP, p.Name, p.BannedBy, p.BanReason);
         }
     }
 }