1.7.7-alpha-small-optimizations

- Clear bans cache on plugin reload
- Changed ip history to int
This commit is contained in:
Dawid Bepierszcz
2025-05-23 03:28:10 +02:00
parent f654d6b085
commit 3ab63c05db
11 changed files with 284 additions and 169 deletions

View File

@@ -62,14 +62,14 @@ internal static class Helper
return GetValidPlayers().FirstOrDefault(x => x.IpAddress != null && x.IpAddress.Split(":")[0].Equals(ipAddress));
}
public static IReadOnlyList<CCSPlayerController> GetValidPlayers()
public static List<CCSPlayerController> GetValidPlayers()
{
return Utilities.GetPlayers().AsValueEnumerable()
.Where(p => p is { IsValid: true, IsBot: false, Connected: PlayerConnectedState.PlayerConnected })
.ToList();
}
public static IReadOnlyList<CCSPlayerController> GetValidPlayersWithBots()
public static List<CCSPlayerController> GetValidPlayersWithBots()
{
return Utilities.GetPlayers().AsValueEnumerable()
.Where(p => p is { IsValid: true, IsHLTV: false, Connected: PlayerConnectedState.PlayerConnected }).ToList();
@@ -970,3 +970,35 @@ public static class WeaponHelper
return filteredWeapons; // Return all relevant matches for the partial input
}
}
public static class IpHelper
{
public static uint IpToUint(string ipAddress)
{
return (uint)BitConverter.ToInt32(System.Net.IPAddress.Parse(ipAddress).GetAddressBytes().Reverse().ToArray(),
0);
}
public static bool TryConvertIpToUint(string ipString, out uint ipUint)
{
ipUint = 0;
if (string.IsNullOrWhiteSpace(ipString))
return false;
if (!System.Net.IPAddress.TryParse(ipString, out var ipAddress))
return false;
var bytes = ipAddress.GetAddressBytes();
if (bytes.Length != 4)
return false;
ipUint = IpToUint(ipString);
return true;
}
public static string UintToIp(uint ipAddress)
{
var bytes = BitConverter.GetBytes(ipAddress).Reverse().ToArray();
return new System.Net.IPAddress(bytes).ToString();
}
}