1
0

AccessReaderComponent.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Content.Shared.StationRecords;
  2. using Robust.Shared.GameStates;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Serialization;
  5. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
  6. namespace Content.Shared.Access.Components;
  7. /// <summary>
  8. /// Stores access levels necessary to "use" an entity
  9. /// and allows checking if something or somebody is authorized with these access levels.
  10. /// </summary>
  11. [RegisterComponent, NetworkedComponent]
  12. public sealed partial class AccessReaderComponent : Component
  13. {
  14. /// <summary>
  15. /// Whether or not the accessreader is enabled.
  16. /// If not, it will always let people through.
  17. /// </summary>
  18. [DataField]
  19. public bool Enabled = true;
  20. /// <summary>
  21. /// The set of tags that will automatically deny an allowed check, if any of them are present.
  22. /// </summary>
  23. [ViewVariables(VVAccess.ReadWrite)]
  24. [DataField]
  25. public HashSet<ProtoId<AccessLevelPrototype>> DenyTags = new();
  26. /// <summary>
  27. /// List of access groups that grant access to this reader. Only a single matching group is required to gain access.
  28. /// A group matches if it is a subset of the set being checked against.
  29. /// </summary>
  30. [DataField("access")] [ViewVariables(VVAccess.ReadWrite)]
  31. public List<HashSet<ProtoId<AccessLevelPrototype>>> AccessLists = new();
  32. /// <summary>
  33. /// A list of <see cref="StationRecordKey"/>s that grant access. Only a single matching key is required to gain
  34. /// access.
  35. /// </summary>
  36. [DataField]
  37. public HashSet<StationRecordKey> AccessKeys = new();
  38. /// <summary>
  39. /// If specified, then this access reader will instead pull access requirements from entities contained in the
  40. /// given container.
  41. /// </summary>
  42. /// <remarks>
  43. /// This effectively causes <see cref="DenyTags"/>, <see cref="AccessLists"/>, and <see cref="AccessKeys"/> to be
  44. /// ignored, though <see cref="Enabled"/> is still respected. Access is denied if there are no valid entities or
  45. /// they all deny access.
  46. /// </remarks>
  47. [DataField]
  48. public string? ContainerAccessProvider;
  49. /// <summary>
  50. /// A list of past authentications
  51. /// </summary>
  52. [DataField]
  53. public Queue<AccessRecord> AccessLog = new();
  54. /// <summary>
  55. /// A limit on the max size of <see cref="AccessLog"/>
  56. /// </summary>
  57. [DataField, ViewVariables(VVAccess.ReadWrite)]
  58. public int AccessLogLimit = 20;
  59. /// <summary>
  60. /// If true logging on successful access uses will be disabled.
  61. /// Can be set by LOG wire.
  62. /// </summary>
  63. [DataField]
  64. public bool LoggingDisabled;
  65. /// <summary>
  66. /// Whether or not emag interactions have an effect on this.
  67. /// </summary>
  68. [DataField]
  69. public bool BreakOnAccessBreaker = true;
  70. }
  71. [DataDefinition, Serializable, NetSerializable]
  72. public readonly partial record struct AccessRecord(
  73. [property: DataField, ViewVariables(VVAccess.ReadWrite)]
  74. TimeSpan AccessTime,
  75. [property: DataField, ViewVariables(VVAccess.ReadWrite)]
  76. string Accessor)
  77. {
  78. public AccessRecord() : this(TimeSpan.Zero, string.Empty)
  79. {
  80. }
  81. }
  82. [Serializable, NetSerializable]
  83. public sealed class AccessReaderComponentState : ComponentState
  84. {
  85. public bool Enabled;
  86. public HashSet<ProtoId<AccessLevelPrototype>> DenyTags;
  87. public List<HashSet<ProtoId<AccessLevelPrototype>>> AccessLists;
  88. public List<(NetEntity, uint)> AccessKeys;
  89. public Queue<AccessRecord> AccessLog;
  90. public int AccessLogLimit;
  91. public AccessReaderComponentState(bool enabled, HashSet<ProtoId<AccessLevelPrototype>> denyTags, List<HashSet<ProtoId<AccessLevelPrototype>>> accessLists, List<(NetEntity, uint)> accessKeys, Queue<AccessRecord> accessLog, int accessLogLimit)
  92. {
  93. Enabled = enabled;
  94. DenyTags = denyTags;
  95. AccessLists = accessLists;
  96. AccessKeys = accessKeys;
  97. AccessLog = accessLog;
  98. AccessLogLimit = accessLogLimit;
  99. }
  100. }
  101. public sealed class AccessReaderConfigurationChangedEvent : EntityEventArgs
  102. {
  103. public AccessReaderConfigurationChangedEvent()
  104. {
  105. }
  106. }