]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
remove mind roles from EntityWhitelist (#36089)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Thu, 10 Apr 2025 10:45:12 +0000 (12:45 +0200)
committerGitHub <noreply@github.com>
Thu, 10 Apr 2025 10:45:12 +0000 (20:45 +1000)
* remove mind roles from EntityWhitelist

* remove redundant dependency

Content.Server/Objectives/Components/RoleRequirementComponent.cs
Content.Server/Objectives/Systems/RoleRequirementSystem.cs
Content.Shared/Whitelist/EntityWhitelist.cs
Content.Shared/Whitelist/EntityWhitelistSystem.cs
Resources/Prototypes/Objectives/dragon.yml
Resources/Prototypes/Objectives/ninja.yml
Resources/Prototypes/Objectives/paradoxClone.yml
Resources/Prototypes/Objectives/thief.yml
Resources/Prototypes/Objectives/traitor.yml
Resources/Prototypes/Objectives/wizard.yml

index 86f8d7cedfe6dc26bffd138c777a40d86aa4c84a..3fbf09b65a2f2dd5bc27716c26dc10d2701b6d5c 100644 (file)
@@ -1,5 +1,6 @@
 using Content.Server.Objectives.Systems;
-using Content.Shared.Whitelist;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
 
 namespace Content.Server.Objectives.Components;
 
@@ -10,6 +11,9 @@ namespace Content.Server.Objectives.Components;
 [RegisterComponent, Access(typeof(RoleRequirementSystem))]
 public sealed partial class RoleRequirementComponent : Component
 {
-    [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
-    public EntityWhitelist Roles = new();
+    /// <summary>
+    /// Mind role component whitelist.
+    /// </summary>
+    [DataField(required: true, customTypeSerializer: typeof(CustomHashSetSerializer<string, ComponentNameSerializer>))]
+    public HashSet<string> Roles = new();
 }
index 83d4c2ea4c553a6f55f545a80b686709085993ef..a86d6bf23adda7b41071fa275b47315abef8c6d8 100644 (file)
@@ -1,6 +1,6 @@
 using Content.Server.Objectives.Components;
 using Content.Shared.Objectives.Components;
-using Content.Shared.Whitelist;
+using Content.Shared.Roles;
 
 namespace Content.Server.Objectives.Systems;
 
@@ -9,7 +9,7 @@ namespace Content.Server.Objectives.Systems;
 /// </summary>
 public sealed class RoleRequirementSystem : EntitySystem
 {
-    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
+    [Dependency] private readonly SharedRoleSystem _roles = default!;
     public override void Initialize()
     {
         base.Initialize();
@@ -22,7 +22,19 @@ public sealed class RoleRequirementSystem : EntitySystem
         if (args.Cancelled)
             return;
 
-        if (_whitelistSystem.IsWhitelistFail(comp.Roles, args.MindId))
-            args.Cancelled = true;
+        foreach (var role in comp.Roles)
+        {
+            if (!EntityManager.ComponentFactory.TryGetRegistration(role, out var roleReg))
+            {
+                Log.Error($"Role component not found for RoleRequirementComponent: {role}");
+                continue;
+            }
+
+            if (_roles.MindHasRole(args.MindId, roleReg.Type, out _))
+                return; // whitelist pass
+        }
+
+        // whitelist fail
+        args.Cancelled = true;
     }
 }
index cbe4633360f8c8b7140bc8e7cf4b0e2c068b98ce..e08bb339e5bb67cf72103bbe09917de59926d771 100644 (file)
@@ -10,6 +10,9 @@ namespace Content.Shared.Whitelist;
 ///     Does not whitelist by prototypes, since that is undesirable; you're better off just adding a tag to all
 ///     entity prototypes that need to be whitelisted, and checking for that.
 /// </summary>
+/// <remarks>
+///     Do not add more conditions like itemsize to the whitelist, this should stay as lightweight as possible!
+/// </remarks>
 /// <code>
 /// whitelist:
 ///   tags:
@@ -32,12 +35,6 @@ public sealed partial class EntityWhitelist
     [DataField] public string[]? Components;
     // TODO yaml validation
 
-    /// <summary>
-    ///     Mind Role Prototype names that are allowed in the whitelist.
-    /// </summary>
-    [DataField] public string[]? MindRoles;
-    // TODO yaml validation
-
     /// <summary>
     ///     Item sizes that are allowed in the whitelist.
     /// </summary>
index 9a6e87c1b4ad66399e3080a742c1178b9f16f0dc..b33bbf2586f38e3e614df58b8c4439f1b4a8bb1d 100644 (file)
@@ -1,6 +1,5 @@
 using System.Diagnostics.CodeAnalysis;
 using Content.Shared.Item;
-using Content.Shared.Roles;
 using Content.Shared.Tag;
 
 namespace Content.Shared.Whitelist;
@@ -8,7 +7,6 @@ namespace Content.Shared.Whitelist;
 public sealed class EntityWhitelistSystem : EntitySystem
 {
     [Dependency] private readonly IComponentFactory _factory = default!;
-    [Dependency] private readonly SharedRoleSystem _roles = default!;
     [Dependency] private readonly TagSystem _tag = default!;
 
     private EntityQuery<ItemComponent> _itemQuery;
@@ -57,22 +55,6 @@ public sealed class EntityWhitelistSystem : EntitySystem
             }
         }
 
-        if (list.MindRoles != null)
-        {
-            var regs = StringsToRegs(list.MindRoles);
-
-            foreach (var role in regs)
-            {
-                if ( _roles.MindHasRole(uid, role.Type, out _))
-                {
-                    if (!list.RequireAll)
-                        return true;
-                }
-                else if (list.RequireAll)
-                    return false;
-            }
-        }
-
         if (list.Registrations != null && list.Registrations.Count > 0)
         {
             foreach (var reg in list.Registrations)
index 9d81c62ab3f43b4490d750e3afd3aabf528bc71a..35740896e3cd4afb038864ff3baa692707ef4424 100644 (file)
@@ -9,8 +9,7 @@
     issuer: objective-issuer-dragon
   - type: RoleRequirement
     roles:
-      mindRoles:
-      - DragonRole
+    - DragonRole
 
 - type: entity
   parent: BaseDragonObjective
index 28b624519c49f6108e4283bddb69185056575a7a..76d74876b03d73a401f29d1051da3b521730c70e 100644 (file)
@@ -9,8 +9,7 @@
     issuer: objective-issuer-spiderclan
   - type: RoleRequirement
     roles:
-      mindRoles:
-      - NinjaRole
+    - NinjaRole
 
 - type: entity
   parent: BaseNinjaObjective
index 073c014af0be24c57bb8bc3cba39a067f72ea91b..40a1021676904f554adf95a4cb6fe4e53ef18d13 100644 (file)
@@ -9,8 +9,7 @@
     issuer: objective-issuer-paradox
   - type: RoleRequirement
     roles:
-      mindRoles:
-      - ParadoxCloneRole
+    - ParadoxCloneRole
   - type: Tag
     tags:
     - ParadoxCloneObjectiveBlacklist # don't copy the objectives from other clones
index b5d0141cb76e8eef64642c01810ad77c5e3ab694..f887029fccd6f08a54a6bf214b8e7b19cb3f4426 100644 (file)
@@ -7,8 +7,7 @@
     issuer: objective-issuer-thief
   - type: RoleRequirement
     roles:
-      mindRoles:
-      - ThiefRole
+    - ThiefRole
 
 - type: entity
   abstract: true
index b6f31449c02890e238d8d68d22e8ed2541ab1c01..de222df6cc5e73be47f32199c28533c765079522 100644 (file)
@@ -7,8 +7,7 @@
     issuer: objective-issuer-syndicate
   - type: RoleRequirement
     roles:
-      mindRoles:
-      - TraitorRole
+    - TraitorRole
 
 - type: entity
   abstract: true
index fc8ef6dca3df86b95ddb0e6612de074acf9bad76..52ac7e365a99c8d221f097f4a30124ae915aeecf 100644 (file)
@@ -9,8 +9,7 @@
     issuer: objective-issuer-swf
   - type: RoleRequirement
     roles:
-      mindRoles:
-      - WizardRole
+    - WizardRole
 
 - type: entity
   parent: [BaseWizardObjective, BaseSurviveObjective]