예제 #1
0
        protected static void RegisterDelegate(Type invokeClass, string cmdName, MirrorInvokeType invokerType,
                                               CmdDelegate func)
        {
            var cmdHash = GetMethodHash(invokeClass, cmdName); // type+func so Inventory.RpcUse != Equipment.RpcUse

            if (cmdHandlerDelegates.ContainsKey(cmdHash))
            {
                // something already registered this hash
                var oldInvoker = cmdHandlerDelegates[cmdHash];
                if (oldInvoker.invokeClass == invokeClass && oldInvoker.invokeType == invokerType &&
                    oldInvoker.invokeFunction == func)
                {
                    // it's all right,  it was the same function
                    return;
                }

                Debug.LogError(
                    $"Function {oldInvoker.invokeClass}.{oldInvoker.invokeFunction.GetMethodName()} and {invokeClass}.{oldInvoker.invokeFunction.GetMethodName()} have the same hash.  Please rename one of them");
            }

            var invoker = new Invoker
            {
                invokeType     = invokerType,
                invokeClass    = invokeClass,
                invokeFunction = func
            };

            cmdHandlerDelegates[cmdHash] = invoker;
            if (LogFilter.Debug)
            {
                Debug.Log("RegisterDelegate hash:" + cmdHash + " invokerType: " + invokerType + " method:" +
                          func.GetMethodName());
            }
        }
예제 #2
0
 protected static void RegisterSyncListDelegate(Type invokeClass, int cmdHash, CmdDelegate func)
 {
     if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
     {
         Invoker invoker = new Invoker();
         invoker.invokeType             = UNetInvokeType.SyncList;
         invoker.invokeClass            = invokeClass;
         invoker.invokeFunction         = func;
         s_CmdHandlerDelegates[cmdHash] = invoker;
         if (LogFilter.logDev)
         {
             Debug.Log("RegisterSyncListDelegate hash:" + cmdHash + " " + func.GetMethodName());
         }
     }
 }
예제 #3
0
        protected static void RegisterEventDelegate(Type invokeClass, int cmdHash, CmdDelegate func)
        {
            if (s_CmdHandlerDelegates.ContainsKey(cmdHash))
            {
                return;
            }
            Invoker inv = new Invoker();

            inv.invokeType                 = UNetInvokeType.SyncEvent;
            inv.invokeClass                = invokeClass;
            inv.invokeFunction             = func;
            s_CmdHandlerDelegates[cmdHash] = inv;
            if (LogFilter.Debug)
            {
                Debug.Log("RegisterEventDelegate hash:" + cmdHash + " " + func.GetMethodName());
            }
        }
예제 #4
0
        static bool CheckIfDeligateExists(Type invokeClass, MirrorInvokeType invokerType, CmdDelegate func, int cmdHash)
        {
            if (cmdHandlerDelegates.ContainsKey(cmdHash))
            {
                // something already registered this hash
                Invoker oldInvoker = cmdHandlerDelegates[cmdHash];
                if (oldInvoker.AreEqual(invokeClass, invokerType, func))
                {
                    // it's all right,  it was the same function
                    return(true);
                }

                Debug.LogError($"Function {oldInvoker.invokeClass}.{oldInvoker.invokeFunction.GetMethodName()} and {invokeClass}.{func.GetMethodName()} have the same hash.  Please rename one of them");
            }

            return(false);
        }
