예제 #1
0
        private static void EventSink_SocketConnect(SocketConnectEventArgs e)
        {
            try
            {
                IPAddress ip = ((IPEndPoint)e.Socket.RemoteEndPoint).Address;

                if (Firewall.IsBlocked(ip))
                {
                    Console.WriteLine("Client: {0}: Firewall blocked connection attempt.", ip);
                    e.AllowConnection = false;
                    return;
                }
                else if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip))
                {
                    Console.WriteLine("Client: {0}: Past IP limit threshold", ip);

                    using (StreamWriter op = new StreamWriter("ipLimits.log", true))
                        op.WriteLine("{0}\tPast IP limit threshold\t{1}", ip, DateTime.UtcNow);

                    e.AllowConnection = false;
                    return;
                }
            }
            catch
            {
                e.AllowConnection = false;
            }
        }
예제 #2
0
		public bool HasAccess( IPAddress ipAddress ) {
			AccessLevel level = Misc.AccountHandler.LockdownLevel;

			if ( level > AccessLevel.Player )
			{
				bool hasAccess = false;

				if ( m_AccessLevel >= level )
				{
					hasAccess = true;
				}
				else
				{
					for ( int i = 0; !hasAccess && i < this.Length; ++i )
					{
						Mobile m = this[i];

						if ( m != null && m.AccessLevel >= level )
							hasAccess = true;
					}
				}

				if ( !hasAccess )
					return false;
			}

			bool accessAllowed = ( m_IPRestrictions.Length == 0 || IPLimiter.IsExempt( ipAddress ) );

			for ( int i = 0; !accessAllowed && i < m_IPRestrictions.Length; ++i )
				accessAllowed = Utility.IPMatch( m_IPRestrictions[i], ipAddress );

			return accessAllowed;
		}
예제 #3
0
        private static void EventSink_SocketConnect(SocketConnectEventArgs e)
        {
            try
            {
                var ip = (e.Connection.RemoteEndPoint as IPEndPoint)?.Address;

                if (Firewall.IsBlocked(ip))
                {
                    logger.Information("Client: {IP}: Firewall blocked connection attempt.", ip);
                    e.AllowConnection = false;
                    return;
                }

                if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip))
                {
                    logger.Warning("Client: {IP}: Past IP limit threshold", ip);

                    using (var op = new StreamWriter("ipLimits.log", true))
                    {
                        op.WriteLine("{0}\tPast IP limit threshold\t{1}", ip, Core.Now);
                    }

                    e.AllowConnection = false;
                }
            }
            catch
            {
                e.AllowConnection = false;
            }
        }
예제 #4
0
        private static void EventSink_SocketConnect(SocketConnectEventArgs e)
        {
            try
            {
                IPAddress ip = ((IPEndPoint)e.Socket.RemoteEndPoint).Address;

                if (Firewall.IsBlocked(ip))
                {
                    Utility.PushColor(ConsoleColor.Red);
                    Console.WriteLine("Client: {0}: Firewall blocked connection attempt.", ip);
                    Utility.PopColor();
                    e.AllowConnection = false;
                    return;
                }
                else if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip))
                {
                    Utility.PushColor(ConsoleColor.Red);
                    Console.WriteLine("Client: {0}: Past IP limit threshold", ip);
                    Utility.PopColor();

                    using (StreamWriter op = new StreamWriter("ipLimits.log", true))
                        op.WriteLine("{0}\tPast IP limit threshold\t{1}", ip, DateTime.UtcNow);

                    e.AllowConnection = false;
                    return;
                }
            }
            catch (Exception ex)
            {
                Diagnostics.ExceptionLogging.LogException(ex);
                e.AllowConnection = false;
            }
        }
