ModernUO/Projects/UOContent/Accounting/IPLimiter.cs
Kamron Batman b921c38879
fix(core): Removes some uses of Linq (#421)
- [X] Removes some uses of linq
- [X] Creates struct based enumerator for Skills
- [X] Creates a struct based enumerator for TypeCache
- [X] Changes HarvestDefinition to an init array instead of List
- [X] Changes HeritageTokenGump Response from List to Array
2021-01-18 21:05:11 -08:00

60 lines
1.6 KiB
C#

using System.Net;
using Server.Network;
namespace Server.Misc
{
public static class IPLimiter
{
public static readonly IPAddress[] Exemptions =
{
IPAddress.Parse( "127.0.0.1" )
};
public static bool Enabled { get; private set; }
public static bool SocketBlock { get; private set; }
public static int MaxAddresses { get; private set; }
public static void Configure()
{
Enabled = ServerConfiguration.GetOrUpdateSetting("ipLimiter.enable", true);
SocketBlock = ServerConfiguration.GetOrUpdateSetting("ipLimiter.blockAtConnection", true);
MaxAddresses = ServerConfiguration.GetOrUpdateSetting("ipLimiter.maxConnectionsPerIP", 10);
}
public static bool IsExempt(IPAddress ip)
{
for (int i = 0; i < Exemptions.Length; i++)
{
if (ip.Equals(Exemptions[i]))
return true;
}
return false;
}
public static bool Verify(IPAddress ourAddress)
{
if (!Enabled || IsExempt(ourAddress))
{
return true;
}
var count = 0;
foreach (var ns in TcpServer.Instances)
{
if (ourAddress.Equals(ns.Address))
{
++count;
if (count >= MaxAddresses)
{
return false;
}
}
}
return true;
}
}
}