Move Access & AccessReader to shared. (#5798)

* git mv

* Move Access Component & system.

- Name space changes
- Rename AccessReader to AccessReaderComponent
- Also need an abstract TryGetSlot function for SharedInventoryComponent

* better TryGetSlot

* Ah yes, tests exist.
This commit is contained in:
Leon Friedrich
2021-12-26 17:07:28 +13:00
committed by GitHub
parent 32d752bfa6
commit b675bdb789
27 changed files with 90 additions and 81 deletions

View File

@@ -46,8 +46,6 @@ namespace Content.Client.Entry
"ResearchServer", "ResearchServer",
"ResearchPointSource", "ResearchPointSource",
"ResearchClient", "ResearchClient",
"Access",
"AccessReader",
"IdCardConsole", "IdCardConsole",
"Airlock", "Airlock",
"ThermalRegulator", "ThermalRegulator",

View File

@@ -228,9 +228,17 @@ namespace Content.Client.Inventory
_playerAttached = true; _playerAttached = true;
} }
public bool TryGetSlot(Slots slot, [NotNullWhen(true)] out EntityUid item) public override bool TryGetSlot(Slots slot, [NotNullWhen(true)] out EntityUid? item)
{ {
return _slots.TryGetValue(slot, out item); // dict TryGetValue uses default EntityUid, not null.
if (!_slots.ContainsKey(slot))
{
item = null;
return false;
}
item = _slots[slot];
return item != null;
} }
public bool TryFindItemSlots(EntityUid item, [NotNullWhen(true)] out Slots? slots) public bool TryFindItemSlots(EntityUid item, [NotNullWhen(true)] out Slots? slots)

View File

@@ -35,9 +35,9 @@ namespace Content.Client.Inventory
// jesus christ, this is duplicated to server/client, should really just be shared.. // jesus christ, this is duplicated to server/client, should really just be shared..
private void OnSlipAttemptEvent(EntityUid uid, ClientInventoryComponent component, SlipAttemptEvent args) private void OnSlipAttemptEvent(EntityUid uid, ClientInventoryComponent component, SlipAttemptEvent args)
{ {
if (component.TryGetSlot(EquipmentSlotDefines.Slots.SHOES, out EntityUid shoes)) if (component.TryGetSlot(EquipmentSlotDefines.Slots.SHOES, out EntityUid? shoes))
{ {
RaiseLocalEvent(shoes, args, false); RaiseLocalEvent(shoes.Value, args, false);
} }
} }

View File

@@ -203,7 +203,7 @@ namespace Content.Client.Inventory
if (!Owner.TryGetSlot(slot, out var item)) if (!Owner.TryGetSlot(slot, out var item))
return; return;
if (!_itemSlotManager.OnButtonPressed(args, item)) if (!_itemSlotManager.OnButtonPressed(args, item.Value))
base.HandleInventoryKeybind(args, slot); base.HandleInventoryKeybind(args, slot);
} }
@@ -232,7 +232,7 @@ namespace Content.Client.Inventory
if (Owner.TryGetSlot(slot, out var entity)) if (Owner.TryGetSlot(slot, out var entity))
{ {
AddToSlot(slot, entity); AddToSlot(slot, entity.Value);
} }
} }
} }

View File

