[feat] Разделение банов по серверам.

# Conflicts:
#	Content.Client/Administration/UI/BanList/BanListLine.xaml.cs
#	Content.Client/Administration/UI/BanList/Bans/BanListHeader.xaml
#	Content.Client/Administration/UI/BanList/Bans/BanListLine.xaml
#	Content.Client/Administration/UI/Tabs/AdminTab/BanWindow.xaml
#	Content.Client/Administration/UI/Tabs/AdminTab/BanWindow.xaml.cs
#	Content.IntegrationTests/Tests/Commands/PardonCommand.cs
#	Content.Server/Administration/Commands/BanCommand.cs
#	Content.Server/Administration/Commands/DepartmentBanCommand.cs
#	Content.Server/Administration/Commands/RoleBanCommand.cs
#	Content.Server/Administration/Managers/RoleBanManager.cs
#	Content.Server/Database/ServerDbManager.cs
#	Content.Server/Database/ServerDbPostgres.cs
#	Content.Server/Database/ServerDbSqlite.cs
This commit is contained in:
rhailrake
2023-04-30 14:27:27 +06:00
committed by Remuchi
parent 8bd6754472
commit 977e075086
42 changed files with 5825 additions and 328 deletions

View File

@@ -67,7 +67,8 @@ namespace Content.Server.Database
public override async Task<ServerBanDef?> GetServerBanAsync(
IPAddress? address,
NetUserId? userId,
ImmutableArray<byte>? hwId)
ImmutableArray<byte>? hwId,
string serverName = GlobalServerName)
{
if (address == null && userId == null && hwId == null)
{
@@ -77,7 +78,7 @@ namespace Content.Server.Database
await using var db = await GetDbImpl();
var exempt = await GetBanExemptionCore(db, userId);
var query = MakeBanLookupQuery(address, userId, hwId, db, includeUnbanned: false, exempt)
var query = MakeBanLookupQuery(address, userId, hwId, db, includeUnbanned: false, exempt, serverName)
.OrderByDescending(b => b.BanTime);
var ban = await query.FirstOrDefaultAsync();
@@ -87,7 +88,7 @@ namespace Content.Server.Database
public override async Task<List<ServerBanDef>> GetServerBansAsync(IPAddress? address,
NetUserId? userId,
ImmutableArray<byte>? hwId, bool includeUnbanned)
ImmutableArray<byte>? hwId, bool includeUnbanned, string serverName = GlobalServerName)
{
if (address == null && userId == null && hwId == null)
{
@@ -97,7 +98,7 @@ namespace Content.Server.Database
await using var db = await GetDbImpl();
var exempt = await GetBanExemptionCore(db, userId);
var query = MakeBanLookupQuery(address, userId, hwId, db, includeUnbanned, exempt);
var query = MakeBanLookupQuery(address, userId, hwId, db, includeUnbanned, exempt, serverName);
var queryBans = await query.ToArrayAsync();
var bans = new List<ServerBanDef>(queryBans.Length);
@@ -121,7 +122,8 @@ namespace Content.Server.Database
ImmutableArray<byte>? hwId,
DbGuardImpl db,
bool includeUnbanned,
ServerBanExemptFlags? exemptFlags)
ServerBanExemptFlags? exemptFlags,
string serverName = GlobalServerName)
{
DebugTools.Assert(!(address == null && userId == null && hwId == null));
@@ -158,6 +160,9 @@ namespace Content.Server.Database
query != null,
"At least one filter item (IP/UserID/HWID) must have been given to make query not null.");
query = query.Where(p =>
p.ServerName == serverName || p.ServerName == "unknown" || string.IsNullOrEmpty(p.ServerName) || serverName == GlobalServerName);
if (!includeUnbanned)
{
query = query.Where(p =>
@@ -205,7 +210,8 @@ namespace Content.Server.Database
ban.Reason,
ban.Severity,
aUid,
unbanDef);
unbanDef,
ban.ServerName ??= "unknown");
}
private static ServerUnbanDef? ConvertUnban(ServerUnban? unban)
@@ -242,7 +248,8 @@ namespace Content.Server.Database
ExpirationTime = serverBan.ExpirationTime?.UtcDateTime,
RoundId = serverBan.RoundId,
PlaytimeAtNote = serverBan.PlaytimeAtNote,
PlayerUserId = serverBan.UserId?.UserId
PlayerUserId = serverBan.UserId?.UserId,
ServerName = serverBan.ServerName
});
await db.PgDbContext.SaveChangesAsync();
@@ -281,7 +288,8 @@ namespace Content.Server.Database
public override async Task<List<ServerRoleBanDef>> GetServerRoleBansAsync(IPAddress? address,
NetUserId? userId,
ImmutableArray<byte>? hwId,
bool includeUnbanned)
bool includeUnbanned,
string serverName = GlobalServerName)
{
if (address == null && userId == null && hwId == null)
{
@@ -290,7 +298,7 @@ namespace Content.Server.Database
await using var db = await GetDbImpl();
var query = MakeRoleBanLookupQuery(address, userId, hwId, db, includeUnbanned)
var query = MakeRoleBanLookupQuery(address, userId, hwId, db, includeUnbanned, serverName)
.OrderByDescending(b => b.BanTime);
return await QueryRoleBans(query);
@@ -319,7 +327,8 @@ namespace Content.Server.Database
NetUserId? userId,
ImmutableArray<byte>? hwId,
DbGuardImpl db,
bool includeUnbanned)
bool includeUnbanned,
string serverName = GlobalServerName)
{
IQueryable<ServerRoleBan>? query = null;
@@ -350,6 +359,9 @@ namespace Content.Server.Database
query = query == null ? newQ : query.Union(newQ);
}
query = query?.Where(p =>
p.ServerName == serverName || p.ServerName == "unknown" || string.IsNullOrEmpty(p.ServerName) || serverName == GlobalServerName);
if (!includeUnbanned)
{
query = query?.Where(p =>
@@ -395,7 +407,8 @@ namespace Content.Server.Database
ban.Severity,
aUid,
unbanDef,
ban.RoleId);
ban.RoleId,
ban.ServerName ??= "unknown");
}
private static ServerRoleUnbanDef? ConvertRoleUnban(ServerRoleUnban? unban)
@@ -434,6 +447,7 @@ namespace Content.Server.Database
PlaytimeAtNote = serverRoleBan.PlaytimeAtNote,
PlayerUserId = serverRoleBan.UserId?.UserId,
RoleId = serverRoleBan.Role,
ServerName = serverRoleBan.ServerName
};
db.PgDbContext.RoleBan.Add(ban);