1
0

ServerRoleBanDef.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Net;
  2. using Content.Shared.Database;
  3. using Robust.Shared.Network;
  4. namespace Content.Server.Database;
  5. public sealed class ServerRoleBanDef
  6. {
  7. public int? Id { get; }
  8. public NetUserId? UserId { get; }
  9. public (IPAddress address, int cidrMask)? Address { get; }
  10. public ImmutableTypedHwid? HWId { get; }
  11. public DateTimeOffset BanTime { get; }
  12. public DateTimeOffset? ExpirationTime { get; }
  13. public int? RoundId { get; }
  14. public TimeSpan PlaytimeAtNote { get; }
  15. public string Reason { get; }
  16. public NoteSeverity Severity { get; set; }
  17. public NetUserId? BanningAdmin { get; }
  18. public ServerRoleUnbanDef? Unban { get; }
  19. public string Role { get; }
  20. public ServerRoleBanDef(
  21. int? id,
  22. NetUserId? userId,
  23. (IPAddress, int)? address,
  24. ImmutableTypedHwid? hwId,
  25. DateTimeOffset banTime,
  26. DateTimeOffset? expirationTime,
  27. int? roundId,
  28. TimeSpan playtimeAtNote,
  29. string reason,
  30. NoteSeverity severity,
  31. NetUserId? banningAdmin,
  32. ServerRoleUnbanDef? unban,
  33. string role)
  34. {
  35. if (userId == null && address == null && hwId == null)
  36. {
  37. throw new ArgumentException("Must have at least one of banned user, banned address or hardware ID");
  38. }
  39. if (address is {} addr && addr.Item1.IsIPv4MappedToIPv6)
  40. {
  41. // Fix IPv6-mapped IPv4 addresses
  42. // So that IPv4 addresses are consistent between separate-socket and dual-stack socket modes.
  43. address = (addr.Item1.MapToIPv4(), addr.Item2 - 96);
  44. }
  45. Id = id;
  46. UserId = userId;
  47. Address = address;
  48. HWId = hwId;
  49. BanTime = banTime;
  50. ExpirationTime = expirationTime;
  51. RoundId = roundId;
  52. PlaytimeAtNote = playtimeAtNote;
  53. Reason = reason;
  54. Severity = severity;
  55. BanningAdmin = banningAdmin;
  56. Unban = unban;
  57. Role = role;
  58. }
  59. }