protected static void RegisterEventDelegate(Type invokeClass, int cmdHash, NetworkBehaviour.CmdDelegate func)
 {
     if (!NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
     {
         NetworkBehaviour.Invoker invoker = new NetworkBehaviour.Invoker();
         invoker.invokeType     = NetworkBehaviour.UNetInvokeType.SyncEvent;
         invoker.invokeClass    = invokeClass;
         invoker.invokeFunction = func;
         NetworkBehaviour.s_CmdHandlerDelegates[cmdHash] = invoker;
         if (LogFilter.logDev)
         {
             Debug.Log(string.Concat(new object[]
             {
                 "RegisterEventDelegate hash:",
                 cmdHash,
                 " ",
                 func.GetMethodName()
             }));
         }
     }
 }
Ejemplo n.º 2
0
 protected static void RegisterRpcDelegate(Type invokeClass, int cmdHash, NetworkBehaviour.CmdDelegate func)
 {
     if (NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
     {
         return;
     }
     NetworkBehaviour.Invoker invoker = new NetworkBehaviour.Invoker();
     invoker.invokeType     = NetworkBehaviour.UNetInvokeType.ClientRpc;
     invoker.invokeClass    = invokeClass;
     invoker.invokeFunction = func;
     NetworkBehaviour.s_CmdHandlerDelegates[cmdHash] = invoker;
     if (LogFilter.logDev)
     {
         Debug.Log(string.Concat(new object[]
         {
             "RegisterRpcDelegate hash:",
             cmdHash,
             " ",
             func.Method.Name
         }));
     }
 }
Ejemplo n.º 3
0
        public void GetDelegate()
        {
            // registerdelegate is protected, but we can use
            // RegisterCommandDelegate which calls RegisterDelegate
            NetworkBehaviour.RegisterCommandDelegate(
                typeof(NetworkBehaviourDelegateComponent),
                nameof(NetworkBehaviourDelegateComponent.Delegate),
                NetworkBehaviourDelegateComponent.Delegate);

            // get handler
            int cmdHash = NetworkBehaviour.GetMethodHash(typeof(NetworkBehaviourDelegateComponent), nameof(NetworkBehaviourDelegateComponent.Delegate));

            NetworkBehaviour.CmdDelegate func     = NetworkBehaviour.GetDelegate(cmdHash);
            NetworkBehaviour.CmdDelegate expected = NetworkBehaviourDelegateComponent.Delegate;
            Assert.That(func, Is.EqualTo(expected));

            // invalid hash should return null handler
            NetworkBehaviour.CmdDelegate funcNull = NetworkBehaviour.GetDelegate(1234);
            Assert.That(funcNull, Is.Null);

            // clean up
            NetworkBehaviour.ClearDelegates();
        }
Ejemplo n.º 4
0
 private static bool GetInvokerForHash(int cmdHash, NetworkBehaviour.UNetInvokeType invokeType, out System.Type invokeClass, out NetworkBehaviour.CmdDelegate invokeFunction)
 {
     NetworkBehaviour.Invoker invoker = (NetworkBehaviour.Invoker)null;
     if (!NetworkBehaviour.s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker))
     {
         if (LogFilter.logDev)
         {
             Debug.Log((object)("GetInvokerForHash hash:" + (object)cmdHash + " not found"));
         }
         invokeClass    = (System.Type)null;
         invokeFunction = (NetworkBehaviour.CmdDelegate)null;
         return(false);
     }
     if (invoker == null)
     {
         if (LogFilter.logDev)
         {
             Debug.Log((object)("GetInvokerForHash hash:" + (object)cmdHash + " invoker null"));
         }
         invokeClass    = (System.Type)null;
         invokeFunction = (NetworkBehaviour.CmdDelegate)null;
         return(false);
     }
     if (invoker.invokeType != invokeType)
     {
         if (LogFilter.logError)
         {
             Debug.LogError((object)("GetInvokerForHash hash:" + (object)cmdHash + " mismatched invokeType"));
         }
         invokeClass    = (System.Type)null;
         invokeFunction = (NetworkBehaviour.CmdDelegate)null;
         return(false);
     }
     invokeClass    = invoker.invokeClass;
     invokeFunction = invoker.invokeFunction;
     return(true);
 }
Ejemplo n.º 5
0
 internal static bool GetInvokerForHashSyncEvent(int cmdHash, out System.Type invokeClass, out NetworkBehaviour.CmdDelegate invokeFunction)
 {
     return(NetworkBehaviour.GetInvokerForHash(cmdHash, NetworkBehaviour.UNetInvokeType.SyncEvent, out invokeClass, out invokeFunction));
 }
Ejemplo n.º 6
0
 protected static void RegisterSyncListDelegate(System.Type invokeClass, int cmdHash, NetworkBehaviour.CmdDelegate func)
 {
     if (NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
     {
         return;
     }
     NetworkBehaviour.s_CmdHandlerDelegates[cmdHash] = new NetworkBehaviour.Invoker()
     {
         invokeType     = NetworkBehaviour.UNetInvokeType.SyncList,
         invokeClass    = invokeClass,
         invokeFunction = func
     };
     if (!LogFilter.logDev)
     {
         return;
     }
     Debug.Log((object)("RegisterSyncListDelegate hash:" + (object)cmdHash + " " + func.Method.Name));
 }
        private static bool GetInvokerForHash(int cmdHash, NetworkBehaviour.UNetInvokeType invokeType, out Type invokeClass, out NetworkBehaviour.CmdDelegate invokeFunction)
        {
            NetworkBehaviour.Invoker invoker = null;
            bool result;

            if (!NetworkBehaviour.s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker))
            {
                if (LogFilter.logDev)
                {
                    Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found");
                }
                invokeClass    = null;
                invokeFunction = null;
                result         = false;
            }
            else if (invoker == null)
            {
                if (LogFilter.logDev)
                {
                    Debug.Log("GetInvokerForHash hash:" + cmdHash + " invoker null");
                }
                invokeClass    = null;
                invokeFunction = null;
                result         = false;
            }
            else if (invoker.invokeType != invokeType)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("GetInvokerForHash hash:" + cmdHash + " mismatched invokeType");
                }
                invokeClass    = null;
                invokeFunction = null;
                result         = false;
            }
            else
            {
                invokeClass    = invoker.invokeClass;
                invokeFunction = invoker.invokeFunction;
                result         = true;
            }
            return(result);
        }
 internal static bool GetInvokerForHashClientRpc(int cmdHash, out Type invokeClass, out NetworkBehaviour.CmdDelegate invokeFunction)
 {
     return(NetworkBehaviour.GetInvokerForHash(cmdHash, NetworkBehaviour.UNetInvokeType.ClientRpc, out invokeClass, out invokeFunction));
 }