Add access logs (IC ones) (#17810)
This commit is contained in:
@@ -3,58 +3,57 @@ using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Shared.Access.Components
|
||||
namespace Content.Shared.Access.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Simple mutable access provider found on ID cards and such.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedAccessSystem))]
|
||||
[AutoGenerateComponentState]
|
||||
public sealed partial class AccessComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple mutable access provider found on ID cards and such.
|
||||
/// True if the access provider is enabled and can grant access.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedAccessSystem))]
|
||||
[AutoGenerateComponentState]
|
||||
public sealed partial class AccessComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// True if the access provider is enabled and can grant access.
|
||||
/// </summary>
|
||||
[DataField("enabled"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
public bool Enabled = true;
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
public bool Enabled = true;
|
||||
|
||||
[DataField("tags", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessLevelPrototype>))]
|
||||
[Access(typeof(SharedAccessSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
|
||||
[AutoNetworkedField]
|
||||
public HashSet<string> Tags = new();
|
||||
|
||||
/// <summary>
|
||||
/// Access Groups. These are added to the tags during map init. After map init this will have no effect.
|
||||
/// </summary>
|
||||
[DataField("groups", readOnly: true, customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessGroupPrototype>))]
|
||||
[AutoNetworkedField]
|
||||
public HashSet<string> Groups = new();
|
||||
}
|
||||
[DataField(customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessLevelPrototype>))]
|
||||
[Access(typeof(SharedAccessSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
|
||||
[AutoNetworkedField]
|
||||
public HashSet<string> Tags = new();
|
||||
|
||||
/// <summary>
|
||||
/// Event raised on an entity to find additional entities which provide access.
|
||||
/// Access Groups. These are added to the tags during map init. After map init this will have no effect.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public struct GetAdditionalAccessEvent
|
||||
[DataField(readOnly: true, customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessGroupPrototype>))]
|
||||
[AutoNetworkedField]
|
||||
public HashSet<string> Groups = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event raised on an entity to find additional entities which provide access.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public struct GetAdditionalAccessEvent
|
||||
{
|
||||
public HashSet<EntityUid> Entities = new();
|
||||
|
||||
public GetAdditionalAccessEvent()
|
||||
{
|
||||
public HashSet<EntityUid> Entities = new();
|
||||
|
||||
public GetAdditionalAccessEvent()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public record struct GetAccessTagsEvent(HashSet<string> Tags, IPrototypeManager PrototypeManager)
|
||||
{
|
||||
public void AddGroup(string group)
|
||||
{
|
||||
if (!PrototypeManager.TryIndex<AccessGroupPrototype>(group, out var groupPrototype))
|
||||
return;
|
||||
|
||||
Tags.UnionWith(groupPrototype.Tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public record struct GetAccessTagsEvent(HashSet<string> Tags, IPrototypeManager PrototypeManager)
|
||||
{
|
||||
public void AddGroup(string group)
|
||||
{
|
||||
if (!PrototypeManager.TryIndex<AccessGroupPrototype>(group, out var groupPrototype))
|
||||
return;
|
||||
|
||||
Tags.UnionWith(groupPrototype.Tags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,4 +34,10 @@ public sealed partial class IdCardComponent : Component
|
||||
[DataField("jobDepartments")]
|
||||
[AutoNetworkedField]
|
||||
public List<LocId> JobDepartments = new();
|
||||
|
||||
/// <summary>
|
||||
/// Determines if accesses from this card should be logged by <see cref="AccessReaderComponent"/>
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool BypassLogging;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user