From dcb903b272d5337fcf9090d0d5cd2ce59cea3e04 Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Sat, 24 Oct 2020 00:04:43 +0200 Subject: [PATCH] Added missing checks in InnerShipStatus --- .../Extensions/SystemTypesExtensions.cs | 12 +++++++++ .../Net/Objects/InnerPlayerControl.cs | 12 ++++++--- .../Innersloth/Net/Objects/InnerShipStatus.cs | 26 ++++++++++++++----- 3 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 src/Impostor.Api/Extensions/SystemTypesExtensions.cs diff --git a/src/Impostor.Api/Extensions/SystemTypesExtensions.cs b/src/Impostor.Api/Extensions/SystemTypesExtensions.cs new file mode 100644 index 0000000..e927e2e --- /dev/null +++ b/src/Impostor.Api/Extensions/SystemTypesExtensions.cs @@ -0,0 +1,12 @@ +using Impostor.Api.Innersloth.Net.Objects.Systems; + +namespace Impostor.Api +{ + public static class SystemTypesExtensions + { + public static string GetFriendlyName(this SystemTypes type) + { + return SystemTypeHelpers.Names[(int)type]; + } + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Innersloth/Net/Objects/InnerPlayerControl.cs b/src/Impostor.Api/Innersloth/Net/Objects/InnerPlayerControl.cs index 103ea06..f84de76 100644 --- a/src/Impostor.Api/Innersloth/Net/Objects/InnerPlayerControl.cs +++ b/src/Impostor.Api/Innersloth/Net/Objects/InnerPlayerControl.cs @@ -108,16 +108,15 @@ namespace Impostor.Api.Innersloth.Net.Objects { if (!sender.IsHost) { - throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetInfected)} but was not a host."); + throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.Exiled)} but was not a host."); } if (target != null) { - throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetInfected)} to a specific player instead of broadcast."); + throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.Exiled)} to a specific player instead of broadcast."); } - Console.WriteLine(PlayerInfo.PlayerName + " was voted out."); - + // TODO: Not hit? Die(DeathReason.Exile); break; } @@ -250,6 +249,11 @@ namespace Impostor.Api.Innersloth.Net.Objects } var player = reader.ReadNetObject(_game); + if (!player.PlayerInfo.IsDead) + { + player.Die(DeathReason.Kill); + } + break; } diff --git a/src/Impostor.Api/Innersloth/Net/Objects/InnerShipStatus.cs b/src/Impostor.Api/Innersloth/Net/Objects/InnerShipStatus.cs index f3960d9..3bbf9b1 100644 --- a/src/Impostor.Api/Innersloth/Net/Objects/InnerShipStatus.cs +++ b/src/Impostor.Api/Innersloth/Net/Objects/InnerShipStatus.cs @@ -48,24 +48,38 @@ namespace Impostor.Api.Innersloth.Net.Objects { case RpcCalls.CloseDoorsOfType: { + if (target == null || !target.IsHost) + { + throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CloseDoorsOfType)} to wrong destinition, must be host."); + } + if (!sender.Character.PlayerInfo.IsImpostor) { - Console.WriteLine($"OOPS Fake Impostor: {sender.Character.PlayerInfo.PlayerName} did doors"); + // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CloseDoorsOfType)} as crewmate."); } + var systemType = (SystemTypes)reader.ReadByte(); + break; } case RpcCalls.RepairSystem: { + if (target == null || !target.IsHost) + { + throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.RepairSystem)} to wrong destinition, must be host."); + } + + if (!sender.Character.PlayerInfo.IsImpostor) + { + // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.RepairSystem)} as crewmate."); + } + var systemType = (SystemTypes)reader.ReadByte(); var player = reader.ReadNetObject(_game); var amount = reader.ReadByte(); - if (systemType == SystemTypes.Sabotage && !player.PlayerInfo.IsImpostor) - { - Console.WriteLine($"OOPS Fake Impostor: {player.PlayerInfo.PlayerName} did {(SystemTypes) amount}"); - } + // TODO: Modify data (?) break; } @@ -80,7 +94,7 @@ namespace Impostor.Api.Innersloth.Net.Objects public override bool Serialize(IMessageWriter writer, bool initialState) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public override void Deserialize(IClientPlayer sender, IMessageReader reader, bool initialState) -- 2.39.5