예제 #1
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);
        }
예제 #2
0
 public RemoteCall(Type declaringType, RpcInvokeType invokeType, RpcDelegate function, bool requireAuthority, string name)
 {
     DeclaringType    = declaringType;
     InvokeType       = invokeType;
     this.function    = function;
     RequireAuthority = requireAuthority;
     this.name        = name;
 }
예제 #3
0
        public bool AreEqual(Type declaringType, RpcInvokeType invokeType, RpcDelegate function)
        {
            if (InvokeType != invokeType)
            {
                return(false);
            }

            if (declaringType.IsGenericType)
            {
                return(AreEqualIgnoringGeneric(declaringType, function));
            }

            return(DeclaringType == declaringType &&
                   this.function == function);
        }
예제 #4
0
        static bool CheckIfDelegateExists(Type invokeClass, RpcInvokeType invokerType, CmdDelegate func, int cmdHash)
        {
            if (cmdHandlerDelegates.ContainsKey(cmdHash))
            {
                // something already registered this hash
                Skeleton 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.Method.Name} and {invokeClass}.{func.Method.Name} have the same hash.  Please rename one of them");
            }

            return(false);
        }
예제 #5
0
        public void Register(int index, Type invokeClass, string name, RpcInvokeType invokerType, RpcDelegate func, bool cmdRequireAuthority)
        {
            // weaver gives index, so should never give 2 indexes that are the same
            if (remoteCalls[index] != null)
            {
                throw new InvalidOperationException("2 Rpc has same index");
            }

            var call = new RemoteCall(invokeClass, invokerType, func, cmdRequireAuthority, name);

            remoteCalls[index] = call;

            if (logger.LogEnabled())
            {
                var requireAuthorityMessage = invokerType == RpcInvokeType.ServerRpc ? $" RequireAuthority:{cmdRequireAuthority}" : "";
                logger.Log($"RegisterDelegate invokerType: {invokerType} method: {func.Method.Name}{requireAuthorityMessage}");
            }
        }
예제 #6
0
 public bool AreEqual(Type invokeClass, RpcInvokeType invokeType, CmdDelegate invokeFunction)
 {
     return(this.invokeClass == invokeClass &&
            this.invokeType == invokeType &&
            this.invokeFunction == invokeFunction);
 }