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