using Content.Shared.StationRecords;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
namespace Content.Shared.Access.Components;
///
/// Stores access levels necessary to "use" an entity
/// and allows checking if something or somebody is authorized with these access levels.
///
[RegisterComponent, NetworkedComponent]
public sealed partial class AccessReaderComponent : Component
{
///
/// Whether or not the accessreader is enabled.
/// If not, it will always let people through.
///
[DataField]
public bool Enabled = true;
///
/// The set of tags that will automatically deny an allowed check, if any of them are present.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField(customTypeSerializer: typeof(PrototypeIdHashSetSerializer))]
public HashSet DenyTags = new();
///
/// 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.
///
[DataField("access")] [ViewVariables(VVAccess.ReadWrite)]
public List> AccessLists = new();
///
/// A list of s that grant access. Only a single matching key is required tp gaim
/// access.
///
[DataField]
public HashSet AccessKeys = new();
///
/// If specified, then this access reader will instead pull access requirements from entities contained in the
/// given container.
///
///
/// This effectively causes , , and to be
/// ignored, though is still respected. Access is denied if there are no valid entities or
/// they all deny access.
///
[DataField]
public string? ContainerAccessProvider;
///
/// A list of past authentications
///
[DataField]
public Queue AccessLog = new();
///
/// A limit on the max size of
///
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int AccessLogLimit = 20;
///
/// Whether or not emag interactions have an effect on this.
///
[DataField]
public bool BreakOnEmag = true;
}
[DataDefinition, Serializable, NetSerializable]
public readonly partial record struct AccessRecord(
[property: DataField, ViewVariables(VVAccess.ReadWrite)]
TimeSpan AccessTime,
[property: DataField, ViewVariables(VVAccess.ReadWrite)]
string Accessor)
{
public AccessRecord() : this(TimeSpan.Zero, string.Empty)
{
}
}
[Serializable, NetSerializable]
public sealed class AccessReaderComponentState : ComponentState
{
public bool Enabled;
public HashSet DenyTags;
public List> AccessLists;
public List<(NetEntity, uint)> AccessKeys;
public Queue AccessLog;
public int AccessLogLimit;
public AccessReaderComponentState(bool enabled, HashSet denyTags, List> accessLists, List<(NetEntity, uint)> accessKeys, Queue accessLog, int accessLogLimit)
{
Enabled = enabled;
DenyTags = denyTags;
AccessLists = accessLists;
AccessKeys = accessKeys;
AccessLog = accessLog;
AccessLogLimit = accessLogLimit;
}
}