private void OnRpc(RpcMsg msg) { var methodname = msg.methodeName; //for (var k = 0; k < args.Length; k++) //{ // name += "_" + args[k].GetType().Name; //} //fire(msg.methodeName, args); Dictionary <object, MethodInfo> rpcinfo = new Dictionary <object, MethodInfo>(); if (rpcHandlerDict.TryGetValue(methodname, out rpcinfo)) { object[] args = null; var iter = rpcinfo.GetEnumerator(); bool flag = true; while (iter.MoveNext()) { var info = iter.Current; if (flag) { flag = false; try { if (!MsgHelper.UnpackMethod(info.Value, msg.data, out args)) { throw new Exception("Parameter cannot be unpacked for rpc method " + methodname); } } catch (Exception e) { throw new Exception("OnRpc UnpackMethod Execption for method name " + methodname + " exception:" + e); } } info.Value.Invoke(info.Key, args); } return; } if (!entityDict.ContainsKey(msg.EntityID)) { throw new Exception("entity id->" + msg.EntityID + " not exists!"); } entityDict[msg.EntityID].OnRpc(methodname, msg.data); }
internal void OnRpc(string methodname, byte[] data) { Dictionary <object, MethodInfo> rpcinfo = new Dictionary <object, MethodInfo>(); if (rpcHandlerDict.TryGetValue(methodname, out rpcinfo)) { object[] args = null; var iter = rpcinfo.GetEnumerator(); bool flag = true; while (iter.MoveNext()) { var info = iter.Current; if (flag) { flag = false; try { if (!MsgHelper.UnpackMethod(info.Value, data, out args)) { throw new Exception("Parameter cannot be unpacked for rpc method " + methodname + " in entity id->" + id); } } catch (Exception e) { throw new Exception("OnRpc UnpackMethod Execption for method name " + methodname + " in entity id->" + id + ". exception:" + e); } } info.Value.Invoke(info.Key, args); } } else { throw new Exception("rpc method name->" + methodname + " not exists in entity id->" + id); } }