From: AeonLucid Date: Thu, 12 Nov 2020 03:32:30 +0000 (+0100) Subject: Fixes #115 and #118 - Proper SetInfected packet body X-Git-Tag: v1.2.2~23 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=2ea270d577c3f3be9939fa4123e9bb7c3ce0f8a5;p=rhonda%2Fimpostor.git Fixes #115 and #118 - Proper SetInfected packet body --- diff --git a/src/Impostor.Api/Games/IGame.cs b/src/Impostor.Api/Games/IGame.cs index ab42371..ad71986 100644 --- a/src/Impostor.Api/Games/IGame.cs +++ b/src/Impostor.Api/Games/IGame.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Impostor.Api.Innersloth; using Impostor.Api.Net; using Impostor.Api.Net.Inner; +using Impostor.Api.Net.Inner.Objects; using Impostor.Api.Net.Messages; namespace Impostor.Api.Games @@ -49,9 +50,16 @@ namespace Impostor.Api.Games /// Syncs the internal to all players. /// Necessary to do if you modified it, otherwise it won't be used. /// - /// + /// A representing the asynchronous operation. ValueTask SyncSettingsAsync(); + /// + /// Sets the specified list as Impostor on all connected players. + /// + /// List of players to be Impostor. + /// A representing the asynchronous operation. + ValueTask SetInfectedAsync(IEnumerable players); + /// /// Send the message to all players. /// @@ -77,4 +85,4 @@ namespace Impostor.Api.Games /// A representing the asynchronous operation. ValueTask SendToAsync(IMessageWriter writer, int id); } -} \ No newline at end of file +} diff --git a/src/Impostor.Api/Net/IClientPlayer.cs b/src/Impostor.Api/Net/IClientPlayer.cs index 1a21bc3..6070210 100644 --- a/src/Impostor.Api/Net/IClientPlayer.cs +++ b/src/Impostor.Api/Net/IClientPlayer.cs @@ -25,7 +25,7 @@ namespace Impostor.Api.Net /// LimboStates Limbo { get; set; } - IInnerPlayerControl Character { get; } + IInnerPlayerControl? Character { get; } public bool IsHost { get; } @@ -40,4 +40,4 @@ namespace Impostor.Api.Net ValueTask BanAsync(); } -} \ No newline at end of file +} diff --git a/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs b/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs index cd031db..4109509 100644 --- a/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs +++ b/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs @@ -6,6 +6,11 @@ namespace Impostor.Api.Net.Inner.Objects { public interface IInnerPlayerControl : IInnerNetObject { + /// + /// Gets the assigned by the client of the host of the game. + /// + byte PlayerId { get; } + /// /// Gets the of the . /// Contains vent logic. @@ -100,13 +105,6 @@ namespace Impostor.Api.Net.Inner.Objects /// Task that must be awaited. ValueTask SendChatToPlayerAsync(string text, IInnerPlayerControl? player = null); - /// - /// Sets the current to infected (impostor) . - /// Visible to all players. - /// - /// Task that must be awaited. - ValueTask SetInfectedAsync(); - /// /// Sets the current to be murdered . /// Visible to all players. diff --git a/src/Impostor.Server/Net/Inner/Objects/InnerGameData.cs b/src/Impostor.Server/Net/Inner/Objects/InnerGameData.cs index d4881ab..9f18a52 100644 --- a/src/Impostor.Server/Net/Inner/Objects/InnerGameData.cs +++ b/src/Impostor.Server/Net/Inner/Objects/InnerGameData.cs @@ -43,8 +43,7 @@ namespace Impostor.Server.Net.Inner.Objects return _allPlayers.TryGetValue(id, out var player) ? player : null; } - public override ValueTask HandleRpc(ClientPlayer sender, ClientPlayer? target, RpcCalls call, - IMessageReader reader) + public override ValueTask HandleRpc(ClientPlayer sender, ClientPlayer? target, RpcCalls call, IMessageReader reader) { switch (call) { diff --git a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs index 78337b9..95fad02 100644 --- a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs +++ b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs @@ -103,12 +103,5 @@ namespace Impostor.Server.Net.Inner.Objects writer.Write((byte)NetId); await _game.FinishRpcAsync(writer); } - - public async ValueTask SetInfectedAsync() - { - var writer = _game.StartRpc(NetId, RpcCalls.SetInfected); - writer.Write((byte)NetId); - await _game.FinishRpcAsync(writer); - } } } diff --git a/src/Impostor.Server/Net/State/ClientPlayer.Api.cs b/src/Impostor.Server/Net/State/ClientPlayer.Api.cs index e617cfb..2e2467e 100644 --- a/src/Impostor.Server/Net/State/ClientPlayer.Api.cs +++ b/src/Impostor.Server/Net/State/ClientPlayer.Api.cs @@ -13,6 +13,6 @@ namespace Impostor.Server.Net.State IGame IClientPlayer.Game => Game; /// - IInnerPlayerControl IClientPlayer.Character => Character; + IInnerPlayerControl? IClientPlayer.Character => Character; } -} \ No newline at end of file +} diff --git a/src/Impostor.Server/Net/State/ClientPlayer.cs b/src/Impostor.Server/Net/State/ClientPlayer.cs index addbf5f..107edbf 100644 --- a/src/Impostor.Server/Net/State/ClientPlayer.cs +++ b/src/Impostor.Server/Net/State/ClientPlayer.cs @@ -30,7 +30,7 @@ namespace Impostor.Server.Net.State /// public LimboStates Limbo { get; set; } - public InnerPlayerControl Character { get; internal set; } + public InnerPlayerControl? Character { get; internal set; } public bool IsHost => Game?.Host == this; diff --git a/src/Impostor.Server/Net/State/Game.Api.cs b/src/Impostor.Server/Net/State/Game.Api.cs index 194df87..f395be2 100644 --- a/src/Impostor.Server/Net/State/Game.Api.cs +++ b/src/Impostor.Server/Net/State/Game.Api.cs @@ -1,10 +1,13 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; using System.Net; using System.Threading.Tasks; +using Impostor.Api; using Impostor.Api.Games; using Impostor.Api.Innersloth; using Impostor.Api.Net; using Impostor.Api.Net.Inner; +using Impostor.Api.Net.Inner.Objects; using Impostor.Server.Net.Inner; namespace Impostor.Server.Net.State @@ -22,6 +25,11 @@ namespace Impostor.Server.Net.State public async ValueTask SyncSettingsAsync() { + if (Host.Character == null) + { + throw new ImpostorException("Attempted to set infected when the host was not spawned."); + } + using (var writer = StartRpc(Host.Character.NetId, RpcCalls.SyncSettings)) { // Someone will probably forget to do this, so we include it here. @@ -38,5 +46,25 @@ namespace Impostor.Server.Net.State await FinishRpcAsync(writer); } } + + public async ValueTask SetInfectedAsync(IEnumerable players) + { + if (Host.Character == null) + { + throw new ImpostorException("Attempted to set infected when the host was not spawned."); + } + + using (var writer = StartRpc(Host.Character.NetId, RpcCalls.SetInfected)) + { + writer.Write((byte)Host.Character.NetId); + + foreach (var player in players) + { + writer.Write((byte)player.PlayerId); + } + + await FinishRpcAsync(writer); + } + } } -} \ No newline at end of file +}