Add access logs (IC ones) (#17810)

This commit is contained in:
Chief-Engineer
2023-12-26 16:24:53 -06:00
committed by GitHub
parent 4d42d00194
commit 476ea14e8a
28 changed files with 438 additions and 81 deletions

View File

@@ -6,8 +6,8 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
namespace Content.Shared.Access.Components;
/// <summary>
/// Stores access levels necessary to "use" an entity
/// and allows checking if something or somebody is authorized with these access levels.
/// Stores access levels necessary to "use" an entity
/// and allows checking if something or somebody is authorized with these access levels.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class AccessReaderComponent : Component
@@ -16,27 +16,28 @@ public sealed partial class AccessReaderComponent : Component
/// Whether or not the accessreader is enabled.
/// If not, it will always let people through.
/// </summary>
[DataField("enabled")]
[DataField]
public bool Enabled = true;
/// <summary>
/// The set of tags that will automatically deny an allowed check, if any of them are present.
/// The set of tags that will automatically deny an allowed check, if any of them are present.
/// </summary>
[DataField("denyTags", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessLevelPrototype>))]
[ViewVariables(VVAccess.ReadWrite)]
[DataField(customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessLevelPrototype>))]
public HashSet<string> DenyTags = new();
/// <summary>
/// List of access groups that grant access to this reader. Only a single matching group is required to gain access.
/// A group matches if it is a subset of the set being checked against.
/// </summary>
[DataField("access")]
[DataField("access")] [ViewVariables(VVAccess.ReadWrite)]
public List<HashSet<string>> AccessLists = new();
/// <summary>
/// A list of <see cref="StationRecordKey"/>s that grant access. Only a single matching key is required tp gaim
/// access.
/// </summary>
[DataField("accessKeys")]
[DataField]
public HashSet<StationRecordKey> AccessKeys = new();
/// <summary>
@@ -48,10 +49,25 @@ public sealed partial class AccessReaderComponent : Component
/// ignored, though <see cref="Enabled"/> is still respected. Access is denied if there are no valid entities or
/// they all deny access.
/// </remarks>
[DataField("containerAccessProvider")]
[DataField]
public string? ContainerAccessProvider;
/// <summary>
/// A list of past authentications
/// </summary>
[DataField]
public Queue<AccessRecord> AccessLog = new();
/// <summary>
/// A limit on the max size of <see cref="AccessLog"/>
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int AccessLogLimit = 20;
}
[Serializable, NetSerializable]
public record struct AccessRecord(TimeSpan AccessTime, string Accessor);
[Serializable, NetSerializable]
public sealed class AccessReaderComponentState : ComponentState
{
@@ -63,11 +79,17 @@ public sealed class AccessReaderComponentState : ComponentState
public List<(NetEntity, uint)> AccessKeys;
public AccessReaderComponentState(bool enabled, HashSet<string> denyTags, List<HashSet<string>> accessLists, List<(NetEntity, uint)> accessKeys)
public Queue<AccessRecord> AccessLog;
public int AccessLogLimit;
public AccessReaderComponentState(bool enabled, HashSet<string> denyTags, List<HashSet<string>> accessLists, List<(NetEntity, uint)> accessKeys, Queue<AccessRecord> accessLog, int accessLogLimit)
{
Enabled = enabled;
DenyTags = denyTags;
AccessLists = accessLists;
AccessKeys = accessKeys;
AccessLog = accessLog;
AccessLogLimit = accessLogLimit;
}
}