remove mind roles from EntityWhitelist (#36089)
* remove mind roles from EntityWhitelist * remove redundant dependency
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
issuer: objective-issuer-dragon
|
||||
- type: RoleRequirement
|
||||
roles:
|
||||
mindRoles:
|
||||
- DragonRole
|
||||
- DragonRole
|
||||
|
||||
- type: entity
|
||||
parent: BaseDragonObjective
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
issuer: objective-issuer-spiderclan
|
||||
- type: RoleRequirement
|
||||
roles:
|
||||
mindRoles:
|
||||
- NinjaRole
|
||||
- NinjaRole
|
||||
|
||||
- type: entity
|
||||
parent: BaseNinjaObjective
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
issuer: objective-issuer-thief
|
||||
- type: RoleRequirement
|
||||
roles:
|
||||
mindRoles:
|
||||
- ThiefRole
|
||||
- ThiefRole
|
||||
|
||||
- type: entity
|
||||
abstract: true
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
issuer: objective-issuer-syndicate
|
||||
- type: RoleRequirement
|
||||
roles:
|
||||
mindRoles:
|
||||
- TraitorRole
|
||||
- TraitorRole
|
||||
|
||||
- type: entity
|
||||
abstract: true
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
issuer: objective-issuer-swf
|
||||
- type: RoleRequirement
|
||||
roles:
|
||||
mindRoles:
|
||||
- WizardRole
|
||||
- WizardRole
|
||||
|
||||
- type: entity
|
||||
parent: [BaseWizardObjective, BaseSurviveObjective]
|
||||
|
||||
Reference in New Issue
Block a user