private void HandleRPCMessage(ISession session, RPCMessage rpcMessage) { RPCMethodHelper helper = rpcManager.GetMethodHelper(rpcMessage.name); if (helper != null) { object[] args = new object[rpcMessage.rawargs.Count + 1]; var rawargs = rpcMessage.rawargs; var paramInfo = helper.method.GetParameters(); args[0] = session; if (args.Length == paramInfo.Length) { for (int i = 0; i < rawargs.Count; i++) { if (rawargs[i].type == enRPCArgType.PBObject) { args[i + 1] = ProtoBuffUtility.Deserialize(paramInfo[i + 1].ParameterType, rawargs[i].rawValue); } else { args[i + 1] = rawargs[i].value; } } currInvokingName = rpcMessage.name; currInvokingSession = session; try { helper.method.Invoke(helper.listener, BindingFlags.NonPublic, null, args, null); } catch (Exception e) { Debuger.LogError("RPC调用出错:{0} : {1}\n{2}", rpcMessage.name, e.Message, e.StackTrace); } currInvokingName = null; currInvokingSession = null; } else { Debuger.LogWarning("参数数量不一致!{0}", rpcMessage.name); } } else { Debuger.LogWarning("RPC不存在!{0}", rpcMessage.name); } }
private void HandleMessage(IPCMessage msg) { RPCMessage rpcmsg = msg.rpcMessage; var helper = rpcManager.GetMethodHelper(rpcmsg.name); if (helper != null) { object[] args = new object[rpcmsg.args.Length +1]; List<RPCArg> rawargs = rpcmsg.rawargs; ParameterInfo[] paramInfo = helper.method.GetParameters(); if (args.Length == paramInfo.Length) { for (int i = 0; i < rawargs.Count; i++) { if (rawargs[i].type == enRPCArgType.PBObject) { args[i + 1] = ProtoBuffUtility.Deserialize(paramInfo[i + 1].ParameterType, rawargs[i].rawValue); } else { args[i + 1] = rawargs[i].value; } } args[0] = msg.srcID; currInvokingName = rpcmsg.name; currInvokingSrc = msg.srcID; try { helper.method.Invoke(helper.listener, BindingFlags.NonPublic, null, args, null); } catch (Exception e) { Debuger.LogError("RPC调用出错:{0}\n{1}", e.Message, e.StackTrace); } currInvokingName = ""; currInvokingSrc = 0; } else { Debuger.LogWarning("参数数量不一致!"); } } else { Debuger.LogWarning("RPC不存在!"); } }
private void HandleRPCMessage(RPCMessage rpcmsg) { Debuger.Log("Connection[{0}]-> {1}({2})", connection.ID, rpcmsg.name, rpcmsg.args); var helper = rpcManager.GetMethodHelper(rpcmsg.name); if (helper != null) { object[] args = rpcmsg.args; var rawargs = rpcmsg.rawargs; var paramInfo = helper.method.GetParameters(); if (rawargs.Count == paramInfo.Length) { for (int i = 0; i < rawargs.Count; i++) { if (rawargs[i].type == enRPCArgType.PBObject) { var type = paramInfo[i].ParameterType; object arg = ProtoBuffUtility.Deserialize(type, rawargs[i].rawValue); args[i] = arg; } } currInvokingName = rpcmsg.name; try { helper.method.Invoke(helper.listener, BindingFlags.NonPublic, null, args, null); } catch (Exception e) { Debuger.LogError("RPC调用出错:{0}: {1}\n{2}", rpcmsg.name, e.Message, e.StackTrace); } currInvokingName = null; } else { Debuger.LogWarning("参数数量不一致!{0}", rpcmsg.name); } } else { Debuger.LogWarning("RPC不存在!{0} ", rpcmsg.name); } }