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.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();
}

View 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))
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;
}
}

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
/// 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>

View 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)

View File

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

View File

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

View File

@@ -9,7 +9,6 @@
issuer: objective-issuer-paradox
- type: RoleRequirement
roles:
mindRoles:
- ParadoxCloneRole
- type: Tag
tags:

View File

@@ -7,7 +7,6 @@
issuer: objective-issuer-thief
- type: RoleRequirement
roles:
mindRoles:
- ThiefRole
- type: entity

View File

@@ -7,7 +7,6 @@
issuer: objective-issuer-syndicate
- type: RoleRequirement
roles:
mindRoles:
- TraitorRole
- type: entity

View File

@@ -9,7 +9,6 @@
issuer: objective-issuer-swf
- type: RoleRequirement
roles:
mindRoles:
- WizardRole
- type: entity