public static void Process(RPCSpecialHolder pkg) { var type = (PackageType)pkg.PkgType; switch (type) { case PackageType.PKGT_C2P_Player_SendAndWait: { System.Object retObject = RPCEntrance.Execute(pkg.mForward.LimitLevel, pkg.mForward.Planes2GateConnect, pkg.mRoot, pkg, pkg.mForward); if (retObject == null || retObject.GetType() == typeof(void)) { break; } var retPkg = new PackageWriter(); retPkg.SerialId = pkg.SerialId; retPkg.WritePODObject(retObject); retPkg.Write(pkg.mForward.Handle); retPkg.DoReturnCommand(pkg.mForward.Planes2GateConnect, CommandTargetType.Planes); } break; case PackageType.PKGT_C2P_Player_Send: { System.Object retObject = RPCEntrance.Execute(pkg.mForward.LimitLevel, pkg.mForward.Planes2GateConnect, pkg.mRoot, pkg, pkg.mForward); } break; } }
protected void ReceiveData(Iocp.NetConnection sender, byte[] pData, int nLength) { var pkg = new PackageProxy(pData, nLength); System.UInt16 serialId = pkg.SerialId; RPCForwardInfo fwd = null; if (mGateServerForward != null) { fwd = mGateServerForward.GetForwardInfo(sender); } Iocp.TcpConnect tcpConnect = sender as Iocp.TcpConnect; int LimitLevel = (int)RPCExecuteLimitLevel.Developer; if (tcpConnect != null) { LimitLevel = tcpConnect.mLimitLevel; } //只有对外的GateServer才需要判断权限,更新最高权限 if (fwd != null) { LimitLevel = fwd.LimitLevel; } if (fwd != null && (PackageType)pkg.PkgType >= PackageType.PKGT_C2P_Send) { switch ((PackageType)pkg.PkgType) { case PackageType.PKGT_C2P_Send: case PackageType.PKGT_C2P_Player_Send: { Iocp.NetConnection conn = fwd.Gate2PlanesConnect; if (conn != null) { var fwdPkg = new PackageWriter(pData, nLength); fwd.Write(fwdPkg); fwdPkg.SendBuffer(conn); } } return; case PackageType.PKGT_C2P_SendAndWait: case PackageType.PKGT_C2P_Player_SendAndWait: { Iocp.NetConnection conn = fwd.Gate2PlanesConnect; if (conn != null) { var fwdPkg = new PackageWriter(pData, nLength); fwd.Write(fwdPkg); fwdPkg.SendBuffer(conn); } } return; case PackageType.PKGT_C2P_Return: { if (mGateServerForward == null) { Log.Log.Common.Print("肯定有人改分包了,不是Gate但是收到PKGT_C2P_Return"); } System.UInt16 handle; //pkg.SeekTo(nLength-sizeof(RPCHeader)-sizeof(System.UInt16)); pkg.SeekTo(nLength - PackageProxy.HeaderSize - sizeof(System.UInt16)); pkg.Read(out handle); pkg.SeekTo(0); Iocp.NetConnection conn = mGateServerForward.GetConnectByHandle(handle); if (conn != null) { var fwdPkg = new PackageWriter(pData, nLength - sizeof(System.UInt16)); fwdPkg.PkgType = PackageType.PKGT_Return; fwdPkg.SendBuffer(conn); } } return; } } if (fwd == null) { fwd = new RPCForwardInfo(); fwd.ReturnSerialId = serialId; fwd.Gate2ClientConnect = sender; fwd.Planes2GateConnect = sender; } else { fwd.ReturnSerialId = serialId; } switch ((PackageType)pkg.PkgType) { case PackageType.PKGT_Send: { //远端直接执行 RPCEntrance.Execute(LimitLevel, sender, mRootObject, pkg, fwd); } break; case PackageType.PKGT_SendAndWait: { //远端执行后,返回执行结束 System.Object retObject = RPCEntrance.Execute(LimitLevel, sender, mRootObject, pkg, fwd); if (retObject == null || retObject.GetType() == typeof(void)) { break; } var retPkg = new PackageWriter(); retPkg.SerialId = serialId; retPkg.WritePODObject(retObject); retPkg.DoReturnCommand(sender, CommandTargetType.DefaultType); } break; case PackageType.PKGT_C2P_Send: { //pkg.SeekTo(nLength-sizeof(RPCHeader)-RPCForwardInfo.GetBlockSize()); pkg.SeekTo(nLength - PackageProxy.HeaderSize - RPCForwardInfo.GetBlockSize()); fwd.Read(pkg); pkg.SeekTo(0); System.Object retObject = RPCEntrance.Execute(fwd.LimitLevel, fwd.Planes2GateConnect, mRootObject, pkg, fwd); } break; case PackageType.PKGT_C2P_Player_Send: { if (mPlanesServerSpecialRoot == null) { Log.Log.Common.Print("有人改分包了,不是Planes但是收到PKGT_C2P_Player_Send消息"); break; } RPCSpecialHolder holder = new RPCSpecialHolder(pData, nLength - RPCForwardInfo.GetBlockSize()); holder.mForward = new RPCForwardInfo(); //pkg.SeekTo(nLength-sizeof(RPCHeader)-RPCForwardInfo.GetBlockSize()); pkg.SeekTo(nLength - PackageProxy.HeaderSize - RPCForwardInfo.GetBlockSize()); holder.mForward.Read(pkg); pkg.SeekTo(0); holder.mForward.ReturnSerialId = serialId; holder.mForward.Planes2GateConnect = sender; mPlanesServerSpecialRoot.Push2Processor(holder, (int)PackageType.PKGT_C2P_Player_Send); } break; case PackageType.PKGT_C2P_SendAndWait: { //pkg.SeekTo(nLength-sizeof(RPCHeader)-RPCForwardInfo.GetBlockSize()); pkg.SeekTo(nLength - PackageProxy.HeaderSize - RPCForwardInfo.GetBlockSize()); fwd.Read(pkg); pkg.SeekTo(0); System.Object retObject = RPCEntrance.Execute(fwd.LimitLevel, fwd.Planes2GateConnect, mRootObject, pkg, fwd); if (retObject == null || retObject.GetType() == typeof(void)) { //Log.Log.Common.Print("有人改分包了,不是Planes但是收到PKGT_C2P_SendAndWait消息"); break; } var retPkg = new PackageWriter(); retPkg.SerialId = serialId; retPkg.WritePODObject(retObject); retPkg.Write(fwd.Handle); retPkg.DoReturnCommand(sender, CommandTargetType.Planes); } break; case PackageType.PKGT_C2P_Player_SendAndWait: { if (mPlanesServerSpecialRoot == null) { Log.Log.Common.Print("有人改分包了,不是Planes但是收到PKGT_C2P_Player_SendAndWait消息"); break; } var holder = new RPCSpecialHolder(pData, nLength - RPCForwardInfo.GetBlockSize()); holder.mForward = new RPCForwardInfo(); holder.mForward.ReturnSerialId = serialId; //pkg.SeekTo(nLength-sizeof(RPCHeader)-RPCForwardInfo.GetBlockSize()); pkg.SeekTo(nLength - PackageProxy.HeaderSize - RPCForwardInfo.GetBlockSize()); holder.mForward.Read(pkg); pkg.SeekTo(0); holder.mForward.Planes2GateConnect = sender; mPlanesServerSpecialRoot.Push2Processor(holder, (int)PackageType.PKGT_C2P_Player_SendAndWait); } break; case PackageType.PKGT_Return: { OnFarCallFinished(serialId, pkg, false); } break; case PackageType.PKGT_C2P_Return: { if (mGateServerForward == null) { Log.Log.Common.Print("有人改分包了,不是Gate但是收到PKGT_C2P_Return消息"); return; } System.UInt16 handle; //pkg.SeekTo(nLength-sizeof(RPCHeader)-sizeof(System.UInt16)); pkg.SeekTo(nLength - PackageProxy.HeaderSize - sizeof(System.UInt16)); pkg.Read(out handle); pkg.SeekTo(0); Iocp.NetConnection conn = mGateServerForward.GetConnectByHandle(handle); if (conn != null) { var fwdPkg = new PackageWriter(pData, nLength - sizeof(System.UInt16)); fwdPkg.PkgType = PackageType.PKGT_Return; fwdPkg.SendBuffer(conn); } } break; case PackageType.PKGT_P2C_Send: { if (mGateServerForward == null) { Log.Log.Common.Print("有人改分包了,不是Gate但是收到PKGT_C2P_Return消息"); return; } System.UInt16 handle; //pkg.SeekTo(nLength-sizeof(RPCHeader)-sizeof(System.UInt16)); pkg.SeekTo(nLength - PackageProxy.HeaderSize - sizeof(System.UInt16)); pkg.Read(out handle); pkg.SeekTo(0); Iocp.TcpConnect conn = mGateServerForward.GetConnectByHandle(handle) as Iocp.TcpConnect; if (conn != null) { if (conn.State != Iocp.NetState.Connect) { if (OnP2CCall_WhenClientDisConnect != null) { OnP2CCall_WhenClientDisConnect(handle, conn); } } else { pkg.PkgType = PackageType.PKGT_Send; //pkg.DangrouseSetPkgLength(nLength - sizeof(System.UInt16)); conn.SendBuffer(pkg.Ptr, 0, (int)(nLength - sizeof(System.UInt16))); } } } return; } }