ModernUO/Projects/UOContent/Accounting/AccessRestrictions.cs
Kamron Batman 525cda5413
Cleanup & Fixes for .NET 5 (#309)
- [X] Fixes several bugs
- [X] Updates more ordinal issues
- [X] Cleans up the code a bit
- [X] Turns classes static that should have been
- [X] Changes TcpServer.Instances to a HashSet

Bumps release version
2020-11-15 10:03:50 -08:00

46 lines
1.3 KiB
C#

using System;
using System.IO;
using System.Net;
using Server.Misc;
namespace Server
{
public static class AccessRestrictions
{
public static void Initialize()
{
EventSink.SocketConnect += EventSink_SocketConnect;
}
private static void EventSink_SocketConnect(SocketConnectEventArgs e)
{
try
{
var ip = (e.Connection.RemoteEndPoint as IPEndPoint)?.Address;
if (Firewall.IsBlocked(ip))
{
Console.WriteLine("Client: {0}: Firewall blocked connection attempt.", ip);
e.AllowConnection = false;
return;
}
if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip))
{
Console.WriteLine("Client: {0}: Past IP limit threshold", ip);
using (var op = new StreamWriter("ipLimits.log", true))
{
op.WriteLine("{0}\tPast IP limit threshold\t{1}", ip, DateTime.UtcNow);
}
e.AllowConnection = false;
}
}
catch
{
e.AllowConnection = false;
}
}
}
}