]> git.deb.at Git - rhonda/impostor.git/commitdiff
Added deserialization checks
authorAeonLucid <aeonlucid@outlook.com>
Fri, 23 Oct 2020 22:28:02 +0000 (00:28 +0200)
committerAeonLucid <aeonlucid@outlook.com>
Fri, 23 Oct 2020 22:28:02 +0000 (00:28 +0200)
src/Impostor.Api/Innersloth/Net/Objects/Components/InnerCustomNetworkTransform.cs
src/Impostor.Api/Innersloth/Net/Objects/Components/InnerVoteBanSystem.cs
src/Impostor.Api/Innersloth/Net/Objects/InnerGameData.cs
src/Impostor.Api/Innersloth/Net/Objects/InnerMeetingHud.cs
src/Impostor.Api/Innersloth/Net/Objects/InnerPlayerControl.cs
src/Impostor.Api/Innersloth/Net/Objects/InnerShipStatus.cs
src/Impostor.Tools.ServerReplay/Program.cs

index 15f043701067368a4aa40903419ac36634d54a19..f8b347641d340be4cd21e4e688b6136813077238 100644 (file)
@@ -1,4 +1,5 @@
-using System.Numerics;
+using System;
+using System.Numerics;
 using Impostor.Api.Net;
 using Impostor.Api.Net.Messages;
 using Microsoft.Extensions.Logging;
@@ -87,6 +88,16 @@ namespace Impostor.Api.Innersloth.Net.Objects.Components
             }
             else
             {
+                if (!sender.IsOwner(this))
+                {
+                    throw new ImpostorCheatException($"Client attempted to send unowned {nameof(InnerCustomNetworkTransform)} data.");
+                }
+
+                if (target != null)
+                {
+                    throw new ImpostorCheatException($"Client attempted to send {nameof(InnerCustomNetworkTransform)} data to a specific player, must be broadcast.");
+                }
+
                 if (!SidGreaterThan(sequenceId, _lastSequenceId))
                 {
                     return;
index b77e56337d8fa4d7beb7e1b88b47ca6e21978d48..9dbe92f53f623f758de45359c59c5329bf6827f5 100644 (file)
@@ -48,6 +48,11 @@ namespace Impostor.Api.Innersloth.Net.Objects.Components
 
         public override void Deserialize(IClientPlayer sender, IClientPlayer? target, IMessageReader reader, bool initialState)
         {
+            if (!sender.IsHost)
+            {
+                throw new ImpostorCheatException($"Client attempted to send data for {nameof(InnerShipStatus)} as non-host.");
+            }
+
             var votes = _votes;
             var unknown = reader.ReadByte();
             if (unknown != 0)
index cf5d307d73756ac3ff284e24df5070c679c1c9e0..3de285281cb9be2321320279f327c9defbc57f29 100644 (file)
@@ -114,6 +114,11 @@ namespace Impostor.Api.Innersloth.Net.Objects
 
         public override void Deserialize(IClientPlayer sender, IClientPlayer? target, IMessageReader reader, bool initialState)
         {
+            if (!sender.IsHost)
+            {
+                throw new ImpostorCheatException($"Client attempted to send data for {nameof(InnerGameData)} as non-host.");
+            }
+
             if (initialState)
             {
                 var num = reader.ReadPackedInt32();
index f00c6ef69a279a14d34cd3ebef7a00a44eb6c48e..a20389732d07b6e53764991e3ff81a285ffae9a3 100644 (file)
@@ -1,7 +1,6 @@
 using System;
 using System.Linq;
 using Impostor.Api.Games;
-using Impostor.Api.Innersloth.Data;
 using Impostor.Api.Net;
 using Impostor.Api.Net.Messages;
 using Microsoft.Extensions.Logging;
@@ -115,6 +114,16 @@ namespace Impostor.Api.Innersloth.Net.Objects
 
         public override void Deserialize(IClientPlayer sender, IClientPlayer? target, IMessageReader reader, bool initialState)
         {
+            if (!sender.IsHost)
+            {
+                throw new ImpostorCheatException($"Client attempted to send data for {nameof(InnerMeetingHud)} as non-host.");
+            }
+
+            if (target != null)
+            {
+                throw new ImpostorCheatException($"Client attempted to send {nameof(InnerMeetingHud)} data to a specific player, must be broadcast.");
+            }
+
             if (initialState)
             {
                 PopulateButtons(0);
index bfc8fe19099056cbc59a14436498018049618e02..dd2eb8a3bc114f4686d73d5c97d5ee7b30f1834c 100644 (file)
@@ -378,6 +378,11 @@ namespace Impostor.Api.Innersloth.Net.Objects
 
         public override void Deserialize(IClientPlayer sender, IClientPlayer? target, IMessageReader reader, bool initialState)
         {
+            if (!sender.IsHost)
+            {
+                throw new ImpostorCheatException($"Client attempted to send data for {nameof(InnerPlayerControl)} as non-host.");
+            }
+
             if (initialState)
             {
                 IsNew = reader.ReadBoolean();
@@ -390,6 +395,8 @@ namespace Impostor.Api.Innersloth.Net.Objects
         {
             PlayerInfo.IsDead = true;
             PlayerInfo.LastDeathReason = reason;
+
+            Console.WriteLine($"{PlayerInfo.PlayerName,-15} died {reason}");
         }
     }
 }
\ No newline at end of file
index 806837f2a13b435a4f65de79aa7569ca23298a5a..abbbb251e8da60ed837469db4f931811ce05cc34 100644 (file)
@@ -99,6 +99,16 @@ namespace Impostor.Api.Innersloth.Net.Objects
 
         public override void Deserialize(IClientPlayer sender, IClientPlayer? target, IMessageReader reader, bool initialState)
         {
+            if (!sender.IsHost)
+            {
+                throw new ImpostorCheatException($"Client attempted to send data for {nameof(InnerShipStatus)} as non-host.");
+            }
+
+            if (target != null)
+            {
+                throw new ImpostorCheatException($"Client attempted to send {nameof(InnerShipStatus)} data to a specific player, must be broadcast.");
+            }
+
             if (initialState)
             {
                 // TODO: (_systems[SystemTypes.Doors] as DoorsSystemType).SetDoors();
index c904081610fb0f0782e10c57b47a6c3566d1f108..7a8802da73b6ff12b6581148dcc431422d3a1c50 100644 (file)
@@ -42,11 +42,11 @@ namespace Impostor.Tools.ServerReplay
 
         private static async Task Main(string[] args)
         {
-            Log.Logger = new LoggerConfiguration()
-                // .MinimumLevel.Verbose()
-                .MinimumLevel.Debug()
-                .WriteTo.Console()
-                .CreateLogger();
+            // Log.Logger = new LoggerConfiguration()
+            //     // .MinimumLevel.Verbose()
+            //     .MinimumLevel.Debug()
+            //     .WriteTo.Console()
+            //     .CreateLogger();
 
             var stopwatch = Stopwatch.StartNew();