Files
tbd-station-14/Content.Shared/Access/Components/AccessReaderComponent.cs
c4llv07e 64bb8dbdd5 Add door electronics access configuration menu (#17778)
* Add door electronics configuration menu

* Use file-scoped namespaces

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Open door electronics configuration menu only with network configurator

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Doors will now try to move their AccessReaderComponent to their door electronics when the map is initialized

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Make the access list in the id card computer a separate control

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Fix merge conflict

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Remove DoorElectronics tag

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Integrate doors with #17927

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Move door electornics ui stuff to the right place

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Some review fixes

Signed-off-by: c4llv07e <kseandi@gmail.com>

* More fixes

Signed-off-by: c4llv07e <kseandi@gmail.com>

* review fix

Signed-off-by: c4llv07e <kseandi@gmail.com>

* move all accesses from airlock prototypes to door electronics

Signed-off-by: c4llv07e <kseandi@gmail.com>

* rework door electronics config access list

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Remove Linq from the door electronics user interface

* [WIP] Add EntityWhitelist to the activatable ui component

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Better interaction system

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Refactor

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Fix some door electronics not working without AccessReaderComponent

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Move AccessReaderComponent update code to the AccessReaderSystem

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Remove unnecesary newlines in the door access prototypes

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Remove unused variables in access level control

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Remove unnecessary method from the door electronics configuration menu

Signed-off-by: c4llv07e <kseandi@gmail.com>

* [WIP] change access type from string to ProtoId<AccessLevelPrototype>

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Remove unused methods

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Newline fix

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Restored to a functional state

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Fix access configurator not working with door electronics AccessReaderComponent

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Replace all string access fields with ProtoId

Signed-off-by: c4llv07e <kseandi@gmail.com>

* move access level control initialization into Populate method

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Review

---------

Signed-off-by: c4llv07e <kseandi@gmail.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2024-04-01 17:06:13 +11:00

119 lines
3.9 KiB
C#

using Content.Shared.StationRecords;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
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.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class AccessReaderComponent : Component
{
/// <summary>
/// Whether or not the accessreader is enabled.
/// If not, it will always let people through.
/// </summary>
[DataField]
public bool Enabled = true;
/// <summary>
/// The set of tags that will automatically deny an allowed check, if any of them are present.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public HashSet<ProtoId<AccessLevelPrototype>> 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")] [ViewVariables(VVAccess.ReadWrite)]
public List<HashSet<ProtoId<AccessLevelPrototype>>> AccessLists = new();
/// <summary>
/// A list of <see cref="StationRecordKey"/>s that grant access. Only a single matching key is required to gain
/// access.
/// </summary>
[DataField]
public HashSet<StationRecordKey> AccessKeys = new();
/// <summary>
/// If specified, then this access reader will instead pull access requirements from entities contained in the
/// given container.
/// </summary>
/// <remarks>
/// This effectively causes <see cref="DenyTags"/>, <see cref="AccessLists"/>, and <see cref="AccessKeys"/> to be
/// ignored, though <see cref="Enabled"/> is still respected. Access is denied if there are no valid entities or
/// they all deny access.
/// </remarks>
[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;
/// <summary>
/// Whether or not emag interactions have an effect on this.
/// </summary>
[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<ProtoId<AccessLevelPrototype>> DenyTags;
public List<HashSet<ProtoId<AccessLevelPrototype>>> AccessLists;
public List<(NetEntity, uint)> AccessKeys;
public Queue<AccessRecord> AccessLog;
public int AccessLogLimit;
public AccessReaderComponentState(bool enabled, HashSet<ProtoId<AccessLevelPrototype>> denyTags, List<HashSet<ProtoId<AccessLevelPrototype>>> accessLists, List<(NetEntity, uint)> accessKeys, Queue<AccessRecord> accessLog, int accessLogLimit)
{
Enabled = enabled;
DenyTags = denyTags;
AccessLists = accessLists;
AccessKeys = accessKeys;
AccessLog = accessLog;
AccessLogLimit = accessLogLimit;
}
}
public sealed class AccessReaderConfigurationChangedEvent : EntityEventArgs
{
public AccessReaderConfigurationChangedEvent()
{
}
}