Server ban exemption system (#15076)
This commit is contained in:
committed by
GitHub
parent
e037d12899
commit
c8e90e561b
@@ -68,9 +68,11 @@ namespace Content.Server.Database
|
||||
{
|
||||
await using var db = await GetDbImpl();
|
||||
|
||||
var exempt = await GetBanExemptionCore(db, userId);
|
||||
|
||||
// SQLite can't do the net masking stuff we need to match IP address ranges.
|
||||
// So just pull down the whole list into memory.
|
||||
var bans = await GetAllBans(db.SqliteDbContext, includeUnbanned: false);
|
||||
var bans = await GetAllBans(db.SqliteDbContext, includeUnbanned: false, exempt);
|
||||
|
||||
return bans.FirstOrDefault(b => BanMatches(b, address, userId, hwId)) is { } foundBan
|
||||
? ConvertBan(foundBan)
|
||||
@@ -83,9 +85,11 @@ namespace Content.Server.Database
|
||||
{
|
||||
await using var db = await GetDbImpl();
|
||||
|
||||
var exempt = await GetBanExemptionCore(db, userId);
|
||||
|
||||
// SQLite can't do the net masking stuff we need to match IP address ranges.
|
||||
// So just pull down the whole list into memory.
|
||||
var queryBans = await GetAllBans(db.SqliteDbContext, includeUnbanned);
|
||||
var queryBans = await GetAllBans(db.SqliteDbContext, includeUnbanned, exempt);
|
||||
|
||||
return queryBans
|
||||
.Where(b => BanMatches(b, address, userId, hwId))
|
||||
@@ -95,7 +99,8 @@ namespace Content.Server.Database
|
||||
|
||||
private static async Task<List<ServerBan>> GetAllBans(
|
||||
SqliteServerDbContext db,
|
||||
bool includeUnbanned)
|
||||
bool includeUnbanned,
|
||||
ServerBanExemptFlags? exemptFlags)
|
||||
{
|
||||
IQueryable<ServerBan> query = db.Ban.Include(p => p.Unban);
|
||||
if (!includeUnbanned)
|
||||
@@ -104,6 +109,11 @@ namespace Content.Server.Database
|
||||
p.Unban == null && (p.ExpirationTime == null || p.ExpirationTime.Value > DateTime.UtcNow));
|
||||
}
|
||||
|
||||
if (exemptFlags is { } exempt)
|
||||
{
|
||||
query = query.Where(b => (b.ExemptFlags & exempt) == 0);
|
||||
}
|
||||
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user