diff --git a/Content.Server/GameObjects/EntitySystems/ConstructionSystem.cs b/Content.Server/GameObjects/EntitySystems/ConstructionSystem.cs index 96520441b8..f415bf2b98 100644 --- a/Content.Server/GameObjects/EntitySystems/ConstructionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/ConstructionSystem.cs @@ -20,6 +20,7 @@ using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Log; using Robust.Shared.Maths; using Robust.Shared.Players; using Robust.Shared.Prototypes; @@ -306,8 +307,18 @@ namespace Content.Server.GameObjects.EntitySystems private async void HandleStartItemConstruction(TryStartItemConstructionMessage ev, EntitySessionEventArgs args) { - var constructionPrototype = _prototypeManager.Index(ev.PrototypeName); - var constructionGraph = _prototypeManager.Index(constructionPrototype.Graph); + if (!_prototypeManager.TryIndex(ev.PrototypeName, out ConstructionPrototype constructionPrototype)) + { + Logger.Error($"Tried to start construction of invalid recipe '{ev.PrototypeName}'!"); + return; + } + + if (!_prototypeManager.TryIndex(constructionPrototype.Graph, out ConstructionGraphPrototype constructionGraph)) + { + Logger.Error($"Invalid construction graph '{constructionPrototype.Graph}' in recipe '{ev.PrototypeName}'!"); + return; + } + var startNode = constructionGraph.Nodes[constructionPrototype.StartNode]; var targetNode = constructionGraph.Nodes[constructionPrototype.TargetNode]; var pathFind = constructionGraph.Path(startNode.Name, targetNode.Name); @@ -352,8 +363,20 @@ namespace Content.Server.GameObjects.EntitySystems private async void HandleStartStructureConstruction(TryStartStructureConstructionMessage ev, EntitySessionEventArgs args) { - var constructionPrototype = _prototypeManager.Index(ev.PrototypeName); - var constructionGraph = _prototypeManager.Index(constructionPrototype.Graph); + if (!_prototypeManager.TryIndex(ev.PrototypeName, out ConstructionPrototype constructionPrototype)) + { + Logger.Error($"Tried to start construction of invalid recipe '{ev.PrototypeName}'!"); + RaiseNetworkEvent(new AckStructureConstructionMessage(ev.Ack)); + return; + } + + if (!_prototypeManager.TryIndex(constructionPrototype.Graph, out ConstructionGraphPrototype constructionGraph)) + { + Logger.Error($"Invalid construction graph '{constructionPrototype.Graph}' in recipe '{ev.PrototypeName}'!"); + RaiseNetworkEvent(new AckStructureConstructionMessage(ev.Ack)); + return; + } + var startNode = constructionGraph.Nodes[constructionPrototype.StartNode]; var targetNode = constructionGraph.Nodes[constructionPrototype.TargetNode]; var pathFind = constructionGraph.Path(startNode.Name, targetNode.Name);