Files
OldThink/Content.Server/Database/ServerRoleBanDef.cs

71 lines
2.1 KiB
C#
Raw Normal View History

using System.Collections.Immutable;
2022-02-21 14:11:39 -08:00
using System.Net;
using Content.Shared.Database;
2022-02-21 14:11:39 -08:00
using Robust.Shared.Network;
namespace Content.Server.Database;
public sealed class ServerRoleBanDef
{
public int? Id { get; }
public NetUserId? UserId { get; }
public (IPAddress address, int cidrMask)? Address { get; }
public ImmutableArray<byte>? HWId { get; }
public DateTimeOffset BanTime { get; }
public DateTimeOffset? ExpirationTime { get; }
public int? RoundId { get; }
public TimeSpan PlaytimeAtNote { get; }
2022-02-21 14:11:39 -08:00
public string Reason { get; }
public NoteSeverity Severity { get; set; }
2022-02-21 14:11:39 -08:00
public NetUserId? BanningAdmin { get; }
public ServerRoleUnbanDef? Unban { get; }
public string Role { get; }
public string? ServerName { get; }
2022-02-21 14:11:39 -08:00
public ServerRoleBanDef(
int? id,
NetUserId? userId,
(IPAddress, int)? address,
ImmutableArray<byte>? hwId,
DateTimeOffset banTime,
DateTimeOffset? expirationTime,
int? roundId,
TimeSpan playtimeAtNote,
2022-02-21 14:11:39 -08:00
string reason,
NoteSeverity severity,
2022-02-21 14:11:39 -08:00
NetUserId? banningAdmin,
ServerRoleUnbanDef? unban,
string role,
string serverName)
2022-02-21 14:11:39 -08:00
{
if (userId == null && address == null && hwId == null)
{
throw new ArgumentException("Must have at least one of banned user, banned address or hardware ID");
}
if (address is {} addr && addr.Item1.IsIPv4MappedToIPv6)
{
// Fix IPv6-mapped IPv4 addresses
// So that IPv4 addresses are consistent between separate-socket and dual-stack socket modes.
address = (addr.Item1.MapToIPv4(), addr.Item2 - 96);
}
Id = id;
UserId = userId;
Address = address;
HWId = hwId;
BanTime = banTime;
ExpirationTime = expirationTime;
RoundId = roundId;
PlaytimeAtNote = playtimeAtNote;
2022-02-21 14:11:39 -08:00
Reason = reason;
Severity = severity;
2022-02-21 14:11:39 -08:00
BanningAdmin = banningAdmin;
Unban = unban;
Role = role;
ServerName = serverName;
2022-02-21 14:11:39 -08:00
}
}