]> git.deb.at Git - rhonda/impostor.git/commitdiff
Accept RPC's called on GameManager
authorminiduikboot <mini@duikbo.at>
Thu, 13 Jun 2024 18:52:25 +0000 (20:52 +0200)
committerminiduikboot <mini@duikbo.at>
Thu, 13 Jun 2024 18:52:25 +0000 (20:52 +0200)
Previously Impostor would just throw when a method was called on a
GameManager, but this caused issues with client mods that did just this,
even through vanilla never calls an RPC on GameManager.

This commit changes that throw statement to pass the exception to the
custom message handler/anticheat instead, which is also how it works for
the other NetObjects

src/Impostor.Server/Net/Inner/Objects/GameManager/InnerGameManager.cs
src/Impostor.Server/Net/Inner/Objects/GameManager/Logic/GameLogicComponent.cs

index ee727f32df8b6db80b2f9700440eaff3680bcbaa..f51b0804a7db6ac0ca62aa3f6a3ca13e64527e07 100644 (file)
@@ -53,12 +53,20 @@ internal abstract class InnerGameManager : InnerNetObject, IInnerGameManager
 
     public override async ValueTask<bool> HandleRpcAsync(ClientPlayer sender, ClientPlayer? target, RpcCalls call, IMessageReader reader)
     {
+        // Let all logic components process this RPC. If at least one component handles it, return true.
+        var result = false;
         foreach (var logicComponent in _logicComponents)
         {
-            await logicComponent.HandleRpcAsync(call, reader);
+            result |= await logicComponent.HandleRpcAsync(call, reader);
         }
 
-        return true;
+        // If no component accepted it, try and find a custom RPC that can deal with it.
+        if (!result)
+        {
+            result |= await base.HandleRpcAsync(sender, target, call, reader);
+        }
+
+        return result;
     }
 
     public override ValueTask<bool> SerializeAsync(IMessageWriter writer, bool initialState)
index 6993ddb139afd13934a8ecdca03ee8c1df430040..8ee662f8897b26a8de2e6b9a8bcfcacf81f9b33a 100644 (file)
@@ -6,9 +6,9 @@ namespace Impostor.Server.Net.Inner.Objects.GameManager.Logic;
 
 internal abstract class GameLogicComponent
 {
-    public virtual ValueTask HandleRpcAsync(RpcCalls callId, IMessageReader reader)
+    public virtual ValueTask<bool> HandleRpcAsync(RpcCalls callId, IMessageReader reader)
     {
-        throw new NotImplementedException($"Unhandled RpcCall {callId}");
+        return ValueTask.FromResult(false);
     }
 
     public virtual ValueTask<bool> SerializeAsync(IMessageWriter writer, bool initialState)