예제 #1
0
        public static PlayerInfo[] FindPlayersCidr([NotNull] IPAddress address, byte range, int limit)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            if (range > 32)
            {
                throw new ArgumentOutOfRangeException("range");
            }
            if (limit < 0)
            {
                throw new ArgumentOutOfRangeException("limit");
            }
            CheckIfLoaded();
            List <PlayerInfo> result = new List <PlayerInfo>();
            int  count      = 0;
            uint addressInt = address.AsUInt();
            uint netMask    = IPAddressUtil.NetMask(range);

            PlayerInfo[] cache = PlayerInfoList;
            for (int i = 0; i < cache.Length; i++)
            {
                if (cache[i].LastIP.Match(addressInt, netMask))
                {
                    result.Add(cache[i]);
                    count++;
                    if (count >= limit)
                    {
                        return(result.ToArray());
                    }
                }
            }
            return(result.ToArray());
        }
예제 #2
0
        public static bool Match([NotNull] this IPAddress thisAddr, uint otherAddr, uint mask)
        {
            if (thisAddr == null)
            {
                throw new ArgumentNullException("thisAddr");
            }
            uint thisAsUInt = thisAddr.AsUInt();

            return((thisAsUInt & mask) == (otherAddr & mask));
        }