@@ -1,15 +1,15 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.IntegrationTests; using Content.IntegrationTests;
using Content.Server.Access.Components; using Content.Shared.Access.Components;
using Content.Server.Access.Systems; using Content.Shared.Access.Systems;
using NUnit.Framework; using NUnit.Framework;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
namespace Content.Tests.Server.GameObjects.Components.Access namespace Content.Tests.Server.GameObjects.Components.Access
{ {
[TestFixture] [TestFixture]
[TestOf(typeof(AccessReader))] [TestOf(typeof(AccessReaderComponent))]
public class AccessReaderTest : ContentIntegrationTest public class AccessReaderTest : ContentIntegrationTest
{ {
[Test] [Test]
@@ -21,13 +21,13 @@ namespace Content.Tests.Server.GameObjects.Components.Access
var system = EntitySystem.Get<AccessReaderSystem>(); var system = EntitySystem.Get<AccessReaderSystem>();
// test empty // test empty
var reader = new AccessReader(); var reader = new AccessReaderComponent();
Assert.That(system.IsAllowed(reader, new[] { "Foo" }), Is.True); Assert.That(system.IsAllowed(reader, new[] { "Foo" }), Is.True);
Assert.That(system.IsAllowed(reader, new[] { "Bar" }), Is.True); Assert.That(system.IsAllowed(reader, new[] { "Bar" }), Is.True);
Assert.That(system.IsAllowed(reader, new string[] { }), Is.True); Assert.That(system.IsAllowed(reader, new string[] { }), Is.True);
// test deny // test deny
reader = new AccessReader(); reader = new AccessReaderComponent();
reader.DenyTags.Add("A"); reader.DenyTags.Add("A");
Assert.That(system.IsAllowed(reader, new[] { "Foo" }), Is.True); Assert.That(system.IsAllowed(reader, new[] { "Foo" }), Is.True);
Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.False); Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.False);
@@ -35,7 +35,7 @@ namespace Content.Tests.Server.GameObjects.Components.Access
Assert.That(system.IsAllowed(reader, new string[] { }), Is.True); Assert.That(system.IsAllowed(reader, new string[] { }), Is.True);
// test one list // test one list
reader = new AccessReader(); reader = new AccessReaderComponent();
reader.AccessLists.Add(new HashSet<string> { "A" }); reader.AccessLists.Add(new HashSet<string> { "A" });
Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.True); Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.True);
Assert.That(system.IsAllowed(reader, new[] { "B" }), Is.False); Assert.That(system.IsAllowed(reader, new[] { "B" }), Is.False);
@@ -43,7 +43,7 @@ namespace Content.Tests.Server.GameObjects.Components.Access
Assert.That(system.IsAllowed(reader, new string[] { }), Is.False); Assert.That(system.IsAllowed(reader, new string[] { }), Is.False);
// test one list - two items // test one list - two items
reader = new AccessReader(); reader = new AccessReaderComponent();
reader.AccessLists.Add(new HashSet<string> { "A", "B" }); reader.AccessLists.Add(new HashSet<string> { "A", "B" });
Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.False); Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.False);
Assert.That(system.IsAllowed(reader, new[] { "B" }), Is.False); Assert.That(system.IsAllowed(reader, new[] { "B" }), Is.False);
@@ -51,7 +51,7 @@ namespace Content.Tests.Server.GameObjects.Components.Access
Assert.That(system.IsAllowed(reader, new string[] { }), Is.False); Assert.That(system.IsAllowed(reader, new string[] { }), Is.False);
// test two list // test two list
reader = new AccessReader(); reader = new AccessReaderComponent();
reader.AccessLists.Add(new HashSet<string> { "A" }); reader.AccessLists.Add(new HashSet<string> { "A" });
reader.AccessLists.Add(new HashSet<string> { "B", "C" }); reader.AccessLists.Add(new HashSet<string> { "B", "C" });
Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.True); Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.True);
@@ -62,7 +62,7 @@ namespace Content.Tests.Server.GameObjects.Components.Access
Assert.That(system.IsAllowed(reader, new string[] { }), Is.False); Assert.That(system.IsAllowed(reader, new string[] { }), Is.False);
// test deny list // test deny list
reader = new AccessReader(); reader = new AccessReaderComponent();
reader.AccessLists.Add(new HashSet<string> { "A" }); reader.AccessLists.Add(new HashSet<string> { "A" });
reader.DenyTags.Add("B"); reader.DenyTags.Add("B");
Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.True); Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.True);

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.Access.Systems; using Content.Server.Access.Systems;
using Content.Server.AI.Pathfinding.Pathfinders; using Content.Server.AI.Pathfinding.Pathfinders;
using Content.Shared.Access.Systems;
using Content.Shared.AI; using Content.Shared.AI;
using Content.Shared.GameTicking; using Content.Shared.GameTicking;
using JetBrains.Annotations; using JetBrains.Annotations;

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.Access.Systems;
using Content.Server.AI.Components; using Content.Server.AI.Components;
using Content.Shared.Access.Systems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Physics; using Robust.Shared.Physics;

View File

@@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.Access.Systems;
using Content.Server.AI.Pathfinding.Accessible; using Content.Server.AI.Pathfinding.Accessible;
using Content.Server.AI.Pathfinding.Pathfinders; using Content.Server.AI.Pathfinding.Pathfinders;
using Content.Shared.Access.Systems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;

View File

