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.
|
/// Ban is a datacenter range, connections usually imply usage of a VPN service.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Datacenter = 1 << 0,
|
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
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace Content.Server.Database
|
|||||||
query = query == null ? newQ : query.Union(newQ);
|
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
|
var newQ = db.PgDbContext.Ban
|
||||||
.Include(p => p.Unban)
|
.Include(p => p.Unban)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace Content.Server.Database
|
|||||||
// So just pull down the whole list into memory.
|
// So just pull down the whole list into memory.
|
||||||
var bans = await GetAllBans(db.SqliteDbContext, includeUnbanned: false, exempt);
|
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)
|
? ConvertBan(foundBan)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ namespace Content.Server.Database
|
|||||||
var queryBans = await GetAllBans(db.SqliteDbContext, includeUnbanned, exempt);
|
var queryBans = await GetAllBans(db.SqliteDbContext, includeUnbanned, exempt);
|
||||||
|
|
||||||
return queryBans
|
return queryBans
|
||||||
.Where(b => BanMatches(b, address, userId, hwId))
|
.Where(b => BanMatches(b, address, userId, hwId, exempt))
|
||||||
.Select(ConvertBan)
|
.Select(ConvertBan)
|
||||||
.ToList()!;
|
.ToList()!;
|
||||||
}
|
}
|
||||||
@@ -117,13 +117,14 @@ namespace Content.Server.Database
|
|||||||
return await query.ToListAsync();
|
return await query.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool BanMatches(
|
private static bool BanMatches(ServerBan ban,
|
||||||
ServerBan ban,
|
|
||||||
IPAddress? address,
|
IPAddress? address,
|
||||||
NetUserId? userId,
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user