public void DoReturnGate2Client(RPCForwardInfo fwd) { SerialId = fwd.ReturnSerialId; PkgType = PackageType.PKGT_Return; SendBuffer(fwd.Gate2ClientConnect); }
public void DoReturnPlanes2Client(RPCForwardInfo fwd) { SerialId = fwd.ReturnSerialId; Write(fwd.Handle); DoReturnCommand(fwd.Planes2GateConnect, CommandTargetType.Planes); }
public virtual System.String GetPlayerInfoString(RPCForwardInfo fwd) { return(""); }
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; } }
public static System.Object Execute(int limitLevel, Iocp.NetConnection connect, RPCObject rootObj, PackageProxy pkg, RPCForwardInfo fwd) { if (rootObj == null) { return(null); } try { if (EntranceExecute != null) { return(EntranceExecute(limitLevel, connect, rootObj, pkg, fwd)); } else { RPCObject curExe = rootObj; for (Int16 i = 0; i < pkg.GetMaxStack(); i++) { if (curExe == null) { return(null); } System.Byte stk = pkg.GetStack(i); if (stk == (Byte)ERPCHeader.StackUnused) { break; } else if (stk < (Byte)ERPCHeader.StackIndexBegin) { //curExe = curExe.RPCGetChildObject(limitLevel,stk); curExe = curExe.GetRPCClassInfo().RPCGetChildObject(limitLevel, stk, curExe); //curExe = (RPCObject)curExe.GetRPCClassInfo().mChildObjects[stk].GetValue(curExe,null); } else { //curExe = curExe.RPCGetIndexObject(limitLevel,stk-RPCHeader.StackIndexBegin,pkg); curExe = curExe.GetRPCClassInfo().RPCGetIndexerExecuter(limitLevel, stk - (Byte)ERPCHeader.StackIndexBegin, curExe, pkg); } } if (curExe == null) { return(null); } //return curExe.GetRPCClassInfo().RPCExecuteMethod(limitLevel,connect,pkg.GetMethod(),pkg,fwd); return(curExe.GetRPCClassInfo().RPCGetMethordExecuter(limitLevel, connect, pkg.GetMethod(), curExe, pkg, fwd)); } } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine(e.Message + "==>"); System.Diagnostics.Debug.WriteLine(e.StackTrace.ToString()); Log.Log.Common.Print(e.Message + "==>"); Log.Log.Common.Print(e.StackTrace.ToString()); //如果发生RPC函数内部异常,尽量返回一个-128的值,免得服务器之间的调用因为没有返回WaitHandle没有机会清空 PackageWriter retPkg = new PackageWriter(); retPkg.Write((System.SByte)(-128)); retPkg.DoReturnCommand2(connect, fwd.ReturnSerialId); return(null); } }
public System.Object RPCGetMethordExecuter(int limitLevel, Iocp.NetConnection connect, int Index, RPCObject obj, PackageProxy pkg, RPCForwardInfo fwd) { if (mMethods[Index] == null) { System.Diagnostics.Debug.WriteLine("RPCGetMethordExecuter Indexer Over Ranged:" + Index); return(null); } if (limitLevel < mMethods[Index].LimitLevel) { //此处应该记录有人越权调用函数 RPCPlanesServerSpecialRoot cb = RPCNetworkMgr.Instance.mPlanesServerSpecialRoot; if (cb == null) { Log.Log.Common.Print("发现有超越权限的函数调用({0})", mMethods[Index].mMethodName); System.Diagnostics.Debug.WriteLine("发现有超越权限的函数调用({0})", mMethods[Index].mMethodName); } else { System.String str = cb.GetPlayerInfoString(fwd); Log.Log.Common.Print("发现有超越权限的函数调用({0}:{1})", mMethods[Index].mMethodName, str); System.Diagnostics.Debug.WriteLine("发现有超越权限的函数调用({0}:{1})", mMethods[Index].mMethodName, str); } return(null); } return(mMethods[Index].Execute(connect, obj, pkg, fwd)); }
public virtual System.Object Execute(Iocp.NetConnection connect, RPCObject obj, PackageProxy pkg, RPCForwardInfo fwd) { return(null); }