internal static bool GetInvokerForHashClientRpc(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
 {
     return(GetInvokerForHash(cmdHash, UNetInvokeType.ClientRpc, out invokeClass, out invokeFunction));
 }
Exemple #2
0
 public CmdItem(int Size, string Name, CmdDelegate Cmd)
 {
     size = Size;
     name = Name;
     cmd = Cmd;
 }
        static protected void RegisterSyncListDelegate(Type invokeClass, int cmdHash, CmdDelegate func)
        {
            if (s_CmdHandlerDelegates.ContainsKey(cmdHash))
            {
                return;
            }
            Invoker inv = new Invoker();

            inv.invokeType                 = UNetInvokeType.SyncList;
            inv.invokeClass                = invokeClass;
            inv.invokeFunction             = func;
            s_CmdHandlerDelegates[cmdHash] = inv;
            if (LogFilter.logDev)
            {
                Debug.Log("RegisterSyncListDelegate hash:" + cmdHash + " " + func.GetMethodName());
            }
        }
Exemple #4
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.Method.Name);
         }
     }
 }
 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.Method.Name }));
         }
     }
 }
Exemple #6
0
 protected static void RegisterRpcDelegate(Type invokeClass, string rpcName, CmdDelegate func)
 {
     RegisterDelegate(invokeClass, rpcName, MirrorInvokeType.ClientRpc, func);
 }
        protected static void RegisterDelegate(Type invokeClass, string cmdName, MirrorInvokeType invokerType, CmdDelegate func)
        {
            int cmdHash = GetMethodHash(invokeClass, cmdName); // type+func so Inventory.RpcUse != Equipment.RpcUse

            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;
                }

                Debug.LogError($"Function {oldInvoker.invokeClass}.{oldInvoker.invokeFunction.GetMethodName()} and {invokeClass}.{oldInvoker.invokeFunction.GetMethodName()} have the same hash.  Please rename one of them");
            }
            Invoker 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());
            }
        }
 public bool AreEqual(Type invokeClass, MirrorInvokeType invokeType, CmdDelegate invokeFunction)
 {
     return(this.invokeClass == invokeClass &&
            this.invokeType == invokeType &&
            this.invokeFunction == invokeFunction);
 }
        /// <summary>
        /// helper function register a Command/Rpc/SyncEvent 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);
        }
Exemple #10
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, RpcInvokeType 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 == RpcInvokeType.ServerRpc ? $" RequireAuthority:{cmdRequireAuthority}" : "";
                logger.Log($"RegisterDelegate hash: {cmdHash} invokerType: {invokerType} method: {func.Method.Name}{requireAuthorityMessage}");
            }

            return(cmdHash);
        }
 public static void RegisterCommandDelegate(Type invokeClass, string cmdName, CmdDelegate func, bool ignoreAuthority)
 {
     RegisterDelegate(invokeClass, cmdName, MirrorInvokeType.Command, func, ignoreAuthority);
 }
Exemple #12
0
 public static void RegisterRpcDelegate(Type invokeClass, string rpcName, CmdDelegate func)
 {
     RegisterDelegate(invokeClass, rpcName, RpcInvokeType.ClientRpc, func);
 }
Exemple #13
0
 public static void RegisterServerRpcDelegate(Type invokeClass, string cmdName, CmdDelegate func, bool requireAuthority)
 {
     RegisterDelegate(invokeClass, cmdName, RpcInvokeType.ServerRpc, func, requireAuthority);
 }
Exemple #14
0
 // wrapper fucntions for each type of network operation
 internal static bool GetInvokerForHashCommand(int cmdHash, out CmdDelegate invokeFunction)
 {
     return(GetInvokerForHash(cmdHash, UNetInvokeType.Command, out invokeFunction));
 }
 internal static bool GetInvokerForHashSyncEvent(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
 {
     return(GetInvokerForHash(cmdHash, UNetInvokeType.SyncEvent, out invokeClass, out invokeFunction));
 }
        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);
                }

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

            return(false);
        }
        static bool GetInvokerForHash(int cmdHash, NetworkBehaviour.UNetInvokeType invokeType, out Type invokeClass, out CmdDelegate invokeFunction)
        {
            Invoker invoker = null;

            if (!s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker))
            {
                if (LogFilter.logDev)
                {
                    Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found");
                }
                invokeClass    = null;
                invokeFunction = null;
                return(false);
            }

            if (invoker == null)
            {
                if (LogFilter.logDev)
                {
                    Debug.Log("GetInvokerForHash hash:" + cmdHash + " invoker null");
                }
                invokeClass    = null;
                invokeFunction = null;
                return(false);
            }

            if (invoker.invokeType != invokeType)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("GetInvokerForHash hash:" + cmdHash + " mismatched invokeType");
                }
                invokeClass    = null;
                invokeFunction = null;
                return(false);
            }

            invokeClass    = invoker.invokeClass;
            invokeFunction = invoker.invokeFunction;
            return(true);
        }
Exemple #18
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());
            }
        }
Exemple #19
0
 protected static void RegisterEventDelegate(Type invokeClass, string eventName, CmdDelegate func)
 {
     RegisterDelegate(invokeClass, eventName, MirrorInvokeType.SyncEvent, func);
 }
Exemple #20
0
 public CmdItem(int Size, string Name, CmdDelegate Cmd, EclDump ecl_dump)
 {
     size = Size;
     name = Name;
     cmd = Cmd;
     ecldump = ecl_dump;
 }
 protected static void RegisterCommandDelegate(Type invokeClass, string cmdName, CmdDelegate func)
 {
     RegisterDelegate(invokeClass, cmdName, MirrorInvokeType.Command, func);
 }
Exemple #22
0
 public void AddHandler(string cmd, CmdDelegate del)
 {
     cmdMaps.Add(cmd, del);
 }