]> git.deb.at Git - rhonda/impostor.git/commitdiff
Fixes #115 and #118 - Proper SetInfected packet body
authorAeonLucid <aeonlucid@outlook.com>
Thu, 12 Nov 2020 03:32:30 +0000 (04:32 +0100)
committerAeonLucid <aeonlucid@outlook.com>
Thu, 12 Nov 2020 03:32:30 +0000 (04:32 +0100)
src/Impostor.Api/Games/IGame.cs
src/Impostor.Api/Net/IClientPlayer.cs
src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs
src/Impostor.Server/Net/Inner/Objects/InnerGameData.cs
src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs
src/Impostor.Server/Net/State/ClientPlayer.Api.cs
src/Impostor.Server/Net/State/ClientPlayer.cs
src/Impostor.Server/Net/State/Game.Api.cs

index ab42371cb40597327c951660bb065da193cc032b..ad719867eab7001fa2d876a5fd2f3fd0f2c786e2 100644 (file)
@@ -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 <see cref="GameOptionsData"/> to all players.
         ///     Necessary to do if you modified it, otherwise it won't be used.
         /// </summary>
-        /// <returns></returns>
+        /// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
         ValueTask SyncSettingsAsync();
 
+        /// <summary>
+        ///     Sets the specified list as Impostor on all connected players.
+        /// </summary>
+        /// <param name="players">List of players to be Impostor.</param>
+        /// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
+        ValueTask SetInfectedAsync(IEnumerable<IInnerPlayerControl> players);
+
         /// <summary>
         ///     Send the message to all players.
         /// </summary>
@@ -77,4 +85,4 @@ namespace Impostor.Api.Games
         /// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
         ValueTask SendToAsync(IMessageWriter writer, int id);
     }
-}
\ No newline at end of file
+}
index 1a21bc3f10f47347ead898711871b74946899c15..60702101e73e96e801ec3f98cbefff4cea3e8df1 100644 (file)
@@ -25,7 +25,7 @@ namespace Impostor.Api.Net
         /// </summary>
         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
+}
index cd031db0d192bf1348bc91c003b990c55630ec4e..4109509c1ad6de67a4c516384c2402c854b705fb 100644 (file)
@@ -6,6 +6,11 @@ namespace Impostor.Api.Net.Inner.Objects
 {
     public interface IInnerPlayerControl : IInnerNetObject
     {
+        /// <summary>
+        ///     Gets the <see cref="PlayerId"/> assigned by the client of the host of the game.
+        /// </summary>
+        byte PlayerId { get; }
+
         /// <summary>
         ///     Gets the <see cref="IInnerPlayerPhysics"/> of the <see cref="IInnerPlayerControl"/>.
         ///     Contains vent logic.
@@ -100,13 +105,6 @@ namespace Impostor.Api.Net.Inner.Objects
         /// <returns>Task that must be awaited.</returns>
         ValueTask SendChatToPlayerAsync(string text, IInnerPlayerControl? player = null);
 
-        /// <summary>
-        ///     Sets the current to infected (impostor) <see cref="IInnerPlayerControl"/>.
-        ///     Visible to all players.
-        /// </summary>
-        /// <returns>Task that must be awaited.</returns>
-        ValueTask SetInfectedAsync();
-
         /// <summary>
         ///     Sets the current to be murdered <see cref="IInnerPlayerControl"/>.
         ///     Visible to all players.
index d4881abe574a4d5d7c7f7a11aa2f7f9f62a2bc0d..9f18a52360fa6680b8542bb305f7172fd1b5f4ac 100644 (file)
@@ -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)
             {
index 78337b952a53d8687b58137032b8f11c352a8cfe..95fad02cb599b665c37cfc3b16bc5377e156e436 100644 (file)
@@ -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);
-        }
     }
 }
index e617cfb23b17540521fa4860c526c4b0a83a4ff0..2e2467e3c0951c9e944732ee71314ec007d808f5 100644 (file)
@@ -13,6 +13,6 @@ namespace Impostor.Server.Net.State
         IGame IClientPlayer.Game => Game;
 
         /// <inheritdoc />
-        IInnerPlayerControl IClientPlayer.Character => Character;
+        IInnerPlayerControl? IClientPlayer.Character => Character;
     }
-}
\ No newline at end of file
+}
index addbf5f1a216981ac38ea128d02c03906eed8661..107edbfef3d457a439f307c0d67aca43273e023a 100644 (file)
@@ -30,7 +30,7 @@ namespace Impostor.Server.Net.State
         /// <inheritdoc />
         public LimboStates Limbo { get; set; }
 
-        public InnerPlayerControl Character { get; internal set; }
+        public InnerPlayerControl? Character { get; internal set; }
 
         public bool IsHost => Game?.Host == this;
 
index 194df87c20f14c6ea868e112f69a0c11efd0f219..f395be29234b3a12c86a4eed8dc4694a14dbd0bf 100644 (file)
@@ -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<IInnerPlayerControl> 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
+}