From: miniduikboot Date: Mon, 17 May 2021 17:13:54 +0000 (+0200) Subject: Fix KeyNotFoundException for nonexistent vents (#413) X-Git-Tag: v1.4.0~1 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=a13fee108f36d828e46bfd2315457b85b87ec35e;p=rhonda%2Fimpostor.git Fix KeyNotFoundException for nonexistent vents (#413) Some mods add extra vents that don't yet exist, this commit checks if a given vent exists and if it doesn't, throw an AC violation instead of disconnecting the player One downside is that the Enter/ExitVent events are no longer called, but this would require the vent in that event to become nullable --- diff --git a/src/Impostor.Server/Net/Inner/Objects/Components/InnerPlayerPhysics.cs b/src/Impostor.Server/Net/Inner/Objects/Components/InnerPlayerPhysics.cs index 053fbf3..7ce2860 100644 --- a/src/Impostor.Server/Net/Inner/Objects/Components/InnerPlayerPhysics.cs +++ b/src/Impostor.Server/Net/Inner/Objects/Components/InnerPlayerPhysics.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Impostor.Api.Events.Managers; +using Impostor.Api.Innersloth; using Impostor.Api.Net; using Impostor.Api.Net.Custom; using Impostor.Api.Net.Inner; @@ -65,7 +66,15 @@ namespace Impostor.Server.Net.Inner.Objects.Components throw new ArgumentOutOfRangeException(nameof(call), call, null); } - var vent = Game.GameNet.ShipStatus!.Data.Vents[ventId]; + if (!Game.GameNet.ShipStatus!.Data.Vents.TryGetValue(ventId, out var vent)) + { + if (await sender.Client.ReportCheatAsync(call, "Client interacted with nonexistent vent")) + { + return false; + } + + break; + } switch (call) {