Exemple #1
0
        void EventManager_OnClientConnect(IClientAPI client)
        {
            // Only need to run through all this if there are entries in the ban list
            if (bans.Count > 0)
            {
                IPAddress end      = client.RemoteEndPoint.Address;
                string    endstr   = end.ToString();
                string    hostName = null;
                try
                {
                    IPHostEntry rDNS = Dns.GetHostEntry(end);
                    hostName = rDNS.HostName;
                }
                catch (System.Net.Sockets.SocketException)
                {
                    //m_log.WarnFormat("[IPBAN] IP address \"{0}\" cannot be resolved via DNS", end);
                    hostName = null;
                }

                if (string.IsNullOrEmpty(hostName))
                {
                    // just try possible ip match
                    foreach (string ban in bans)
                    {
                        if (endstr.StartsWith(ban))
                        {
                            client.Disconnect("Banned - network \"" + ban + "\" is not allowed to connect to this server.");
                            m_log.Warn("[IPBAN] Disconnected '" + end + "' due to '" + ban + "' ban.");
                            return;
                        }
                    }
                }
                else
                {
                    foreach (string ban in bans)
                    {
                        if (hostName.Contains(ban) || end.ToString().StartsWith(ban))
                        {
                            client.Disconnect("Banned - network \"" + ban + "\" is not allowed to connect to this server.");
                            m_log.Warn("[IPBAN] Disconnected '" + end + "' due to '" + ban + "' ban.");
                            return;
                        }
                    }
                }
            }
            // m_log.DebugFormat("[IPBAN] User \"{0}\" not in any ban lists. Allowing connection.", end);
        }