public RPCWaitHandle WaitDoClient2PlanesPlayer(Iocp.NetConnection conn, float timeOut) { PkgType = PackageType.PKGT_C2P_Player_SendAndWait; if (RPCManager == null) { RPCManager = RPCNetworkMgr.Instance; } RPCWaitHandle handle = RPCManager.NewWaitHandleTimeOut(null, timeOut); SerialId = handle.CallID; SendBuffer(conn); return(handle); }
public void _SyncDoCommand(Iocp.TcpClient cltConn, int timeout) { if (RPCManager == null) { RPCManager = RPCNetworkMgr.Instance; } PkgType = PackageType.PKGT_SendAndWait; RPCWaitHandle handle = RPCManager.NewWaitHandle(null); SendBuffer(cltConn); while (true) { cltConn.Update(); if (null == RPCManager.GetWaitHandle(handle.CallID)) { break; } System.Threading.Thread.Sleep(1); } }
public RPCWaitHandle WaitDoCommandWithTimeOut(float timeOut, Iocp.NetConnection conn, CommandTargetType target, System.Diagnostics.StackTrace st) {//其实这里有很微弱的多线程问题,后面如果设置delegate的时候,网络已经返回的话,不过这个情况应该基本不可能发生 switch (target) { case CommandTargetType.DefaultType: PkgType = PackageType.PKGT_SendAndWait; break; case CommandTargetType.Planes: PkgType = PackageType.PKGT_C2P_SendAndWait; break; } if (RPCManager == null) { RPCManager = RPCNetworkMgr.Instance; } RPCWaitHandle handle = RPCManager.NewWaitHandleTimeOut(st, timeOut); SerialId = handle.CallID; SendBuffer(conn); return(handle); }
public static void BuildRPCMethordExecuter(System.Reflection.Assembly assembly) { System.Type[] ctypes = assembly.GetTypes(); foreach (System.Type t in ctypes) { if (t.FullName == "RPC_ExecuterNamespace.MappingHashCode2Index") { System.Reflection.MethodInfo buildMI = t.GetMethod("BuildMapping"); if (buildMI != null) { buildMI.Invoke(System.Activator.CreateInstance(t), new System.Object[0]); } } { System.Object[] attrs = t.GetCustomAttributes(typeof(RPCMethordExecuterTypeAttribute), true); if (attrs != null && attrs.Length == 1) { RPCMethordExecuterTypeAttribute att = (RPCMethordExecuterTypeAttribute)(attrs[0]); if (att == null) { continue; } RPCNetworkMgr.AddExecuterType(att.KeyCode, att.ExecuterType); } } { System.Object[] attrs = t.GetCustomAttributes(typeof(RPCIndexExecuterTypeAttribute), true); if (attrs != null && attrs.Length == 1) { RPCIndexExecuterTypeAttribute att = (RPCIndexExecuterTypeAttribute)(attrs[0]); if (att == null) { continue; } RPCNetworkMgr.AddIndexExecuterType(att.KeyCode, att.ExecuterType); } } } foreach (System.Type t in ctypes) { System.Object[] attrs = t.GetCustomAttributes(typeof(RPCClassAttribute), false); if (attrs != null && attrs.Length == 1) { RPCClassAttribute att = (RPCClassAttribute)(attrs[0]); if (att == null) { continue; } System.Reflection.MethodInfo mtd_GetRPCClassInfo = t.GetMethod("GetRPCClassInfo"); if (mtd_GetRPCClassInfo == null) { continue; } System.Object obj = System.Activator.CreateInstance(t); RPCClassInfo cInfos = (RPCClassInfo)mtd_GetRPCClassInfo.Invoke(obj, null); if (cInfos == null) { continue; } BuildRPCClassInfo(t, cInfos); } } }
public static void BuildRPCClassInfo(System.Type type, RPCClassInfo cInfos) { cInfos.ObjType = type; System.Reflection.PropertyInfo[] props = type.GetProperties(); foreach (System.Reflection.PropertyInfo p in props) { if (p.Name == "Item") { System.Object[] attrs = p.GetCustomAttributes(typeof(RPCIndexObjectAttribute), true); if (attrs == null || attrs.Length == 0) { continue; } RPCIndexObjectAttribute att = (RPCIndexObjectAttribute)(attrs[0]); if (att == null) { continue; } System.Type exeType = RPCNetworkMgr.FindIndexExecuterType(GetIndexerHashCode(p, type.FullName)); if (exeType == null) { continue; } RPCIndexerExecuter executer = (RPCIndexerExecuter)System.Activator.CreateInstance(exeType); executer.mMethodName = type.FullName + "." + p.ToString(); cInfos.mIndexers[att.ChildIndex] = executer; continue; } else { System.Object[] attrs = p.GetCustomAttributes(typeof(RPCChildObjectAttribute), true); if (attrs != null && attrs.Length == 1) { RPCChildObjectAttribute att = (RPCChildObjectAttribute)(attrs[0]); if (att == null) { continue; } cInfos.mChildObjects[att.ChildIndex] = p; } } } System.Reflection.MethodInfo[] methords = type.GetMethods(); foreach (System.Reflection.MethodInfo m in methords) { System.Object[] attrs = m.GetCustomAttributes(typeof(RPCMethodAttribute), true); if (attrs != null && attrs.Length == 1) { RPCMethodAttribute att = (RPCMethodAttribute)(attrs[0]); if (att == null) { continue; } System.UInt32 hashCode = GetMethodHashCode(m, type.FullName); System.Type exeType = RPCNetworkMgr.FindExecuterType(hashCode); if (exeType == null) { continue; } System.Byte methodIndexer = RPCNetworkMgr.FindExecuterIndexer(hashCode); RPCMethodExecuter executer = (RPCMethodExecuter)System.Activator.CreateInstance(exeType); executer.mMethodFullName = type.FullName + "." + m.ToString(); executer.mMethodName = m.Name; cInfos.mMethods[methodIndexer] = executer; } } RpcAllClassInfo.Add(cInfos); }