[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

@@ -79,7 +79,8 @@ namespace Content.Server.Database
public override async Task<ServerBanDef?> GetServerBanAsync(
IPAddress? address,
NetUserId? userId,
ImmutableArray<byte>? hwId)
ImmutableArray<byte>? hwId,
string serverName = GlobalServerName)
{
await using var db = await GetDbImpl();
@@ -89,14 +90,14 @@ namespace Content.Server.Database
// So just pull down the whole list into memory.
var bans = await GetAllBans(db.SqliteDbContext, includeUnbanned: false, exempt);
return bans.FirstOrDefault(b => BanMatches(b, address, userId, hwId, exempt)) is { } foundBan
return bans.FirstOrDefault(b => BanMatches(b, address, userId, hwId, exempt, serverName)) is { } foundBan
? ConvertBan(foundBan)
: null;
}
public override async Task<List<ServerBanDef>> GetServerBansAsync(IPAddress? address,
NetUserId? userId,
ImmutableArray<byte>? hwId, bool includeUnbanned)
ImmutableArray<byte>? hwId, bool includeUnbanned, string serverName = GlobalServerName)
{
await using var db = await GetDbImpl();
@@ -107,7 +108,7 @@ namespace Content.Server.Database
var queryBans = await GetAllBans(db.SqliteDbContext, includeUnbanned, exempt);
return queryBans
.Where(b => BanMatches(b, address, userId, hwId, exempt))
.Where(b => BanMatches(b, address, userId, hwId, exempt, serverName))
.Select(ConvertBan)
.ToList()!;
}
@@ -136,8 +137,14 @@ namespace Content.Server.Database
IPAddress? address,
NetUserId? userId,
ImmutableArray<byte>? hwId,
ServerBanExemptFlags? exemptFlags)
ServerBanExemptFlags? exemptFlags,
string serverName = GlobalServerName)
{
if (serverName != GlobalServerName && ban.ServerName != GlobalServerName && serverName != ban.ServerName)
{
return false;
}
if (!exemptFlags.GetValueOrDefault(ServerBanExemptFlags.None).HasFlag(ServerBanExemptFlags.IP)
&& address != null && ban.Address is not null && address.IsInSubnet(ban.Address.Value))
{
@@ -167,7 +174,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.SqliteDbContext.SaveChangesAsync();
@@ -205,7 +213,8 @@ namespace Content.Server.Database
IPAddress? address,
NetUserId? userId,
ImmutableArray<byte>? hwId,
bool includeUnbanned)
bool includeUnbanned,
string serverName = GlobalServerName)
{
await using var db = await GetDbImpl();
@@ -214,7 +223,7 @@ namespace Content.Server.Database
var queryBans = await GetAllRoleBans(db.SqliteDbContext, includeUnbanned);
return queryBans
.Where(b => RoleBanMatches(b, address, userId, hwId))
.Where(b => RoleBanMatches(b, address, userId, hwId, serverName))
.Select(ConvertRoleBan)
.ToList()!;
}
@@ -237,8 +246,14 @@ namespace Content.Server.Database
ServerRoleBan ban,
IPAddress? address,
NetUserId? userId,
ImmutableArray<byte>? hwId)
ImmutableArray<byte>? hwId,
string serverName)
{
if (serverName != GlobalServerName && ban.ServerName != GlobalServerName && serverName != ban.ServerName)
{
return false;
}
if (address != null && ban.Address is not null && address.IsInSubnet(ban.Address.Value))
{
return true;
@@ -269,6 +284,7 @@ namespace Content.Server.Database
PlaytimeAtNote = serverBan.PlaytimeAtNote,
PlayerUserId = serverBan.UserId?.UserId,
RoleId = serverBan.Role,
ServerName = serverBan.ServerName
};
db.SqliteDbContext.RoleBan.Add(ban);
@@ -326,7 +342,8 @@ namespace Content.Server.Database
ban.Severity,
aUid,
unban,
ban.RoleId);
ban.RoleId,
ban.ServerName ??= GlobalServerName);
}
private static ServerRoleUnbanDef? ConvertRoleUnban(ServerRoleUnban? unban)
@@ -395,7 +412,8 @@ namespace Content.Server.Database
ban.Reason,
ban.Severity,
aUid,
unban);
unban,
ban.ServerName ??= GlobalServerName);
}
private static ServerUnbanDef? ConvertUnban(ServerUnban? unban)