aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Agent/IPBan/SceneBanner.cs
blob: 1d8da46b68e58697e2d2d2f5d21825101e436d06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Collections.Generic;
using System.Net;
using OpenSim.Framework.Client;
using OpenSim.Region.Framework.Scenes;

namespace OpenSim.Region.CoreModules.Agent.IPBan
{
    internal class SceneBanner
    {
                private static readonly log4net.ILog m_log
                    = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        private List<string> bans;
        private SceneBase m_scene;
        public SceneBanner(SceneBase scene, List<string> banList)
        {
            scene.EventManager.OnClientConnect += EventManager_OnClientConnect;

            bans = banList;
            m_scene = scene;
        }

        void EventManager_OnClientConnect(IClientCore client)
        {
            IClientIPEndpoint ipEndpoint;
            if(client.TryGet(out ipEndpoint))
            {
                IPAddress end = ipEndpoint.EndPoint;

                IPHostEntry rDNS = Dns.GetHostEntry(end);
                foreach (string ban in bans)
                {
                    if (rDNS.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.Warn("[IPBAN] User '" + end + "' not in any ban lists. Allowing connection.");
            }
        }
    }
}