예제 #5
0
		public void LogAccess( IPAddress ipAddress ) {
			if ( IPLimiter.IsExempt( ipAddress ) )
				return;

			if ( m_LoginIPs.Length == 0 ) {
				if ( AccountHandler.IPTable.ContainsKey( ipAddress ) )
					AccountHandler.IPTable[ipAddress]++;
				else
					AccountHandler.IPTable[ipAddress] = 1;
			}

			bool contains = false;

			for ( int i = 0; !contains && i < m_LoginIPs.Length; ++i )
				contains = m_LoginIPs[i].Equals( ipAddress );

			if ( contains )
				return;

			IPAddress[] old = m_LoginIPs;
			m_LoginIPs = new IPAddress[old.Length + 1];

			for ( int i = 0; i < old.Length; ++i )
				m_LoginIPs[i] = old[i];

			m_LoginIPs[old.Length] = ipAddress;
		}
        private static void EventSink_SocketConnect(SocketConnectEventArgs e)
        {
            try
            {
                IPAddress ip = ((IPEndPoint)e.Socket.RemoteEndPoint).Address;

                if (Firewall.IsBlocked(ip))
                {
                    log.ErrorFormat("Client: {0}: Firewall blocked connection attempt.", ip);
                    e.AllowConnection = false;
                    return;
                }
                else if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip))
                {
                    log.ErrorFormat("Client: {0}: Past IP limit threshold", ip);

                    e.AllowConnection = false;
                    return;
                }
            }
            catch
            {
                e.AllowConnection = false;
            }
        }
예제 #7
0
        private static void OnSocketConnect(SocketConnectEventArgs e)
        {
            try
            {
                IPAddress ip = ((IPEndPoint)e.Socket.RemoteEndPoint).Address;

                if (Firewall.IsBlocked(ip))
                {
                    Console.WriteLine("Client: {0}: Firewall blocked connection attempt.", ip);
                    e.AllowConnection = false;
                    return;
                }

                if (!IPLimiter.SocketBlock || IPLimiter.Verify(ip))
                {
                    return;
                }

                LoggingCustom.Log(
                    "LOG_IPLimits.log",
                    String.Format("{0}\tPast IP limit threshold\t{1}", ip, DateTime.Now.ToSimpleString("t d-m-y N")));

                Console.WriteLine("Client: {0}: Past IP limit threshold", ip);

                e.AllowConnection = false;
            }
            catch
            {
                e.AllowConnection = false;
            }
        }
예제 #8
0
        public void LogAccess(IPAddress ipAddress, bool loggedOut)
        {
            if (IPLimiter.IsExempt(ipAddress))
            {
                return;
            }

            if (LoginIPs.Count == 0)
            {
                if (AccountHandler.IPTable.ContainsKey(ipAddress))
                {
                    AccountHandler.IPTable[ipAddress]++;
                }
                else
                {
                    AccountHandler.IPTable[ipAddress] = 1;
                }
            }

            LogIPAccess(ipAddress, loggedOut);

            if (!LoginIPs.Contains(ipAddress))
            {
                LoginIPs.Add(ipAddress);
            }
        }
예제 #9
0
        /// <summary>
        /// Checks if a specific NetState is allowed access to this account.
        /// </summary>
        /// <param name="ns">NetState instance to check.</param>
        /// <returns>True if allowed, false if not.</returns>
        public bool HasAccess(NetState ns)
        {
            if (ns == null)
            {
                return(false);
            }

            AccessLevel level = Misc.AccountHandler.LockdownLevel;

            if (level > AccessLevel.Player)
            {
                bool hasAccess = false;

                if (m_AccessLevel >= level)
                {
                    hasAccess = true;
                }
                else
                {
                    for (int i = 0; !hasAccess && i < this.Length; ++i)
                    {
                        Mobile m = this[i];

                        if (m != null && m.AccessLevel >= level)
                        {
                            hasAccess = true;
                        }
                    }
                }

                if (!hasAccess)
                {
                    return(false);
                }
            }

            IPAddress ipAddress;

            try { ipAddress = ((IPEndPoint)ns.Socket.RemoteEndPoint).Address; }
            catch { return(false); }

            bool accessAllowed = (m_IPRestrictions.Length == 0 || IPLimiter.IsExempt(ipAddress));

            for (int i = 0; !accessAllowed && i < m_IPRestrictions.Length; ++i)
            {
                accessAllowed = Utility.IPMatch(m_IPRestrictions[i], ipAddress);
            }

            return(accessAllowed);
        }
