Пример #1
0
        private void HandleMessage(IPCMessage msg)
        {
            RPCWork.RPCMessage rpcmsg = msg.rpc;

            Debuger.Log("[{0}]-> {1}({2})", msg.src, rpcmsg.name, rpcmsg.args.ToListString());

            var helper = GetMethodHelper(rpcmsg.name);

            if (helper != null)
            {
                object[] args = new object[rpcmsg.args.Length + 1];

                List <RPCWork.RPCRawArg> raw_args = rpcmsg.raw_args;

                ParameterInfo[] paramInfo = helper.method.GetParameters();

                if (args.Length == paramInfo.Length)
                {
                    for (int i = 0; i < raw_args.Count; i++)
                    {
                        if (raw_args[i].type == RPCWork.RPCArgType.PBObject)
                        {
                            args[i + 1] = m_RecvBuff.DecodeProtoMsg(raw_args[i].raw_value, null, paramInfo[i + 1].ParameterType);
                        }
                        else
                        {
                            args[i + 1] = raw_args[i].value;
                        }
                    }

                    args[0] = msg.src;

                    m_currInvokingName = rpcmsg.name;
                    m_currInvokingSrc  = msg.src;

                    try
                    {
                        helper.method.Invoke(helper.listener, BindingFlags.NonPublic, null, args, null);
                    }
                    catch (Exception e)
                    {
                        Debuger.LogError("RPC调用出错:{0}\n{1}", e.Message, e.StackTrace);
                    }

                    m_currInvokingName = "";
                    m_currInvokingSrc  = 0;
                }
                else
                {
                    Debuger.LogWarning("参数数量不一致!");
                }
            }
            else
            {
                Debuger.LogWarning("RPC不存在!");
            }
        }
Пример #2
0
        private void DoReceiveInMain()
        {
            lock (m_RecvBufferQueue)
            {
                if (m_RecvBufferQueue.Count > 0)
                {
                    byte[] buffer = m_RecvBufferQueue.Dequeue();
                    m_RecvBuff.Reset();
                    m_RecvBuff.In(buffer, 0, (uint)buffer.Length);
                    IPCMessage msg = new IPCMessage();
                    m_RecvBuff.DecodeProtoMsg(msg);

                    HandleMessage(msg);
                }
            }
        }
Пример #3
0
        public void Invoke(int dst, string name, params object[] args)
        {
            Debuger.Log("->[{0}] {1}({2})", dst, name, args.ToListString());

            RPCWork.RPCMessage rpcmsg = new RPCWork.RPCMessage();
            rpcmsg.name = name;
            rpcmsg.args = args;

            IPCMessage msg = new IPCMessage();

            msg.src = m_id;
            msg.rpc = rpcmsg;

            m_SendBuff.Reset();
            m_SendBuff.EncodeProtoMsg(msg);
            SendMessage(dst, m_SendBuff.GetBuffer(), (int)m_SendBuff.Size);
        }
Пример #4
0
        public void ReturnError(string errinfo, int errcode = 1)
        {
            var name = "On" + m_currInvokingName + "Error";

            Debuger.LogWarning("->[{0}] {1}({2},{3})", m_currInvokingSrc, name, errinfo, errcode);

            RPCWork.RPCMessage rpcmsg = new RPCWork.RPCMessage();
            rpcmsg.name = name;
            rpcmsg.args = new object[] { errinfo, errcode };

            IPCMessage msg = new IPCMessage();

            msg.src = m_id;
            msg.rpc = rpcmsg;

            m_SendBuff.Reset();
            m_SendBuff.EncodeProtoMsg(msg);
            SendMessage(m_currInvokingSrc, m_SendBuff.GetBuffer(), (int)m_SendBuff.Size);
        }
Пример #5
0
        public void Return(params object[] args)
        {
            var name = "On" + m_currInvokingName;

            Debuger.Log("->[{0}] {1}({2})", m_currInvokingSrc, name, args.ToListString());

            RPCWork.RPCMessage rpcmsg = new RPCWork.RPCMessage();
            rpcmsg.name = name;
            rpcmsg.args = args;

            IPCMessage msg = new IPCMessage();

            msg.src = m_id;
            msg.rpc = rpcmsg;

            m_SendBuff.Reset();
            m_SendBuff.EncodeProtoMsg(msg);
            SendMessage(m_currInvokingSrc, m_SendBuff.GetBuffer(), (int)m_SendBuff.Size);
        }