예제 #5
0
        protected static void RegisterDelegate(Type invokeClass, string cmdName, UNetInvokeType invokerType, CmdDelegate func)
        {
            int cmdHash = (invokeClass + ":" + cmdName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse

            if (s_CmdHandlerDelegates.ContainsKey(cmdHash))
            {
                // something already registered this hash
                Invoker oldInvoker = s_CmdHandlerDelegates[cmdHash];
                if (oldInvoker.invokeClass == invokeClass && oldInvoker.invokeType == invokerType && oldInvoker.invokeFunction == func)
                {
                    // it's all right,  it was the same function
                    return;
                }

                Debug.LogError(string.Format(
                                   "Function {0}.{1} and {2}.{3} have the same hash.  Please rename one of them",
                                   oldInvoker.invokeClass,
                                   oldInvoker.invokeFunction.GetMethodName(),
                                   invokeClass,
                                   oldInvoker.invokeFunction.GetMethodName()));
            }
            Invoker invoker = new Invoker();

            invoker.invokeType             = invokerType;
            invoker.invokeClass            = invokeClass;
            invoker.invokeFunction         = func;
            s_CmdHandlerDelegates[cmdHash] = invoker;
            if (LogFilter.Debug)
            {
                Debug.Log("RegisterDelegate hash:" + cmdHash + " invokerType: " + invokerType + " method:" + func.GetMethodName());
            }
        }
예제 #6
0
 protected static void RegisterSyncListDelegate(System.Type invokeClass, int cmdHash, CmdDelegate func)
 {
     if (!s_CmdHandlerDelegates.ContainsKey(cmdHash))
     {
         Invoker invoker = new Invoker {
             invokeType     = UNetInvokeType.SyncList,
             invokeClass    = invokeClass,
             invokeFunction = func
         };
         s_CmdHandlerDelegates[cmdHash] = invoker;
         if (LogFilter.logDev)
         {
             Debug.Log(string.Concat(new object[] { "RegisterSyncListDelegate hash:", cmdHash, " ", func.GetMethodName() }));
         }
     }
 }
예제 #7
0
        /// <summary>
        /// helper function register a ServerRpc/Rpc delegate
        /// </summary>
        /// <param name="invokeClass"></param>
        /// <param name="cmdName"></param>
        /// <param name="invokerType"></param>
        /// <param name="func"></param>
        /// <param name="cmdRequireAuthority"></param>
        /// <returns>remote function hash</returns>
        public static int RegisterDelegate(Type invokeClass, string cmdName, MirageInvokeType invokerType, CmdDelegate func, bool cmdRequireAuthority = true)
        {
            // type+func so Inventory.RpcUse != Equipment.RpcUse
            int cmdHash = GetMethodHash(invokeClass, cmdName);

            if (CheckIfDelegateExists(invokeClass, invokerType, func, cmdHash))
            {
                return(cmdHash);
            }

            var invoker = new Skeleton
            {
                invokeType          = invokerType,
                invokeClass         = invokeClass,
                invokeFunction      = func,
                cmdRequireAuthority = cmdRequireAuthority,
            };

            cmdHandlerDelegates[cmdHash] = invoker;

            if (logger.LogEnabled())
            {
                string requireAuthorityMessage = invokerType == MirageInvokeType.ServerRpc ? $" RequireAuthority:{cmdRequireAuthority}" : "";
                logger.Log($"RegisterDelegate hash: {cmdHash} invokerType: {invokerType} method: {func.GetMethodName()}{requireAuthorityMessage}");
            }

            return(cmdHash);
        }
예제 #8
0
 public string DebugString()
 {
     return(invokeType + ":" + invokeClass + ":" + invokeFunction.GetMethodName());
 }
예제 #9
0
        /// <summary>
        /// helper function register a Command/Rpc delegate
        /// </summary>
        /// <param name="invokeClass"></param>
        /// <param name="cmdName"></param>
        /// <param name="invokerType"></param>
        /// <param name="func"></param>
        /// <param name="cmdIgnoreAuthority"></param>
        /// <returns>remote function hash</returns>
        internal static int RegisterDelegate(Type invokeClass, string cmdName, MirrorInvokeType invokerType, CmdDelegate func, bool cmdIgnoreAuthority = false)
        {
            // type+func so Inventory.RpcUse != Equipment.RpcUse
            int cmdHash = GetMethodHash(invokeClass, cmdName);

            if (CheckIfDeligateExists(invokeClass, invokerType, func, cmdHash))
            {
                return(cmdHash);
            }

            Invoker invoker = new Invoker
            {
                invokeType         = invokerType,
                invokeClass        = invokeClass,
                invokeFunction     = func,
                cmdIgnoreAuthority = cmdIgnoreAuthority,
            };

            cmdHandlerDelegates[cmdHash] = invoker;

            if (logger.LogEnabled())
            {
                string ingoreAuthorityMessage = invokerType == MirrorInvokeType.Command ? $" IgnoreAuthority:{cmdIgnoreAuthority}" : "";
                logger.Log($"RegisterDelegate hash: {cmdHash} invokerType: {invokerType} method: {func.GetMethodName()}{ingoreAuthorityMessage}");
            }

            return(cmdHash);
        }
예제 #10
0
        protected static void RegisterDelegate(Type invokeClass, string cmdName, MirrorInvokeType invokerType, CmdDelegate func, bool cmdIgnoreAuthority = false)
        {
            // type+func so Inventory.RpcUse != Equipment.RpcUse
            int cmdHash = GetMethodHash(invokeClass, cmdName);

            if (cmdHandlerDelegates.ContainsKey(cmdHash))
            {
                // something already registered this hash
                Invoker oldInvoker = cmdHandlerDelegates[cmdHash];
                if (oldInvoker.invokeClass == invokeClass &&
                    oldInvoker.invokeType == invokerType &&
                    oldInvoker.invokeFunction == func)
                {
                    // it's all right,  it was the same function
                    return;
                }

                logger.LogError($"Function {oldInvoker.invokeClass}.{oldInvoker.invokeFunction.GetMethodName()} and {invokeClass}.{func.GetMethodName()} have the same hash.  Please rename one of them");
            }
            Invoker invoker = new Invoker
            {
                invokeType         = invokerType,
                invokeClass        = invokeClass,
                invokeFunction     = func,
                cmdIgnoreAuthority = cmdIgnoreAuthority,
            };

            cmdHandlerDelegates[cmdHash] = invoker;
            if (logger.LogEnabled())
            {
                logger.Log("RegisterDelegate hash:" + cmdHash + " invokerType: " + invokerType + " method:" + func.GetMethodName());
            }
        }