1.7.7-alpha-fix

- Added missing migration
- Added missing ignoredips
This commit is contained in:
Dawid Bepierszcz
2025-05-21 00:38:54 +02:00
parent f69f1277f8
commit d34ca64970
3 changed files with 12 additions and 4 deletions

View File

@@ -26,6 +26,9 @@
<None Update="Database\Migrations\010_CreateWarnsTable.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Database\Migrations\012_AddUpdatedAtColumnToSaBansTable.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1 @@
ALTER TABLE `sa_bans` ADD COLUMN `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `status`;

View File

@@ -9,6 +9,7 @@ internal class CacheManager
{
private readonly ConcurrentDictionary<int, BanRecord> _banCache = new();
private readonly ConcurrentDictionary<ulong, (HashSet<string> ips, DateTime used_at)> _playerIpsCache = new();
private readonly HashSet<string> _cachedIgnoredIps = [..CS2_SimpleAdmin.Instance.Config.OtherSettings.IgnoredIps];
private DateTime _lastUpdateTime = DateTime.MinValue;
private bool _isInitialized;
@@ -132,7 +133,8 @@ internal class CacheManager
return _banCache.Values.Any(b =>
b.Status == "ACTIVE" &&
!string.IsNullOrEmpty(b.PlayerIp) &&
b.PlayerIp.Equals(ipAddress, StringComparison.OrdinalIgnoreCase));
b.PlayerIp.Equals(ipAddress, StringComparison.OrdinalIgnoreCase) &&
!_cachedIgnoredIps.Contains(ipAddress));
}
public bool IsPlayerBanned(string? steamId, string? ipAddress) =>
@@ -143,7 +145,8 @@ internal class CacheManager
b.PlayerSteamId.Equals(steamId, StringComparison.OrdinalIgnoreCase)) ||
(ipAddress != null &&
b.PlayerIp != null &&
b.PlayerIp.Equals(ipAddress, StringComparison.OrdinalIgnoreCase))
b.PlayerIp.Equals(ipAddress, StringComparison.OrdinalIgnoreCase) &&
!_cachedIgnoredIps.Contains(ipAddress))
));
public bool IsPlayerOrAnyIpBanned(ulong steamId)
@@ -155,8 +158,9 @@ internal class CacheManager
{
return true;
}
return _playerIpsCache.TryGetValue(steamId, out var ipList) && ipList.ips.Any(IsIpBanned);
return _playerIpsCache.TryGetValue(steamId, out var ipList) && ipList.ips.Any(ip =>
!_cachedIgnoredIps.Contains(ip) && IsIpBanned(ip));
}
public bool HasIpForPlayer(ulong steamId, string ipAddress)