From b675bdb789d3da9f56162811f8bcca1e14f481d0 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sun, 26 Dec 2021 17:07:28 +1300 Subject: [PATCH] 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. --- Content.Client/Entry/IgnoredComponents.cs | 2 -- .../Inventory/ClientInventoryComponent.cs | 12 ++++++++-- .../Inventory/ClientInventorySystem.cs | 4 ++-- .../HumanInventoryInterfaceController.cs | 4 ++-- .../Tests/Access/AccessReaderTest.cs | 18 +++++++-------- .../Accessible/AiReachableSystem.cs | 1 + .../Pathfinding/Accessible/ReachableArgs.cs | 2 +- .../AI/Pathfinding/PathfindingHelpers.cs | 2 +- .../AI/Pathfinding/PathfindingNode.cs | 8 +++---- .../AI/Pathfinding/PathfindingSystem.cs | 2 +- .../AI/Steering/AiSteeringSystem.cs | 2 +- .../Components/IdCardConsoleComponent.cs | 7 +++--- .../Access/Systems/PresetIdCardSystem.cs | 1 + Content.Server/Cargo/CargoConsoleSystem.cs | 5 ++-- .../Doors/Components/ServerDoorComponent.cs | 10 ++++---- .../GameTicking/GameTicker.Spawning.cs | 2 +- .../Components/InventoryComponent.cs | 12 ++++++++++ Content.Server/Lock/LockSystem.cs | 4 +++- .../Power/Components/ApcComponent.cs | 8 +++---- Content.Server/Sandbox/SandboxManager.cs | 3 +-- .../Components/EmitterComponent.cs | 5 ++-- .../VendingMachineComponent.cs | 6 ++--- .../Access/Components/AccessComponent.cs | 5 ++-- .../Components/AccessReaderComponent.cs | 15 ++---------- .../Access/Systems/AccessReaderSystem.cs | 23 ++++++++----------- .../Access/Systems/AccessSystem.cs | 4 ++-- .../Inventory/SharedInventoryComponent.cs | 4 +++- 27 files changed, 90 insertions(+), 81 deletions(-) rename {Content.Server => Content.Shared}/Access/Components/AccessComponent.cs (87%) rename {Content.Server => Content.Shared}/Access/Components/AccessReaderComponent.cs (75%) rename {Content.Server => Content.Shared}/Access/Systems/AccessReaderSystem.cs (79%) rename {Content.Server => Content.Shared}/Access/Systems/AccessSystem.cs (88%) diff --git a/Content.Client/Entry/IgnoredComponents.cs b/Content.Client/Entry/IgnoredComponents.cs index 1254b068e4..db6bf409f9 100644 --- a/Content.Client/Entry/IgnoredComponents.cs +++ b/Content.Client/Entry/IgnoredComponents.cs @@ -46,8 +46,6 @@ namespace Content.Client.Entry "ResearchServer", "ResearchPointSource", "ResearchClient", - "Access", - "AccessReader", "IdCardConsole", "Airlock", "ThermalRegulator", diff --git a/Content.Client/Inventory/ClientInventoryComponent.cs b/Content.Client/Inventory/ClientInventoryComponent.cs index 0c9f0e619f..0a52a5443f 100644 --- a/Content.Client/Inventory/ClientInventoryComponent.cs +++ b/Content.Client/Inventory/ClientInventoryComponent.cs @@ -228,9 +228,17 @@ namespace Content.Client.Inventory _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) diff --git a/Content.Client/Inventory/ClientInventorySystem.cs b/Content.Client/Inventory/ClientInventorySystem.cs index 6c691803fa..b354ef2982 100644 --- a/Content.Client/Inventory/ClientInventorySystem.cs +++ b/Content.Client/Inventory/ClientInventorySystem.cs @@ -35,9 +35,9 @@ namespace Content.Client.Inventory // jesus christ, this is duplicated to server/client, should really just be shared.. 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); } } diff --git a/Content.Client/Inventory/HumanInventoryInterfaceController.cs b/Content.Client/Inventory/HumanInventoryInterfaceController.cs index e1e1b62c34..b63948460c 100644 --- a/Content.Client/Inventory/HumanInventoryInterfaceController.cs +++ b/Content.Client/Inventory/HumanInventoryInterfaceController.cs @@ -203,7 +203,7 @@ namespace Content.Client.Inventory if (!Owner.TryGetSlot(slot, out var item)) return; - if (!_itemSlotManager.OnButtonPressed(args, item)) + if (!_itemSlotManager.OnButtonPressed(args, item.Value)) base.HandleInventoryKeybind(args, slot); } @@ -232,7 +232,7 @@ namespace Content.Client.Inventory if (Owner.TryGetSlot(slot, out var entity)) { - AddToSlot(slot, entity); + AddToSlot(slot, entity.Value); } } } diff --git a/Content.IntegrationTests/Tests/Access/AccessReaderTest.cs b/Content.IntegrationTests/Tests/Access/AccessReaderTest.cs index 5587ed14d8..3a42a26f26 100644 --- a/Content.IntegrationTests/Tests/Access/AccessReaderTest.cs +++ b/Content.IntegrationTests/Tests/Access/AccessReaderTest.cs @@ -1,15 +1,15 @@ using System.Collections.Generic; using System.Threading.Tasks; using Content.IntegrationTests; -using Content.Server.Access.Components; -using Content.Server.Access.Systems; +using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using NUnit.Framework; using Robust.Shared.GameObjects; namespace Content.Tests.Server.GameObjects.Components.Access { [TestFixture] - [TestOf(typeof(AccessReader))] + [TestOf(typeof(AccessReaderComponent))] public class AccessReaderTest : ContentIntegrationTest { [Test] @@ -21,13 +21,13 @@ namespace Content.Tests.Server.GameObjects.Components.Access var system = EntitySystem.Get(); // 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[] { "Bar" }), Is.True); Assert.That(system.IsAllowed(reader, new string[] { }), Is.True); // test deny - reader = new AccessReader(); + reader = new AccessReaderComponent(); reader.DenyTags.Add("A"); Assert.That(system.IsAllowed(reader, new[] { "Foo" }), Is.True); 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); // test one list - reader = new AccessReader(); + reader = new AccessReaderComponent(); reader.AccessLists.Add(new HashSet { "A" }); Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.True); 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); // test one list - two items - reader = new AccessReader(); + reader = new AccessReaderComponent(); reader.AccessLists.Add(new HashSet { "A", "B" }); Assert.That(system.IsAllowed(reader, new[] { "A" }), 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); // test two list - reader = new AccessReader(); + reader = new AccessReaderComponent(); reader.AccessLists.Add(new HashSet { "A" }); reader.AccessLists.Add(new HashSet { "B", "C" }); 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); // test deny list - reader = new AccessReader(); + reader = new AccessReaderComponent(); reader.AccessLists.Add(new HashSet { "A" }); reader.DenyTags.Add("B"); Assert.That(system.IsAllowed(reader, new[] { "A" }), Is.True); diff --git a/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs b/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs index cfc97c432c..cabcd3896b 100644 --- a/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs +++ b/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using Content.Server.Access.Systems; using Content.Server.AI.Pathfinding.Pathfinders; +using Content.Shared.Access.Systems; using Content.Shared.AI; using Content.Shared.GameTicking; using JetBrains.Annotations; diff --git a/Content.Server/AI/Pathfinding/Accessible/ReachableArgs.cs b/Content.Server/AI/Pathfinding/Accessible/ReachableArgs.cs index 2e001502d6..517d999750 100644 --- a/Content.Server/AI/Pathfinding/Accessible/ReachableArgs.cs +++ b/Content.Server/AI/Pathfinding/Accessible/ReachableArgs.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using Content.Server.Access.Systems; using Content.Server.AI.Components; +using Content.Shared.Access.Systems; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Physics; diff --git a/Content.Server/AI/Pathfinding/PathfindingHelpers.cs b/Content.Server/AI/Pathfinding/PathfindingHelpers.cs index c648070417..c47e706e8f 100644 --- a/Content.Server/AI/Pathfinding/PathfindingHelpers.cs +++ b/Content.Server/AI/Pathfinding/PathfindingHelpers.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; -using Content.Server.Access.Systems; using Content.Server.AI.Pathfinding.Accessible; using Content.Server.AI.Pathfinding.Pathfinders; +using Content.Shared.Access.Systems; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; diff --git a/Content.Server/AI/Pathfinding/PathfindingNode.cs b/Content.Server/AI/Pathfinding/PathfindingNode.cs index bbd78cfb8d..2e0c7ef0f7 100644 --- a/Content.Server/AI/Pathfinding/PathfindingNode.cs +++ b/Content.Server/AI/Pathfinding/PathfindingNode.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using Content.Server.Access.Components; using Content.Server.Doors.Components; +using Content.Shared.Access.Components; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; @@ -32,8 +32,8 @@ namespace Content.Server.AI.Pathfinding /// The entities on this tile that require access to traverse /// /// We don't store the ICollection, at least for now, as we'd need to replicate the access code here - public IReadOnlyCollection AccessReaders => _accessReaders.Values; - private readonly Dictionary _accessReaders = new(0); + public IReadOnlyCollection AccessReaders => _accessReaders.Values; + private readonly Dictionary _accessReaders = new(0); 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 // AccessReader calls this whenever opening / closing but it can seem to get called multiple times // 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); ParentChunk.Dirty(); diff --git a/Content.Server/AI/Pathfinding/PathfindingSystem.cs b/Content.Server/AI/Pathfinding/PathfindingSystem.cs index ba08f2dedb..ee64db37db 100644 --- a/Content.Server/AI/Pathfinding/PathfindingSystem.cs +++ b/Content.Server/AI/Pathfinding/PathfindingSystem.cs @@ -2,10 +2,10 @@ using System; using System.Collections.Generic; using System.Threading; using Content.Server.Access; -using Content.Server.Access.Systems; using Content.Server.AI.Pathfinding.Pathfinders; using Content.Server.CPUJob.JobQueues; using Content.Server.CPUJob.JobQueues.Queues; +using Content.Shared.Access.Systems; using Content.Shared.GameTicking; using Content.Shared.Physics; using Robust.Shared.GameObjects; diff --git a/Content.Server/AI/Steering/AiSteeringSystem.cs b/Content.Server/AI/Steering/AiSteeringSystem.cs index 8941d7cc3a..f1539cf0c4 100644 --- a/Content.Server/AI/Steering/AiSteeringSystem.cs +++ b/Content.Server/AI/Steering/AiSteeringSystem.cs @@ -3,11 +3,11 @@ using System.Collections.Generic; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; -using Content.Server.Access.Systems; using Content.Server.AI.Components; using Content.Server.AI.Pathfinding; using Content.Server.AI.Pathfinding.Pathfinders; using Content.Server.CPUJob.JobQueues; +using Content.Shared.Access.Systems; using Content.Shared.ActionBlocker; using Content.Shared.Interaction.Helpers; using Robust.Shared.GameObjects; diff --git a/Content.Server/Access/Components/IdCardConsoleComponent.cs b/Content.Server/Access/Components/IdCardConsoleComponent.cs index e505a40b16..71bec9ee6c 100644 --- a/Content.Server/Access/Components/IdCardConsoleComponent.cs +++ b/Content.Server/Access/Components/IdCardConsoleComponent.cs @@ -5,6 +5,7 @@ using Content.Server.Power.Components; using Content.Server.UserInterface; using Content.Shared.Access; using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.Containers.ItemSlots; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; @@ -29,7 +30,7 @@ namespace Content.Server.Access.Components { base.Initialize(); - Owner.EnsureComponentWarn(); + Owner.EnsureComponentWarn(); Owner.EnsureComponentWarn(); if (UserInterface != null) @@ -66,11 +67,11 @@ namespace Content.Server.Access.Components } /// - /// Returns true if there is an ID in and said ID satisfies the requirements of . + /// Returns true if there is an ID in and said ID satisfies the requirements of . /// private bool PrivilegedIdIsAuthorized() { - if (!_entities.TryGetComponent(Owner, out AccessReader? reader)) + if (!_entities.TryGetComponent(Owner, out AccessReaderComponent? reader)) { return true; } diff --git a/Content.Server/Access/Systems/PresetIdCardSystem.cs b/Content.Server/Access/Systems/PresetIdCardSystem.cs index 4d6b0a6ffa..78e4185ff8 100644 --- a/Content.Server/Access/Systems/PresetIdCardSystem.cs +++ b/Content.Server/Access/Systems/PresetIdCardSystem.cs @@ -1,4 +1,5 @@ using Content.Server.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.Roles; using Robust.Shared.GameObjects; using Robust.Shared.IoC; diff --git a/Content.Server/Cargo/CargoConsoleSystem.cs b/Content.Server/Cargo/CargoConsoleSystem.cs index 8e3d70104b..f6aebf7b16 100644 --- a/Content.Server/Cargo/CargoConsoleSystem.cs +++ b/Content.Server/Cargo/CargoConsoleSystem.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using Content.Server.Access.Components; using Content.Server.Access.Systems; using Content.Server.Cargo.Components; +using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.Cargo; using Content.Shared.GameTicking; using Robust.Shared.GameObjects; @@ -177,7 +178,7 @@ namespace Content.Server.Cargo 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? if (Resolve(uid, ref reader) && !_accessReaderSystem.IsAllowed(reader, approver)) diff --git a/Content.Server/Doors/Components/ServerDoorComponent.cs b/Content.Server/Doors/Components/ServerDoorComponent.cs index 8f76be66e7..b3a17c9a19 100644 --- a/Content.Server/Doors/Components/ServerDoorComponent.cs +++ b/Content.Server/Doors/Components/ServerDoorComponent.cs @@ -3,8 +3,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Content.Server.Access; -using Content.Server.Access.Components; -using Content.Server.Access.Systems; using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Server.Construction; @@ -13,6 +11,8 @@ using Content.Server.Hands.Components; using Content.Server.Stunnable; using Content.Server.Tools; using Content.Server.Tools.Components; +using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.Damage; using Content.Shared.Doors; using Content.Shared.Interaction; @@ -310,7 +310,7 @@ namespace Content.Server.Doors.Components return false; } - if (!_entMan.TryGetComponent(Owner, out AccessReader? access)) + if (!_entMan.TryGetComponent(Owner, out AccessReaderComponent? access)) { return true; } @@ -334,7 +334,7 @@ namespace Content.Server.Doors.Components /// 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)); } @@ -445,7 +445,7 @@ namespace Content.Server.Doors.Components return false; } - if (!_entMan.TryGetComponent(Owner, out AccessReader? access)) + if (!_entMan.TryGetComponent(Owner, out AccessReaderComponent? access)) { return true; } diff --git a/Content.Server/GameTicking/GameTicker.Spawning.cs b/Content.Server/GameTicking/GameTicker.Spawning.cs index c143ca7a32..bb1662cebc 100644 --- a/Content.Server/GameTicking/GameTicker.Spawning.cs +++ b/Content.Server/GameTicking/GameTicker.Spawning.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; -using Content.Server.Access.Components; using Content.Server.Access.Systems; using Content.Server.Ghost; using Content.Server.Ghost.Components; @@ -15,6 +14,7 @@ using Content.Server.Roles; using Content.Server.Spawners.Components; using Content.Server.Speech.Components; using Content.Server.Station; +using Content.Shared.Access.Components; using Content.Shared.Administration.Logs; using Content.Shared.CharacterAppearance.Systems; using Content.Shared.Database; diff --git a/Content.Server/Inventory/Components/InventoryComponent.cs b/Content.Server/Inventory/Components/InventoryComponent.cs index f0aade547d..47fa7c7958 100644 --- a/Content.Server/Inventory/Components/InventoryComponent.cs +++ b/Content.Server/Inventory/Components/InventoryComponent.cs @@ -560,5 +560,17 @@ namespace Content.Server.Inventory.Components 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; + } } } diff --git a/Content.Server/Lock/LockSystem.cs b/Content.Server/Lock/LockSystem.cs index 44948fd3cf..969a70c40f 100644 --- a/Content.Server/Lock/LockSystem.cs +++ b/Content.Server/Lock/LockSystem.cs @@ -1,6 +1,8 @@ using Content.Server.Access.Components; using Content.Server.Access.Systems; using Content.Server.Storage.Components; +using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Popups; @@ -144,7 +146,7 @@ namespace Content.Server.Lock 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! if (!Resolve(uid, ref reader)) diff --git a/Content.Server/Power/Components/ApcComponent.cs b/Content.Server/Power/Components/ApcComponent.cs index dd8b3bf215..f4da006a30 100644 --- a/Content.Server/Power/Components/ApcComponent.cs +++ b/Content.Server/Power/Components/ApcComponent.cs @@ -1,8 +1,8 @@ using System; -using Content.Server.Access.Components; -using Content.Server.Access.Systems; using Content.Server.Power.NodeGroups; using Content.Server.UserInterface; +using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.APC; using Content.Shared.Interaction; using Content.Shared.Popups; @@ -59,14 +59,14 @@ namespace Content.Server.Power.Components 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() { base.Initialize(); Owner.EnsureComponentWarn(); - Owner.EnsureComponentWarn(); + Owner.EnsureComponentWarn(); if (UserInterface != null) { diff --git a/Content.Server/Sandbox/SandboxManager.cs b/Content.Server/Sandbox/SandboxManager.cs index 4c78ce12d6..0c7eef4cc2 100644 --- a/Content.Server/Sandbox/SandboxManager.cs +++ b/Content.Server/Sandbox/SandboxManager.cs @@ -1,12 +1,11 @@ using System.Linq; -using Content.Server.Access.Components; -using Content.Server.Access.Systems; using Content.Server.GameTicking; using Content.Server.Hands.Components; using Content.Server.Inventory.Components; using Content.Server.Items; using Content.Shared.Access; using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.Containers.ItemSlots; using Content.Shared.PDA; using Content.Shared.Sandbox; diff --git a/Content.Server/Singularity/Components/EmitterComponent.cs b/Content.Server/Singularity/Components/EmitterComponent.cs index a21401bfa5..6a1de068d7 100644 --- a/Content.Server/Singularity/Components/EmitterComponent.cs +++ b/Content.Server/Singularity/Components/EmitterComponent.cs @@ -1,9 +1,8 @@ using System; using System.Threading; -using Content.Server.Access.Components; using Content.Server.Power.Components; +using Content.Shared.Access.Components; using Content.Shared.Sound; -using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -15,7 +14,7 @@ namespace Content.Server.Singularity.Components public class EmitterComponent : Component { [ComponentDependency] public readonly AppearanceComponent? Appearance = default; - [ComponentDependency] public readonly AccessReader? AccessReader = default; + [ComponentDependency] public readonly AccessReaderComponent? AccessReader = default; [ComponentDependency] public readonly PowerConsumerComponent? PowerConsumer = default; public override string Name => "Emitter"; diff --git a/Content.Server/VendingMachines/VendingMachineComponent.cs b/Content.Server/VendingMachines/VendingMachineComponent.cs index 192e8611f8..ce7c993a0d 100644 --- a/Content.Server/VendingMachines/VendingMachineComponent.cs +++ b/Content.Server/VendingMachines/VendingMachineComponent.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; -using Content.Server.Access.Components; -using Content.Server.Access.Systems; using Content.Server.Popups; using Content.Server.Power.Components; using Content.Server.UserInterface; using Content.Server.WireHacking; +using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.Acts; using Content.Shared.Interaction; using Content.Shared.Sound; @@ -191,7 +191,7 @@ namespace Content.Server.VendingMachines private void TryEject(string id, EntityUid? sender) { - if (_entMan.TryGetComponent(Owner, out var accessReader)) + if (_entMan.TryGetComponent(Owner, out var accessReader)) { var accessSystem = EntitySystem.Get(); if (sender == null || !accessSystem.IsAllowed(accessReader, sender.Value)) diff --git a/Content.Server/Access/Components/AccessComponent.cs b/Content.Shared/Access/Components/AccessComponent.cs similarity index 87% rename from Content.Server/Access/Components/AccessComponent.cs rename to Content.Shared/Access/Components/AccessComponent.cs index 16a76725fb..bb3da3408b 100644 --- a/Content.Server/Access/Components/AccessComponent.cs +++ b/Content.Shared/Access/Components/AccessComponent.cs @@ -1,13 +1,12 @@ using System.Collections.Generic; -using Content.Server.Access.Systems; -using Content.Shared.Access; +using Content.Shared.Access.Systems; using Robust.Shared.Analyzers; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set; using Robust.Shared.ViewVariables; -namespace Content.Server.Access.Components +namespace Content.Shared.Access.Components { /// /// Simple mutable access provider found on ID cards and such. diff --git a/Content.Server/Access/Components/AccessReaderComponent.cs b/Content.Shared/Access/Components/AccessReaderComponent.cs similarity index 75% rename from Content.Server/Access/Components/AccessReaderComponent.cs rename to Content.Shared/Access/Components/AccessReaderComponent.cs index dbcfa39999..5d0a82772c 100644 --- a/Content.Server/Access/Components/AccessReaderComponent.cs +++ b/Content.Shared/Access/Components/AccessReaderComponent.cs @@ -1,27 +1,16 @@ -using System; 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.IoC; -using Robust.Shared.Log; -using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -namespace Content.Server.Access.Components +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] - public class AccessReader : Component + public class AccessReaderComponent : Component { public override string Name => "AccessReader"; diff --git a/Content.Server/Access/Systems/AccessReaderSystem.cs b/Content.Shared/Access/Systems/AccessReaderSystem.cs similarity index 79% rename from Content.Server/Access/Systems/AccessReaderSystem.cs rename to Content.Shared/Access/Systems/AccessReaderSystem.cs index 8157646f8b..1c840d715f 100644 --- a/Content.Server/Access/Systems/AccessReaderSystem.cs +++ b/Content.Shared/Access/Systems/AccessReaderSystem.cs @@ -2,19 +2,17 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -using Content.Server.Access.Components; -using Content.Server.Inventory.Components; -using Content.Server.Items; -using Content.Shared.Access; +using Content.Shared.Access.Components; using Content.Shared.Hands.Components; using Content.Shared.Inventory; +using Content.Shared.Item; using Content.Shared.PDA; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Prototypes; -namespace Content.Server.Access.Systems +namespace Content.Shared.Access.Systems { public class AccessReaderSystem : EntitySystem { @@ -23,10 +21,10 @@ namespace Content.Server.Access.Systems public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(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); 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. /// /// The entity to be searched for access. - public bool IsAllowed(AccessReader reader, EntityUid entity) + public bool IsAllowed(AccessReaderComponent reader, EntityUid entity) { var tags = FindAccessTags(entity); return IsAllowed(reader, tags); } - public bool IsAllowed(AccessReader reader, ICollection accessTags) + public bool IsAllowed(AccessReaderComponent reader, ICollection accessTags) { if (reader.DenyTags.Overlaps(accessTags)) { @@ -80,11 +78,10 @@ namespace Content.Server.Access.Systems } // 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) && - inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent? item) && - FindAccessTagsItem(item.Owner, out tags) + if (inventoryComponent.TryGetSlot(EquipmentSlotDefines.Slots.IDCARD, out var entity) && + FindAccessTagsItem(entity.Value, out tags) ) { return tags; diff --git a/Content.Server/Access/Systems/AccessSystem.cs b/Content.Shared/Access/Systems/AccessSystem.cs similarity index 88% rename from Content.Server/Access/Systems/AccessSystem.cs rename to Content.Shared/Access/Systems/AccessSystem.cs index 7424e10fd8..deb58c2b35 100644 --- a/Content.Server/Access/Systems/AccessSystem.cs +++ b/Content.Shared/Access/Systems/AccessSystem.cs @@ -1,8 +1,8 @@ -using Content.Server.Access.Components; +using Content.Shared.Access.Components; using Robust.Shared.GameObjects; using System.Collections.Generic; -namespace Content.Server.Access.Systems +namespace Content.Shared.Access.Systems { public class AccessSystem : EntitySystem { diff --git a/Content.Shared/Inventory/SharedInventoryComponent.cs b/Content.Shared/Inventory/SharedInventoryComponent.cs index a49a2018d5..8e7e73e531 100644 --- a/Content.Shared/Inventory/SharedInventoryComponent.cs +++ b/Content.Shared/Inventory/SharedInventoryComponent.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Content.Shared.Movement.Components; +using System.Diagnostics.CodeAnalysis; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; @@ -42,6 +42,8 @@ namespace Content.Shared.Inventory InventoryInstance = DynamicTypeFactory.CreateInstance(type!); } + public abstract bool TryGetSlot(Slots slot, [NotNullWhen(true)] out EntityUid? item); + /// true if the item is equipped to an equip slot (NOT inside an equipped container /// like inside a backpack) public abstract bool IsEquipped(EntityUid item);