@@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.Access.Components;
using Content.Server.Doors.Components; using Content.Server.Doors.Components;
using Content.Shared.Access.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
@@ -32,8 +32,8 @@ namespace Content.Server.AI.Pathfinding
/// The entities on this tile that require access to traverse /// The entities on this tile that require access to traverse
/// </summary> /// </summary>
/// We don't store the ICollection, at least for now, as we'd need to replicate the access code here /// We don't store the ICollection, at least for now, as we'd need to replicate the access code here
public IReadOnlyCollection<AccessReader> AccessReaders => _accessReaders.Values; public IReadOnlyCollection<AccessReaderComponent> AccessReaders => _accessReaders.Values;
private readonly Dictionary<EntityUid, AccessReader> _accessReaders = new(0); private readonly Dictionary<EntityUid, AccessReaderComponent> _accessReaders = new(0);
public PathfindingNode(PathfindingChunk parent, TileRef tileRef) public PathfindingNode(PathfindingChunk parent, TileRef tileRef)
{ {
@@ -268,7 +268,7 @@ namespace Content.Server.AI.Pathfinding
// TODO: Check for powered I think (also need an event for when it's depowered // TODO: Check for powered I think (also need an event for when it's depowered
// AccessReader calls this whenever opening / closing but it can seem to get called multiple times // AccessReader calls this whenever opening / closing but it can seem to get called multiple times
// Which may or may not be intended? // Which may or may not be intended?
if (entMan.TryGetComponent(entity, out AccessReader? accessReader) && !_accessReaders.ContainsKey(entity)) if (entMan.TryGetComponent(entity, out AccessReaderComponent? accessReader) && !_accessReaders.ContainsKey(entity))
{ {
_accessReaders.Add(entity, accessReader); _accessReaders.Add(entity, accessReader);
ParentChunk.Dirty(); ParentChunk.Dirty();

View File

@@ -2,10 +2,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using Content.Server.Access; using Content.Server.Access;
using Content.Server.Access.Systems;
using Content.Server.AI.Pathfinding.Pathfinders; using Content.Server.AI.Pathfinding.Pathfinders;
using Content.Server.CPUJob.JobQueues; using Content.Server.CPUJob.JobQueues;
using Content.Server.CPUJob.JobQueues.Queues; using Content.Server.CPUJob.JobQueues.Queues;
using Content.Shared.Access.Systems;
using Content.Shared.GameTicking; using Content.Shared.GameTicking;
using Content.Shared.Physics; using Content.Shared.Physics;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;

View File

@@ -3,11 +3,11 @@ using System.Collections.Generic;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Access.Systems;
using Content.Server.AI.Components; using Content.Server.AI.Components;
using Content.Server.AI.Pathfinding; using Content.Server.AI.Pathfinding;
using Content.Server.AI.Pathfinding.Pathfinders; using Content.Server.AI.Pathfinding.Pathfinders;
using Content.Server.CPUJob.JobQueues; using Content.Server.CPUJob.JobQueues;
using Content.Shared.Access.Systems;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Interaction.Helpers; using Content.Shared.Interaction.Helpers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;

View File

@@ -5,6 +5,7 @@ using Content.Server.Power.Components;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Shared.Access; using Content.Shared.Access;
using Content.Shared.Access.Components; using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -29,7 +30,7 @@ namespace Content.Server.Access.Components
{ {
base.Initialize(); base.Initialize();
Owner.EnsureComponentWarn<AccessReader>(); Owner.EnsureComponentWarn<AccessReaderComponent>();
Owner.EnsureComponentWarn<ServerUserInterfaceComponent>(); Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
if (UserInterface != null) if (UserInterface != null)
@@ -66,11 +67,11 @@ namespace Content.Server.Access.Components
} }
/// <summary> /// <summary>
/// Returns true if there is an ID in <see cref="PrivilegedIdSlot"/> and said ID satisfies the requirements of <see cref="AccessReader"/>. /// Returns true if there is an ID in <see cref="PrivilegedIdSlot"/> and said ID satisfies the requirements of <see cref="AccessReaderComponent"/>.
/// </summary> /// </summary>
private bool PrivilegedIdIsAuthorized() private bool PrivilegedIdIsAuthorized()
{ {
if (!_entities.TryGetComponent(Owner, out AccessReader? reader)) if (!_entities.TryGetComponent(Owner, out AccessReaderComponent? reader))
{ {
return true; return true;
} }

View File

@@ -1,4 +1,5 @@
using Content.Server.Access.Components; using Content.Server.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Roles; using Content.Shared.Roles;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;

View File

@@ -1,8 +1,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Content.Server.Access.Components;
using Content.Server.Access.Systems; using Content.Server.Access.Systems;
using Content.Server.Cargo.Components; using Content.Server.Cargo.Components;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Cargo; using Content.Shared.Cargo;
using Content.Shared.GameTicking; using Content.Shared.GameTicking;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -177,7 +178,7 @@ namespace Content.Server.Cargo
return true; return true;
} }
public bool ApproveOrder(EntityUid uid, EntityUid approver, int id, int orderNumber, AccessReader? reader = null) public bool ApproveOrder(EntityUid uid, EntityUid approver, int id, int orderNumber, AccessReaderComponent? reader = null)
{ {
// does the approver have permission to approve orders? // does the approver have permission to approve orders?
if (Resolve(uid, ref reader) && !_accessReaderSystem.IsAllowed(reader, approver)) if (Resolve(uid, ref reader) && !_accessReaderSystem.IsAllowed(reader, approver))

View File

@@ -3,8 +3,6 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Access; using Content.Server.Access;
using Content.Server.Access.Components;
using Content.Server.Access.Systems;
using Content.Server.Atmos.Components; using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.EntitySystems;
using Content.Server.Construction; using Content.Server.Construction;
@@ -13,6 +11,8 @@ using Content.Server.Hands.Components;
using Content.Server.Stunnable; using Content.Server.Stunnable;
using Content.Server.Tools; using Content.Server.Tools;
using Content.Server.Tools.Components; using Content.Server.Tools.Components;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Doors; using Content.Shared.Doors;
using Content.Shared.Interaction; using Content.Shared.Interaction;
@@ -310,7 +310,7 @@ namespace Content.Server.Doors.Components
return false; return false;
} }
if (!_entMan.TryGetComponent(Owner, out AccessReader? access)) if (!_entMan.TryGetComponent(Owner, out AccessReaderComponent? access))
{ {
return true; return true;
} }
@@ -334,7 +334,7 @@ namespace Content.Server.Doors.Components
/// </summary> /// </summary>
private bool HasAccessType(string accessType) private bool HasAccessType(string accessType)
{ {
if (_entMan.TryGetComponent(Owner, out AccessReader? access)) if (_entMan.TryGetComponent(Owner, out AccessReaderComponent? access))
{ {
return access.AccessLists.Any(list => list.Contains(accessType)); return access.AccessLists.Any(list => list.Contains(accessType));
} }
@@ -445,7 +445,7 @@ namespace Content.Server.Doors.Components
return false; return false;
} }
if (!_entMan.TryGetComponent(Owner, out AccessReader? access)) if (!_entMan.TryGetComponent(Owner, out AccessReaderComponent? access))
{ {
return true; return true;
} }

View File

@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Content.Server.Access.Components;
using Content.Server.Access.Systems; using Content.Server.Access.Systems;
using Content.Server.Ghost; using Content.Server.Ghost;
using Content.Server.Ghost.Components; using Content.Server.Ghost.Components;
@@ -15,6 +14,7 @@ using Content.Server.Roles;
using Content.Server.Spawners.Components; using Content.Server.Spawners.Components;
using Content.Server.Speech.Components; using Content.Server.Speech.Components;
using Content.Server.Station; using Content.Server.Station;
using Content.Shared.Access.Components;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
using Content.Shared.CharacterAppearance.Systems; using Content.Shared.CharacterAppearance.Systems;
using Content.Shared.Database; using Content.Shared.Database;

View File

@@ -560,5 +560,17 @@ namespace Content.Server.Inventory.Components
return false; return false;
} }
public override bool TryGetSlot(Slots slot, [NotNullWhen(true)] out EntityUid? item)
{
if (_slotContainers.TryGetValue(slot, out var container))
{
item = container.ContainedEntity;
return item != null;
}
item = null;
return false;
}
} }
} }

