Better notes and bans (#14228)
Co-authored-by: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com>
This commit is contained in:
@@ -133,22 +133,17 @@ namespace Content.Server.Database
|
||||
ServerBanExemptFlags? exemptFlags)
|
||||
{
|
||||
if (!exemptFlags.GetValueOrDefault(ServerBanExemptFlags.None).HasFlag(ServerBanExemptFlags.IP)
|
||||
&& address != null && ban.Address is not null && IPAddressExt.IsInSubnet(address, ban.Address.Value))
|
||||
&& address != null && ban.Address is not null && address.IsInSubnet(ban.Address.Value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (userId is { } id && ban.UserId == id.UserId)
|
||||
if (userId is { } id && ban.PlayerUserId == id.UserId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hwId is { } hwIdVar && hwIdVar.Length > 0 && hwIdVar.AsSpan().SequenceEqual(ban.HWId))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return hwId is { Length: > 0 } hwIdVar && hwIdVar.AsSpan().SequenceEqual(ban.HWId);
|
||||
}
|
||||
|
||||
public override async Task AddServerBanAsync(ServerBanDef serverBan)
|
||||
@@ -159,11 +154,14 @@ namespace Content.Server.Database
|
||||
{
|
||||
Address = serverBan.Address,
|
||||
Reason = serverBan.Reason,
|
||||
Severity = serverBan.Severity,
|
||||
BanningAdmin = serverBan.BanningAdmin?.UserId,
|
||||
HWId = serverBan.HWId?.ToArray(),
|
||||
BanTime = serverBan.BanTime.UtcDateTime,
|
||||
ExpirationTime = serverBan.ExpirationTime?.UtcDateTime,
|
||||
UserId = serverBan.UserId?.UserId
|
||||
RoundId = serverBan.RoundId,
|
||||
PlaytimeAtNote = serverBan.PlaytimeAtNote,
|
||||
PlayerUserId = serverBan.UserId?.UserId
|
||||
});
|
||||
|
||||
await db.SqliteDbContext.SaveChangesAsync();
|
||||
@@ -197,7 +195,8 @@ namespace Content.Server.Database
|
||||
return ConvertRoleBan(ban);
|
||||
}
|
||||
|
||||
public override async Task<List<ServerRoleBanDef>> GetServerRoleBansAsync(IPAddress? address,
|
||||
public override async Task<List<ServerRoleBanDef>> GetServerRoleBansAsync(
|
||||
IPAddress? address,
|
||||
NetUserId? userId,
|
||||
ImmutableArray<byte>? hwId,
|
||||
bool includeUnbanned)
|
||||
@@ -234,22 +233,17 @@ namespace Content.Server.Database
|
||||
NetUserId? userId,
|
||||
ImmutableArray<byte>? hwId)
|
||||
{
|
||||
if (address != null && ban.Address is not null && IPAddressExt.IsInSubnet(address, ban.Address.Value))
|
||||
if (address != null && ban.Address is not null && address.IsInSubnet(ban.Address.Value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (userId is { } id && ban.UserId == id.UserId)
|
||||
if (userId is { } id && ban.PlayerUserId == id.UserId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hwId is { } hwIdVar && hwIdVar.Length > 0 && hwIdVar.AsSpan().SequenceEqual(ban.HWId))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return hwId is { Length: > 0 } hwIdVar && hwIdVar.AsSpan().SequenceEqual(ban.HWId);
|
||||
}
|
||||
|
||||
public override async Task AddServerRoleBanAsync(ServerRoleBanDef serverBan)
|
||||
@@ -260,11 +254,14 @@ namespace Content.Server.Database
|
||||
{
|
||||
Address = serverBan.Address,
|
||||
Reason = serverBan.Reason,
|
||||
Severity = serverBan.Severity,
|
||||
BanningAdmin = serverBan.BanningAdmin?.UserId,
|
||||
HWId = serverBan.HWId?.ToArray(),
|
||||
BanTime = serverBan.BanTime.UtcDateTime,
|
||||
ExpirationTime = serverBan.ExpirationTime?.UtcDateTime,
|
||||
UserId = serverBan.UserId?.UserId,
|
||||
RoundId = serverBan.RoundId,
|
||||
PlaytimeAtNote = serverBan.PlaytimeAtNote,
|
||||
PlayerUserId = serverBan.UserId?.UserId,
|
||||
RoleId = serverBan.Role,
|
||||
});
|
||||
|
||||
@@ -293,7 +290,7 @@ namespace Content.Server.Database
|
||||
}
|
||||
|
||||
NetUserId? uid = null;
|
||||
if (ban.UserId is { } guid)
|
||||
if (ban.PlayerUserId is { } guid)
|
||||
{
|
||||
uid = new NetUserId(guid);
|
||||
}
|
||||
@@ -314,7 +311,10 @@ namespace Content.Server.Database
|
||||
// SQLite apparently always reads DateTime as unspecified, but we always write as UTC.
|
||||
DateTime.SpecifyKind(ban.BanTime, DateTimeKind.Utc),
|
||||
ban.ExpirationTime == null ? null : DateTime.SpecifyKind(ban.ExpirationTime.Value, DateTimeKind.Utc),
|
||||
ban.RoundId,
|
||||
ban.PlaytimeAtNote,
|
||||
ban.Reason,
|
||||
ban.Severity,
|
||||
aUid,
|
||||
unban,
|
||||
ban.RoleId);
|
||||
@@ -360,7 +360,7 @@ namespace Content.Server.Database
|
||||
}
|
||||
|
||||
NetUserId? uid = null;
|
||||
if (ban.UserId is { } guid)
|
||||
if (ban.PlayerUserId is { } guid)
|
||||
{
|
||||
uid = new NetUserId(guid);
|
||||
}
|
||||
@@ -381,7 +381,10 @@ namespace Content.Server.Database
|
||||
// SQLite apparently always reads DateTime as unspecified, but we always write as UTC.
|
||||
DateTime.SpecifyKind(ban.BanTime, DateTimeKind.Utc),
|
||||
ban.ExpirationTime == null ? null : DateTime.SpecifyKind(ban.ExpirationTime.Value, DateTimeKind.Utc),
|
||||
ban.RoundId,
|
||||
ban.PlaytimeAtNote,
|
||||
ban.Reason,
|
||||
ban.Severity,
|
||||
aUid,
|
||||
unban);
|
||||
}
|
||||
@@ -483,7 +486,7 @@ namespace Content.Server.Database
|
||||
var nextId = 1;
|
||||
if (await db.DbContext.AdminNotes.AnyAsync())
|
||||
{
|
||||
nextId = await db.DbContext.AdminNotes.MaxAsync(dbVersion => dbVersion.Id) + 1;
|
||||
nextId = await db.DbContext.AdminNotes.MaxAsync(adminNote => adminNote.Id) + 1;
|
||||
}
|
||||
|
||||
note.Id = nextId;
|
||||
@@ -491,6 +494,37 @@ namespace Content.Server.Database
|
||||
|
||||
return await base.AddAdminNote(note);
|
||||
}
|
||||
public override async Task<int> AddAdminWatchlist(AdminWatchlist watchlist)
|
||||
{
|
||||
await using (var db = await GetDb())
|
||||
{
|
||||
var nextId = 1;
|
||||
if (await db.DbContext.AdminWatchlists.AnyAsync())
|
||||
{
|
||||
nextId = await db.DbContext.AdminWatchlists.MaxAsync(adminWatchlist => adminWatchlist.Id) + 1;
|
||||
}
|
||||
|
||||
watchlist.Id = nextId;
|
||||
}
|
||||
|
||||
return await base.AddAdminWatchlist(watchlist);
|
||||
}
|
||||
|
||||
public override async Task<int> AddAdminMessage(AdminMessage message)
|
||||
{
|
||||
await using (var db = await GetDb())
|
||||
{
|
||||
var nextId = 1;
|
||||
if (await db.DbContext.AdminMessages.AnyAsync())
|
||||
{
|
||||
nextId = await db.DbContext.AdminMessages.MaxAsync(adminMessage => adminMessage.Id) + 1;
|
||||
}
|
||||
|
||||
message.Id = nextId;
|
||||
}
|
||||
|
||||
return await base.AddAdminMessage(message);
|
||||
}
|
||||
|
||||
private async Task<DbGuardImpl> GetDbImpl()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user