Server ban exemption system (#15076)
This commit is contained in:
committed by
GitHub
parent
e037d12899
commit
c8e90e561b
@@ -332,6 +332,52 @@ namespace Content.Server.Database
|
||||
|
||||
public abstract Task AddServerBanAsync(ServerBanDef serverBan);
|
||||
public abstract Task AddServerUnbanAsync(ServerUnbanDef serverUnban);
|
||||
|
||||
protected static async Task<ServerBanExemptFlags?> GetBanExemptionCore(DbGuard db, NetUserId? userId)
|
||||
{
|
||||
if (userId == null)
|
||||
return null;
|
||||
|
||||
var exemption = await db.DbContext.BanExemption
|
||||
.SingleOrDefaultAsync(e => e.UserId == userId.Value.UserId);
|
||||
|
||||
return exemption?.Flags;
|
||||
}
|
||||
|
||||
public async Task UpdateBanExemption(NetUserId userId, ServerBanExemptFlags flags)
|
||||
{
|
||||
await using var db = await GetDb();
|
||||
|
||||
if (flags == 0)
|
||||
{
|
||||
// Delete whatever is there.
|
||||
await db.DbContext.BanExemption.Where(u => u.UserId == userId.UserId).ExecuteDeleteAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var exemption = await db.DbContext.BanExemption.SingleOrDefaultAsync(u => u.UserId == userId.UserId);
|
||||
if (exemption == null)
|
||||
{
|
||||
exemption = new ServerBanExemption
|
||||
{
|
||||
UserId = userId
|
||||
};
|
||||
|
||||
db.DbContext.BanExemption.Add(exemption);
|
||||
}
|
||||
|
||||
exemption.Flags = flags;
|
||||
await db.DbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<ServerBanExemptFlags> GetBanExemption(NetUserId userId)
|
||||
{
|
||||
await using var db = await GetDb();
|
||||
|
||||
var flags = await GetBanExemptionCore(db, userId);
|
||||
return flags ?? ServerBanExemptFlags.None;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Role Bans
|
||||
@@ -985,6 +1031,5 @@ namespace Content.Server.Database
|
||||
|
||||
public abstract ValueTask DisposeAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user