]> git.deb.at Git - rhonda/impostor.git/commitdiff
Add handler for phantom rpcs
authorNiko233 <139348239+NikoCat233@users.noreply.github.com>
Mon, 24 Jun 2024 10:00:09 +0000 (18:00 +0800)
committerminiduikboot <mini@duikbo.at>
Tue, 20 Aug 2024 19:41:38 +0000 (21:41 +0200)
src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs
src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs

index 46bb7094150c9d468e2b4c03677bb08ac6d598d2..34163f6e5c66860e29eef038afa82186ef2f4fe5 100644 (file)
@@ -148,5 +148,19 @@ namespace Impostor.Server.Net.Inner.Objects
             // Notify plugins.
             await _eventManager.CallAsync(new PlayerExileEvent(Game, Game.GetClientPlayer(OwnerId)!, this));
         }
+
+        public async ValueTask StartVanishAsync()
+        {
+            using var writer = Game.StartRpc(NetId, RpcCalls.StartVanish);
+            Rpc63StartVanish.Serialize(writer);
+            await Game.FinishRpcAsync(writer);
+        }
+
+        public async ValueTask StartAppearAsync(bool shouldAnimate)
+        {
+            using var writer = Game.StartRpc(NetId, RpcCalls.StartAppear);
+            Rpc65StartAppear.Serialize(writer, shouldAnimate);
+            await Game.FinishRpcAsync(writer);
+        }
     }
 }
index c3d88727dfcabc616426f8fde92a46fcd890300a..60340ce1f9806c7f75b8b3bb7190b068b1c43be2 100644 (file)
@@ -536,7 +536,7 @@ namespace Impostor.Server.Net.Inner.Objects
                     }
 
                     Rpc62CheckVanish.Deserialize(reader, out var maxDuration);
-                    break;
+                    return await HandleCheckVanish(sender, maxDuration);
                 }
 
                 case RpcCalls.StartVanish:
@@ -548,7 +548,7 @@ namespace Impostor.Server.Net.Inner.Objects
                     }
 
                     Rpc63StartVanish.Deserialize(reader);
-                    break;
+                    return await HandleStartVanish(sender);
                 }
 
                 case RpcCalls.CheckAppear:
@@ -560,8 +560,8 @@ namespace Impostor.Server.Net.Inner.Objects
                         return false;
                     }
 
-                    Rpc64CheckAppear.Deserialize(reader, out bool shouldAnimate);
-                    break;
+                    Rpc64CheckAppear.Deserialize(reader, out var shouldAnimate);
+                    return await HandleCheckAppear(sender, shouldAnimate);
                 }
 
                 case RpcCalls.StartAppear:
@@ -572,8 +572,8 @@ namespace Impostor.Server.Net.Inner.Objects
                         return false;
                     }
 
-                    Rpc65StartAppear.Deserialize(reader, out _);
-                    break;
+                    Rpc65StartAppear.Deserialize(reader, out var shouldAnimate);
+                    return await HandleStartAppear(sender, shouldAnimate);
                 }
 
                 default:
@@ -1071,5 +1071,61 @@ namespace Impostor.Server.Net.Inner.Objects
 
             return true;
         }
+
+        private async ValueTask<bool> HandleCheckVanish(ClientPlayer sender, float maxDuration)
+        {
+            // TODO: Check if operation is taking place during lobby/meetings
+            // TODO: Check that the player unvanished before the maximum duration is reached
+            // If the game is host authoritive, the RPC is handled by the host, otherwise by the server
+            if (_game.IsHostAuthoritive)
+            {
+                return true;
+            }
+            else
+            {
+                await StartVanishAsync();
+                return false;
+            }
+        }
+
+        private async ValueTask<bool> HandleStartVanish(ClientPlayer sender)
+        {
+            if (!_game.IsHostAuthoritive)
+            {
+                if (await sender.Client.ReportCheatAsync(RpcCalls.StartVanish, CheatCategory.GameFlow, "Client tried to send StartVanish directly"))
+                {
+                    return false;
+                }
+            }
+
+            return true;
+        }
+
+        private async ValueTask<bool> HandleCheckAppear(ClientPlayer sender, bool shouldAnimate)
+        {
+            // If the game is host authoritive, the RPC is handled by the host, otherwise by the server
+            if (_game.IsHostAuthoritive)
+            {
+                return true;
+            }
+            else
+            {
+                await StartAppearAsync(shouldAnimate);
+                return false;
+            }
+        }
+
+        private async ValueTask<bool> HandleStartAppear(ClientPlayer sender, bool shouldAnimate)
+        {
+            if (!_game.IsHostAuthoritive)
+            {
+                if (await sender.Client.ReportCheatAsync(RpcCalls.StartAppear, CheatCategory.GameFlow, "Client tried to send StartAppear directly"))
+                {
+                    return false;
+                }
+            }
+
+            return true;
+        }
     }
 }