Add IP ban exemption flag (#15815)
This commit is contained in:
@@ -459,6 +459,14 @@ namespace Content.Server.Database
|
||||
/// Ban is a datacenter range, connections usually imply usage of a VPN service.
|
||||
/// </summary>
|
||||
Datacenter = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// Ban only matches the IP.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Intended use is for users with shared connections. This should not be used as an alternative to <see cref="Datacenter"/>.
|
||||
/// </remarks>
|
||||
IP = 1 << 1,
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace Content.Server.Database
|
||||
query = query == null ? newQ : query.Union(newQ);
|
||||
}
|
||||
|
||||
if (address != null)
|
||||
if (address != null && !exemptFlags.GetValueOrDefault(ServerBanExemptFlags.None).HasFlag(ServerBanExemptFlags.IP))
|
||||
{
|
||||
var newQ = db.PgDbContext.Ban
|
||||
.Include(p => p.Unban)
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Content.Server.Database
|
||||
// So just pull down the whole list into memory.
|
||||
var bans = await GetAllBans(db.SqliteDbContext, includeUnbanned: false, exempt);
|
||||
|
||||
return bans.FirstOrDefault(b => BanMatches(b, address, userId, hwId)) is { } foundBan
|
||||
return bans.FirstOrDefault(b => BanMatches(b, address, userId, hwId, exempt)) is { } foundBan
|
||||
? ConvertBan(foundBan)
|
||||
: null;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ namespace Content.Server.Database
|
||||
var queryBans = await GetAllBans(db.SqliteDbContext, includeUnbanned, exempt);
|
||||
|
||||
return queryBans
|
||||
.Where(b => BanMatches(b, address, userId, hwId))
|
||||
.Where(b => BanMatches(b, address, userId, hwId, exempt))
|
||||
.Select(ConvertBan)
|
||||
.ToList()!;
|
||||
}
|
||||
@@ -117,13 +117,14 @@ namespace Content.Server.Database
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
private static bool BanMatches(
|
||||
ServerBan ban,
|
||||
private static bool BanMatches(ServerBan ban,
|
||||
IPAddress? address,
|
||||
NetUserId? userId,
|
||||
ImmutableArray<byte>? hwId)
|
||||
ImmutableArray<byte>? hwId,
|
||||
ServerBanExemptFlags? exemptFlags)
|
||||
{
|
||||
if (address != null && ban.Address is not null && IPAddressExt.IsInSubnet(address, ban.Address.Value))
|
||||
if (!exemptFlags.GetValueOrDefault(ServerBanExemptFlags.None).HasFlag(ServerBanExemptFlags.IP)
|
||||
&& address != null && ban.Address is not null && IPAddressExt.IsInSubnet(address, ban.Address.Value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user