예제 #10
0
        /// <summary>
        /// Records the IP address of 'ns' in its 'LoginIPs' list.
        /// </summary>
        /// <param name="ns">NetState instance to record.</param>
        public void LogAccess(NetState ns)
        {
            if (ns == null)
            {
                return;
            }

            IPAddress ipAddress = ns.Address;

            if (IPLimiter.IsExempt(ipAddress))
            {
                return;
            }

            if (m_LoginIPs.Length == 0)
            {
                if (AccountHandler.IPTables[ipAddress] == null)
                {
                    AccountHandler.IPTables[ipAddress] = 1;
                }
                else
                {
                    AccountHandler.IPTables[ipAddress] = (int)AccountHandler.IPTables[ipAddress] + 1;
                }
            }

            bool contains = false;

            for (int i = 0; !contains && i < m_LoginIPs.Length; ++i)
            {
                contains = m_LoginIPs[i].Equals(ipAddress);
            }

            if (contains)
            {
                return;
            }

            IPAddress[] old = m_LoginIPs;
            m_LoginIPs = new IPAddress[old.Length + 1];

            for (int i = 0; i < old.Length; ++i)
            {
                m_LoginIPs[i] = old[i];
            }

            m_LoginIPs[old.Length] = ipAddress;
        }
예제 #11
0
        public void LogAccess(IPAddress ipAddress)
        {
            if (IPLimiter.IsExempt(ipAddress))
            {
                return;
            }

            if (m_LoginIPs.Count == 0)
            {
                if (AccountHandler.IPTable.ContainsKey(ipAddress))
                {
                    AccountHandler.IPTable[ipAddress]++;
                }
                else
                {
                    AccountHandler.IPTable[ipAddress] = 1;
                }
            }

/*
 *                      bool contains = false;
 *
 *                      for ( int i = 0; !contains && i < m_LoginIPs.Length; ++i )
 *                              contains = m_LoginIPs[i].Equals( ipAddress );
 *
 *                      if ( contains )
 *                              return;
 */
            if (!m_LoginIPs.Contains(ipAddress))
            {
                m_LoginIPs.Add(ipAddress);
            }

/*
 *                      IPAddress[] old = m_LoginIPs;
 *                      m_LoginIPs = new IPAddress[old.Length + 1];
 *
 *                      for ( int i = 0; i < old.Length; ++i )
 *                              m_LoginIPs[i] = old[i];
 *
 *                      m_LoginIPs[old.Length] = ipAddress;
 *
 */
        }
예제 #12
0
        public void LogAccess(IPAddress ipAddress)
        {
            if (IPLimiter.IsExempt(ipAddress))
            {
                return;
            }

            if (this.m_LoginIPs.Length == 0)
            {
                if (AccountHandler.IPTable.ContainsKey(ipAddress))
                {
                    AccountHandler.IPTable[ipAddress]++;
                }
                else
                {
                    AccountHandler.IPTable[ipAddress] = 1;
                }
            }

            bool contains = false;

            for (int i = 0; !contains && i < this.m_LoginIPs.Length; ++i)
            {
                contains = this.m_LoginIPs[i].Equals(ipAddress);
            }

            if (contains)
            {
                return;
            }

            IPAddress[] old = this.m_LoginIPs;
            this.m_LoginIPs = new IPAddress[old.Length + 1];

            for (int i = 0; i < old.Length; ++i)
            {
                this.m_LoginIPs[i] = old[i];
            }

            this.m_LoginIPs[old.Length] = ipAddress;
        }