Validate prototype ids in c# fields (#18224)
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.GameTicking.Rules.Components;
|
||||
|
||||
/// <summary>
|
||||
@@ -8,12 +11,12 @@ namespace Content.Server.GameTicking.Rules.Components;
|
||||
[RegisterComponent]
|
||||
public sealed class NukeOperativeSpawnerComponent : Component
|
||||
{
|
||||
[DataField("name")]
|
||||
public string OperativeName = "";
|
||||
[DataField("name", required:true)]
|
||||
public string OperativeName = default!;
|
||||
|
||||
[DataField("rolePrototype")]
|
||||
public string OperativeRolePrototype = "";
|
||||
[DataField("rolePrototype", customTypeSerializer:typeof(PrototypeIdSerializer<AntagPrototype>), required:true)]
|
||||
public string OperativeRolePrototype = default!;
|
||||
|
||||
[DataField("startingGearPrototype")]
|
||||
public string OperativeStartingGear = "";
|
||||
[DataField("startingGearPrototype", customTypeSerializer:typeof(PrototypeIdSerializer<StartingGearPrototype>), required:true)]
|
||||
public string OperativeStartingGear = default!;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Roles;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
@@ -43,19 +44,19 @@ public sealed class NukeopsRuleComponent : Component
|
||||
[DataField("spawnOutpost")]
|
||||
public bool SpawnOutpost = true;
|
||||
|
||||
[DataField("spawnPointProto", customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
|
||||
[DataField("spawnPointProto", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string SpawnPointPrototype = "SpawnPointNukies";
|
||||
|
||||
[DataField("ghostSpawnPointProto", customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
|
||||
[DataField("ghostSpawnPointProto", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string GhostSpawnPointProto = "SpawnPointGhostNukeOperative";
|
||||
|
||||
[DataField("commanderRoleProto", customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
|
||||
[DataField("commanderRoleProto", customTypeSerializer: typeof(PrototypeIdSerializer<AntagPrototype>))]
|
||||
public string CommanderRolePrototype = "NukeopsCommander";
|
||||
|
||||
[DataField("operativeRoleProto", customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
|
||||
[DataField("operativeRoleProto", customTypeSerializer: typeof(PrototypeIdSerializer<AntagPrototype>))]
|
||||
public string OperativeRoleProto = "Nukeops";
|
||||
|
||||
[DataField("medicRoleProto", customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
|
||||
[DataField("medicRoleProto", customTypeSerializer: typeof(PrototypeIdSerializer<AntagPrototype>))]
|
||||
public string MedicRoleProto = "NukeopsMedic";
|
||||
|
||||
[DataField("commanderStartingGearProto", customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
|
||||
|
||||
@@ -574,6 +574,15 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
|
||||
// todo: this is kinda awful for multi-nukies
|
||||
foreach (var nukeops in EntityQuery<NukeopsRuleComponent>())
|
||||
{
|
||||
if (nukeOpSpawner.OperativeName == null
|
||||
|| nukeOpSpawner.OperativeStartingGear == null
|
||||
|| nukeOpSpawner.OperativeRolePrototype == null)
|
||||
{
|
||||
// I have no idea what is going on with nuke ops code, but I'm pretty sure this shouldn't be possible.
|
||||
Log.Error($"Invalid nuke op spawner: {ToPrettyString(spawner)}");
|
||||
continue;
|
||||
}
|
||||
|
||||
SetupOperativeEntity(uid, nukeOpSpawner.OperativeName, nukeOpSpawner.OperativeStartingGear, profile, nukeops);
|
||||
|
||||
nukeops.OperativeMindPendingData.Add(uid, nukeOpSpawner.OperativeRolePrototype);
|
||||
|
||||
Reference in New Issue
Block a user