Revert "Revert "Log ban hits in DB. ( (#6361)
This commit is contained in:
committed by
GitHub
parent
aaea5dd2d8
commit
5091c6aa9d
@@ -59,8 +59,7 @@ namespace Content.Server.Database
|
||||
|
||||
await using var db = await GetDbImpl();
|
||||
|
||||
var query = MakeBanLookupQuery(address, userId, hwId, db)
|
||||
.Where(p => p.Unban == null && (p.ExpirationTime == null || p.ExpirationTime.Value > DateTime.Now))
|
||||
var query = MakeBanLookupQuery(address, userId, hwId, db, includeUnbanned: false)
|
||||
.OrderByDescending(b => b.BanTime);
|
||||
|
||||
var ban = await query.FirstOrDefaultAsync();
|
||||
@@ -68,10 +67,9 @@ namespace Content.Server.Database
|
||||
return ConvertBan(ban);
|
||||
}
|
||||
|
||||
public override async Task<List<ServerBanDef>> GetServerBansAsync(
|
||||
IPAddress? address,
|
||||
public override async Task<List<ServerBanDef>> GetServerBansAsync(IPAddress? address,
|
||||
NetUserId? userId,
|
||||
ImmutableArray<byte>? hwId)
|
||||
ImmutableArray<byte>? hwId, bool includeUnbanned)
|
||||
{
|
||||
if (address == null && userId == null && hwId == null)
|
||||
{
|
||||
@@ -80,7 +78,7 @@ namespace Content.Server.Database
|
||||
|
||||
await using var db = await GetDbImpl();
|
||||
|
||||
var query = MakeBanLookupQuery(address, userId, hwId, db);
|
||||
var query = MakeBanLookupQuery(address, userId, hwId, db, includeUnbanned);
|
||||
|
||||
var queryBans = await query.ToArrayAsync();
|
||||
var bans = new List<ServerBanDef>(queryBans.Length);
|
||||
@@ -102,7 +100,8 @@ namespace Content.Server.Database
|
||||
IPAddress? address,
|
||||
NetUserId? userId,
|
||||
ImmutableArray<byte>? hwId,
|
||||
DbGuardImpl db)
|
||||
DbGuardImpl db,
|
||||
bool includeUnbanned)
|
||||
{
|
||||
IQueryable<ServerBan>? query = null;
|
||||
|
||||
@@ -133,6 +132,12 @@ namespace Content.Server.Database
|
||||
query = query == null ? newQ : query.Union(newQ);
|
||||
}
|
||||
|
||||
if (!includeUnbanned)
|
||||
{
|
||||
query = query?.Where(p =>
|
||||
p.Unban == null && (p.ExpirationTime == null || p.ExpirationTime.Value > DateTime.Now));
|
||||
}
|
||||
|
||||
query = query!.Distinct();
|
||||
return query;
|
||||
}
|
||||
@@ -232,24 +237,30 @@ namespace Content.Server.Database
|
||||
record.LastSeenHWId?.ToImmutableArray());
|
||||
}
|
||||
|
||||
public override async Task AddConnectionLogAsync(
|
||||
public override async Task<int> AddConnectionLogAsync(
|
||||
NetUserId userId,
|
||||
string userName,
|
||||
IPAddress address,
|
||||
ImmutableArray<byte> hwId)
|
||||
ImmutableArray<byte> hwId,
|
||||
ConnectionDenyReason? denied)
|
||||
{
|
||||
await using var db = await GetDbImpl();
|
||||
|
||||
db.PgDbContext.ConnectionLog.Add(new ConnectionLog
|
||||
var connectionLog = new ConnectionLog
|
||||
{
|
||||
Address = address,
|
||||
Time = DateTime.UtcNow,
|
||||
UserId = userId.UserId,
|
||||
UserName = userName,
|
||||
HWId = hwId.ToArray()
|
||||
});
|
||||
HWId = hwId.ToArray(),
|
||||
Denied = denied,
|
||||
};
|
||||
|
||||
db.PgDbContext.ConnectionLog.Add(connectionLog);
|
||||
|
||||
await db.PgDbContext.SaveChangesAsync();
|
||||
|
||||
return connectionLog.Id;
|
||||
}
|
||||
|
||||
public override async Task<((Admin, string? lastUserName)[] admins, AdminRank[])>
|
||||
|
||||
Reference in New Issue
Block a user