Add Whitelist.Components yaml valiation (#40916)
* Add Whitelist.Components yaml valiation * poke_tests * fix linter --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,8 @@ using Content.Shared.Item;
|
|||||||
using Content.Shared.Tag;
|
using Content.Shared.Tag;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
|
||||||
|
|
||||||
namespace Content.Shared.Whitelist;
|
namespace Content.Shared.Whitelist;
|
||||||
|
|
||||||
@@ -32,8 +34,8 @@ public sealed partial class EntityWhitelist
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Component names that are allowed in the whitelist.
|
/// Component names that are allowed in the whitelist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField] public string[]? Components;
|
[DataField(customTypeSerializer:typeof(CustomArraySerializer<string, ComponentNameSerializer>))]
|
||||||
// TODO yaml validation
|
public string[]? Components;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Item sizes that are allowed in the whitelist.
|
/// Item sizes that are allowed in the whitelist.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
using Content.Shared.Tag;
|
using Content.Shared.Tag;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Shared.Whitelist;
|
namespace Content.Shared.Whitelist;
|
||||||
|
|
||||||
@@ -44,21 +45,13 @@ public sealed class EntityWhitelistSystem : EntitySystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsValid(EntityWhitelist list, EntityUid uid)
|
public bool IsValid(EntityWhitelist list, EntityUid uid)
|
||||||
{
|
{
|
||||||
if (list.Components != null)
|
list.Registrations ??= StringsToRegs(list.Components);
|
||||||
{
|
|
||||||
if (list.Registrations == null)
|
|
||||||
{
|
|
||||||
var regs = StringsToRegs(list.Components);
|
|
||||||
list.Registrations = new List<ComponentRegistration>();
|
|
||||||
list.Registrations.AddRange(regs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list.Registrations != null && list.Registrations.Count > 0)
|
if (list.Registrations != null)
|
||||||
{
|
{
|
||||||
foreach (var reg in list.Registrations)
|
foreach (var reg in list.Registrations)
|
||||||
{
|
{
|
||||||
if (HasComp(uid, reg.Type))
|
if (EntityManager.HasComponent(uid, reg))
|
||||||
{
|
{
|
||||||
if (!list.RequireAll)
|
if (!list.RequireAll)
|
||||||
return true;
|
return true;
|
||||||
@@ -168,25 +161,18 @@ public sealed class EntityWhitelistSystem : EntitySystem
|
|||||||
return IsWhitelistFailOrNull(blacklist, uid);
|
return IsWhitelistFailOrNull(blacklist, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ComponentRegistration> StringsToRegs(string[]? input)
|
private List<ComponentRegistration>? StringsToRegs(string[]? input)
|
||||||
{
|
{
|
||||||
var list = new List<ComponentRegistration>();
|
|
||||||
|
|
||||||
if (input == null || input.Length == 0)
|
if (input == null || input.Length == 0)
|
||||||
return list;
|
return null;
|
||||||
|
|
||||||
|
var list = new List<ComponentRegistration>(input.Length);
|
||||||
foreach (var name in input)
|
foreach (var name in input)
|
||||||
{
|
{
|
||||||
var availability = Factory.GetComponentAvailability(name);
|
if (Factory.TryGetRegistration(name, out var registration))
|
||||||
if (Factory.TryGetRegistration(name, out var registration)
|
|
||||||
&& availability == ComponentAvailability.Available)
|
|
||||||
{
|
|
||||||
list.Add(registration);
|
list.Add(registration);
|
||||||
}
|
else if (Factory.GetComponentAvailability(name) != ComponentAvailability.Ignore)
|
||||||
else if (availability == ComponentAvailability.Unknown)
|
Log.Error($"{nameof(StringsToRegs)} failed: Unknown component name {name} passed to EntityWhitelist!");
|
||||||
{
|
|
||||||
Log.Error($"StringsToRegs failed: Unknown component name {name} passed to EntityWhitelist!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@@ -146,7 +146,6 @@
|
|||||||
- RawMaterial
|
- RawMaterial
|
||||||
- Ingot
|
- Ingot
|
||||||
components:
|
components:
|
||||||
- ConstructionMaterial
|
|
||||||
- Circuitboard
|
- Circuitboard
|
||||||
- Flatpack
|
- Flatpack
|
||||||
- FloorTile
|
- FloorTile
|
||||||
|
|||||||
Reference in New Issue
Block a user