View File

@@ -1,6 +1,8 @@
using Content.Server.Access.Components; using Content.Server.Access.Components;
using Content.Server.Access.Systems; using Content.Server.Access.Systems;
using Content.Server.Storage.Components; using Content.Server.Storage.Components;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Popups; using Content.Shared.Popups;
@@ -144,7 +146,7 @@ namespace Content.Server.Lock
return true; return true;
} }
private bool HasUserAccess(EntityUid uid, EntityUid user, AccessReader? reader = null, bool quiet = true) private bool HasUserAccess(EntityUid uid, EntityUid user, AccessReaderComponent? reader = null, bool quiet = true)
{ {
// Not having an AccessComponent means you get free access. woo! // Not having an AccessComponent means you get free access. woo!
if (!Resolve(uid, ref reader)) if (!Resolve(uid, ref reader))

View File

@@ -1,8 +1,8 @@
using System; using System;
using Content.Server.Access.Components;
using Content.Server.Access.Systems;
using Content.Server.Power.NodeGroups; using Content.Server.Power.NodeGroups;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.APC; using Content.Shared.APC;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Popups; using Content.Shared.Popups;
@@ -59,14 +59,14 @@ namespace Content.Server.Power.Components
public BatteryComponent? Battery => _entMan.TryGetComponent(Owner, out BatteryComponent? batteryComponent) ? batteryComponent : null; public BatteryComponent? Battery => _entMan.TryGetComponent(Owner, out BatteryComponent? batteryComponent) ? batteryComponent : null;
[ComponentDependency] private AccessReader? _accessReader = null; [ComponentDependency] private AccessReaderComponent? _accessReader = null;
protected override void Initialize() protected override void Initialize()
{ {
base.Initialize(); base.Initialize();
Owner.EnsureComponentWarn<ServerUserInterfaceComponent>(); Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
Owner.EnsureComponentWarn<AccessReader>(); Owner.EnsureComponentWarn<AccessReaderComponent>();
if (UserInterface != null) if (UserInterface != null)
{ {

View File

@@ -1,12 +1,11 @@
using System.Linq; using System.Linq;
using Content.Server.Access.Components;
using Content.Server.Access.Systems;
using Content.Server.GameTicking; using Content.Server.GameTicking;
using Content.Server.Hands.Components; using Content.Server.Hands.Components;
using Content.Server.Inventory.Components; using Content.Server.Inventory.Components;
using Content.Server.Items; using Content.Server.Items;
using Content.Shared.Access; using Content.Shared.Access;
using Content.Shared.Access.Components; using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.PDA; using Content.Shared.PDA;
using Content.Shared.Sandbox; using Content.Shared.Sandbox;

View File

@@ -1,9 +1,8 @@
using System; using System;
using System.Threading; using System.Threading;
using Content.Server.Access.Components;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Shared.Access.Components;
using Content.Shared.Sound; using Content.Shared.Sound;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -15,7 +14,7 @@ namespace Content.Server.Singularity.Components
public class EmitterComponent : Component public class EmitterComponent : Component
{ {
[ComponentDependency] public readonly AppearanceComponent? Appearance = default; [ComponentDependency] public readonly AppearanceComponent? Appearance = default;
[ComponentDependency] public readonly AccessReader? AccessReader = default; [ComponentDependency] public readonly AccessReaderComponent? AccessReader = default;
[ComponentDependency] public readonly PowerConsumerComponent? PowerConsumer = default; [ComponentDependency] public readonly PowerConsumerComponent? PowerConsumer = default;
public override string Name => "Emitter"; public override string Name => "Emitter";

View File

@@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.Access.Components;
using Content.Server.Access.Systems;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Server.WireHacking; using Content.Server.WireHacking;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Acts; using Content.Shared.Acts;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Sound; using Content.Shared.Sound;
@@ -191,7 +191,7 @@ namespace Content.Server.VendingMachines
private void TryEject(string id, EntityUid? sender) private void TryEject(string id, EntityUid? sender)
{ {
if (_entMan.TryGetComponent<AccessReader?>(Owner, out var accessReader)) if (_entMan.TryGetComponent<AccessReaderComponent?>(Owner, out var accessReader))
{ {
var accessSystem = EntitySystem.Get<AccessReaderSystem>(); var accessSystem = EntitySystem.Get<AccessReaderSystem>();
if (sender == null || !accessSystem.IsAllowed(accessReader, sender.Value)) if (sender == null || !accessSystem.IsAllowed(accessReader, sender.Value))

View File

@@ -1,13 +1,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.Access.Systems; using Content.Shared.Access.Systems;
using Content.Shared.Access;
using Robust.Shared.Analyzers; using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Server.Access.Components namespace Content.Shared.Access.Components
{ {
/// <summary> /// <summary>
/// Simple mutable access provider found on ID cards and such. /// Simple mutable access provider found on ID cards and such.

View File

@@ -1,27 +1,16 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Content.Server.Hands.Components;
using Content.Server.Inventory.Components;
using Content.Server.Items;
using Content.Shared.Access;
using Content.Shared.Inventory;
using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Server.Access.Components namespace Content.Shared.Access.Components
{ {
/// <summary> /// <summary>
/// Stores access levels necessary to "use" an entity /// Stores access levels necessary to "use" an entity
/// and allows checking if something or somebody is authorized with these access levels. /// and allows checking if something or somebody is authorized with these access levels.
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public class AccessReader : Component public class AccessReaderComponent : Component
{ {
public override string Name => "AccessReader"; public override string Name => "AccessReader";

View File

@@ -2,19 +2,17 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Server.Access.Components; using Content.Shared.Access.Components;
using Content.Server.Inventory.Components;
using Content.Server.Items;
using Content.Shared.Access;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Inventory; using Content.Shared.Inventory;
using Content.Shared.Item;
using Content.Shared.PDA; using Content.Shared.PDA;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Log; using Robust.Shared.Log;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Server.Access.Systems namespace Content.Shared.Access.Systems
{ {
public class AccessReaderSystem : EntitySystem public class AccessReaderSystem : EntitySystem
{ {
@@ -23,10 +21,10 @@ namespace Content.Server.Access.Systems
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<AccessReader, ComponentInit>(OnInit); SubscribeLocalEvent<AccessReaderComponent, ComponentInit>(OnInit);
} }
private void OnInit(EntityUid uid, AccessReader reader, ComponentInit args) private void OnInit(EntityUid uid, AccessReaderComponent reader, ComponentInit args)
{ {
var allTags = reader.AccessLists.SelectMany(c => c).Union(reader.DenyTags); var allTags = reader.AccessLists.SelectMany(c => c).Union(reader.DenyTags);
foreach (var level in allTags) foreach (var level in allTags)
@@ -46,13 +44,13 @@ namespace Content.Server.Access.Systems
/// If no access is found, an empty set is used instead. /// If no access is found, an empty set is used instead.
/// </remarks> /// </remarks>
/// <param name="entity">The entity to be searched for access.</param> /// <param name="entity">The entity to be searched for access.</param>
public bool IsAllowed(AccessReader reader, EntityUid entity) public bool IsAllowed(AccessReaderComponent reader, EntityUid entity)
{ {
var tags = FindAccessTags(entity); var tags = FindAccessTags(entity);
return IsAllowed(reader, tags); return IsAllowed(reader, tags);
} }
public bool IsAllowed(AccessReader reader, ICollection<string> accessTags) public bool IsAllowed(AccessReaderComponent reader, ICollection<string> accessTags)
{ {
if (reader.DenyTags.Overlaps(accessTags)) if (reader.DenyTags.Overlaps(accessTags))
{ {
@@ -80,11 +78,10 @@ namespace Content.Server.Access.Systems
} }
// maybe its inside an inventory slot? // maybe its inside an inventory slot?
if (EntityManager.TryGetComponent(uid, out InventoryComponent? inventoryComponent)) if (EntityManager.TryGetComponent(uid, out SharedInventoryComponent? inventoryComponent))
{ {
if (inventoryComponent.HasSlot(EquipmentSlotDefines.Slots.IDCARD) && if (inventoryComponent.TryGetSlot(EquipmentSlotDefines.Slots.IDCARD, out var entity) &&
inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent? item) && FindAccessTagsItem(entity.Value, out tags)
FindAccessTagsItem(item.Owner, out tags)
) )
{ {
return tags; return tags;

View File

@@ -1,8 +1,8 @@
using Content.Server.Access.Components; using Content.Shared.Access.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using System.Collections.Generic; using System.Collections.Generic;
namespace Content.Server.Access.Systems namespace Content.Shared.Access.Systems
{ {
public class AccessSystem : EntitySystem public class AccessSystem : EntitySystem
{ {

View File

@@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Content.Shared.Movement.Components; using System.Diagnostics.CodeAnalysis;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -42,6 +42,8 @@ namespace Content.Shared.Inventory
InventoryInstance = DynamicTypeFactory.CreateInstance<Inventory>(type!); InventoryInstance = DynamicTypeFactory.CreateInstance<Inventory>(type!);
} }
public abstract bool TryGetSlot(Slots slot, [NotNullWhen(true)] out EntityUid? item);
/// <returns>true if the item is equipped to an equip slot (NOT inside an equipped container /// <returns>true if the item is equipped to an equip slot (NOT inside an equipped container
/// like inside a backpack)</returns> /// like inside a backpack)</returns>
public abstract bool IsEquipped(EntityUid item); public abstract bool IsEquipped(EntityUid item);