blob: 20a21590b31a281f979b6d82290ab8338e898408 (
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
46
47
48
49
50
51
52
|
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;
try
{
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;
}
}
}
catch (System.Net.Sockets.SocketException sex)
{
m_log.WarnFormat("[IPBAN] IP address \"{0}\" cannot be resolved via DNS", end);
}
m_log.WarnFormat("[IPBAN] User \"{0}\" not in any ban lists. Allowing connection.", end);
}
}
}
}
|