From: Ziad Montaser <62536773+ZiadMontaser@users.noreply.github.com> Date: Mon, 30 Nov 2020 19:41:46 +0000 (+0400) Subject: Fix set murdered (#192) X-Git-Tag: v1.2.2~5 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=e8f51f6b68938928be9d245d3df0b8558e6dd475;p=rhonda%2Fimpostor.git Fix set murdered (#192) Co-authored-by: Ziad Montaser Co-authored-by: AeonLucid --- diff --git a/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs b/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs index 4109509..04558b9 100644 --- a/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs +++ b/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs @@ -106,10 +106,11 @@ namespace Impostor.Api.Net.Inner.Objects ValueTask SendChatToPlayerAsync(string text, IInnerPlayerControl? player = null); /// - /// Sets the current to be murdered . + /// Sets the current to be murdered by an impostor . /// Visible to all players. /// + /// /// The Impostor who kill. /// Task that must be awaited. - ValueTask SetMurderedAsync(); + ValueTask SetMurderedByAsync(IClientPlayer impostor); } } diff --git a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs index 49076bf..0a7997d 100644 --- a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs +++ b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs @@ -1,7 +1,11 @@ using System.Threading.Tasks; +using Impostor.Api; +using Impostor.Api.Innersloth; using Impostor.Api.Innersloth.Customization; +using Impostor.Api.Net; using Impostor.Api.Net.Inner.Objects; using Impostor.Api.Net.Inner.Objects.Components; +using Impostor.Server.Events.Player; namespace Impostor.Server.Net.Inner.Objects { @@ -97,11 +101,38 @@ namespace Impostor.Server.Net.Inner.Objects await _game.FinishRpcAsync(writer, player.OwnerId); } - public async ValueTask SetMurderedAsync() + public async ValueTask SetMurderedByAsync(IClientPlayer impostor) { - using var writer = _game.StartRpc(NetId, RpcCalls.MurderPlayer); - writer.Write((byte)NetId); + if (impostor.Character == null) + { + throw new ImpostorException("Character is null."); + } + + if (!impostor.Character.PlayerInfo.IsImpostor) + { + throw new ImpostorProtocolException("Plugin tried to murder a player while the impostor specified was not an impostor."); + } + + if (impostor.Character.PlayerInfo.IsDead) + { + throw new ImpostorProtocolException("Plugin tried to murder a player while the impostor specified was dead."); + } + + if (PlayerInfo.IsDead) + { + return; + } + + // Update player. + Die(DeathReason.Kill); + + // Send RPC. + using var writer = _game.StartRpc(impostor.Character.NetId, RpcCalls.MurderPlayer); + writer.WritePacked(NetId); await _game.FinishRpcAsync(writer); + + // Notify plugins. + await _eventManager.CallAsync(new PlayerMurderEvent(_game, impostor, impostor.Character, this)); } } }