remove mind roles from EntityWhitelist (#36089)

* remove mind roles from EntityWhitelist

* remove redundant dependency
This commit is contained in:
slarticodefast
2025-04-10 12:45:12 +02:00
committed by GitHub
parent dc6ed30ec8
commit f6bfce38da
10 changed files with 32 additions and 43 deletions

View File

@@ -1,5 +1,6 @@
using Content.Server.Objectives.Systems; 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; namespace Content.Server.Objectives.Components;
@@ -10,6 +11,9 @@ namespace Content.Server.Objectives.Components;
[RegisterComponent, Access(typeof(RoleRequirementSystem))] [RegisterComponent, Access(typeof(RoleRequirementSystem))]
public sealed partial class RoleRequirementComponent : Component public sealed partial class RoleRequirementComponent : Component
{ {
[DataField(required: true), ViewVariables(VVAccess.ReadWrite)] /// <summary>
public EntityWhitelist Roles = new(); /// Mind role component whitelist.
/// </summary>
[DataField(required: true, customTypeSerializer: typeof(CustomHashSetSerializer<string, ComponentNameSerializer>))]
public HashSet<string> Roles = new();
} }

View File

@@ -1,6 +1,6 @@
using Content.Server.Objectives.Components; using Content.Server.Objectives.Components;
using Content.Shared.Objectives.Components; using Content.Shared.Objectives.Components;
using Content.Shared.Whitelist; using Content.Shared.Roles;
namespace Content.Server.Objectives.Systems; namespace Content.Server.Objectives.Systems;
@@ -9,7 +9,7 @@ namespace Content.Server.Objectives.Systems;
/// </summary> /// </summary>
public sealed class RoleRequirementSystem : EntitySystem public sealed class RoleRequirementSystem : EntitySystem
{ {
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; [Dependency] private readonly SharedRoleSystem _roles = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -22,7 +22,19 @@ public sealed class RoleRequirementSystem : EntitySystem
if (args.Cancelled) if (args.Cancelled)
return; return;
if (_whitelistSystem.IsWhitelistFail(comp.Roles, args.MindId)) foreach (var role in comp.Roles)
args.Cancelled = true; {
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;
} }
} }

View 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 /// 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. /// entity prototypes that need to be whitelisted, and checking for that.
/// </summary> /// </summary>
/// <remarks>
/// Do not add more conditions like itemsize to the whitelist, this should stay as lightweight as possible!
/// </remarks>
/// <code> /// <code>
/// whitelist: /// whitelist:
/// tags: /// tags:
@@ -32,12 +35,6 @@ public sealed partial class EntityWhitelist
[DataField] public string[]? Components; [DataField] public string[]? Components;
// TODO yaml validation // TODO yaml validation
/// <summary>
/// Mind Role Prototype names that are allowed in the whitelist.
/// </summary>
[DataField] public string[]? MindRoles;
// TODO yaml validation
/// <summary> /// <summary>
/// Item sizes that are allowed in the whitelist. /// Item sizes that are allowed in the whitelist.
/// </summary> /// </summary>

View File

@@ -1,6 +1,5 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Roles;
using Content.Shared.Tag; using Content.Shared.Tag;
namespace Content.Shared.Whitelist; namespace Content.Shared.Whitelist;
@@ -8,7 +7,6 @@ namespace Content.Shared.Whitelist;
public sealed class EntityWhitelistSystem : EntitySystem public sealed class EntityWhitelistSystem : EntitySystem
{ {
[Dependency] private readonly IComponentFactory _factory = default!; [Dependency] private readonly IComponentFactory _factory = default!;
[Dependency] private readonly SharedRoleSystem _roles = default!;
[Dependency] private readonly TagSystem _tag = default!; [Dependency] private readonly TagSystem _tag = default!;
private EntityQuery<ItemComponent> _itemQuery; 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) if (list.Registrations != null && list.Registrations.Count > 0)
{ {
foreach (var reg in list.Registrations) foreach (var reg in list.Registrations)

View File

@@ -9,8 +9,7 @@
issuer: objective-issuer-dragon issuer: objective-issuer-dragon
- type: RoleRequirement - type: RoleRequirement
roles: roles:
mindRoles: - DragonRole
- DragonRole
- type: entity - type: entity
parent: BaseDragonObjective parent: BaseDragonObjective

View File

@@ -9,8 +9,7 @@
issuer: objective-issuer-spiderclan issuer: objective-issuer-spiderclan
- type: RoleRequirement - type: RoleRequirement
roles: roles:
mindRoles: - NinjaRole
- NinjaRole
- type: entity - type: entity
parent: BaseNinjaObjective parent: BaseNinjaObjective

View File

@@ -9,8 +9,7 @@
issuer: objective-issuer-paradox issuer: objective-issuer-paradox
- type: RoleRequirement - type: RoleRequirement
roles: roles:
mindRoles: - ParadoxCloneRole
- ParadoxCloneRole
- type: Tag - type: Tag
tags: tags:
- ParadoxCloneObjectiveBlacklist # don't copy the objectives from other clones - ParadoxCloneObjectiveBlacklist # don't copy the objectives from other clones

View File

@@ -7,8 +7,7 @@
issuer: objective-issuer-thief issuer: objective-issuer-thief
- type: RoleRequirement - type: RoleRequirement
roles: roles:
mindRoles: - ThiefRole
- ThiefRole
- type: entity - type: entity
abstract: true abstract: true

View File

@@ -7,8 +7,7 @@
issuer: objective-issuer-syndicate issuer: objective-issuer-syndicate
- type: RoleRequirement - type: RoleRequirement
roles: roles:
mindRoles: - TraitorRole
- TraitorRole
- type: entity - type: entity
abstract: true abstract: true

View File

@@ -9,8 +9,7 @@
issuer: objective-issuer-swf issuer: objective-issuer-swf
- type: RoleRequirement - type: RoleRequirement
roles: roles:
mindRoles: - WizardRole
- WizardRole
- type: entity - type: entity
parent: [BaseWizardObjective, BaseSurviveObjective] parent: [BaseWizardObjective, BaseSurviveObjective]