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;
[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();
}
using Content.Server.Objectives.Components;
using Content.Shared.Objectives.Components;
-using Content.Shared.Whitelist;
+using Content.Shared.Roles;
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();
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;
}
}
/// 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:
[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>
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Item;
-using Content.Shared.Roles;
using Content.Shared.Tag;
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;
}
}
- 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)
issuer: objective-issuer-dragon
- type: RoleRequirement
roles:
- mindRoles:
- - DragonRole
+ - DragonRole
- type: entity
parent: BaseDragonObjective
issuer: objective-issuer-spiderclan
- type: RoleRequirement
roles:
- mindRoles:
- - NinjaRole
+ - NinjaRole
- type: entity
parent: BaseNinjaObjective
issuer: objective-issuer-paradox
- type: RoleRequirement
roles:
- mindRoles:
- - ParadoxCloneRole
+ - ParadoxCloneRole
- type: Tag
tags:
- ParadoxCloneObjectiveBlacklist # don't copy the objectives from other clones
issuer: objective-issuer-thief
- type: RoleRequirement
roles:
- mindRoles:
- - ThiefRole
+ - ThiefRole
- type: entity
abstract: true
issuer: objective-issuer-syndicate
- type: RoleRequirement
roles:
- mindRoles:
- - TraitorRole
+ - TraitorRole
- type: entity
abstract: true
issuer: objective-issuer-swf
- type: RoleRequirement
roles:
- mindRoles:
- - WizardRole
+ - WizardRole
- type: entity
parent: [BaseWizardObjective, BaseSurviveObjective]