public void OnFarCallFinished(System.UInt16 id, PackageProxy ret, bool bTimeOut) { RPCWaitHandle result = null; lock (this) { if (mWaitHandles.TryGetValue(id, out result)) { mWaitHandles.Remove(id); } } if (result != null) { try { result.Raise_OnFarCallFinished(ret, bTimeOut); } catch (System.Exception ex) { Log.Log.Common.Print(ex.ToString()); Log.Log.Common.Print(ex.StackTrace.ToString()); } } }
public void Read(PackageProxy pkg) { pkg.Read(out LimitLevel); pkg.Read(out Handle); pkg.Read(out PlayerIndexInMap); pkg.Read(out MapIndexInServer); pkg.Read(out RoleId); }
public virtual void PackageRead(PackageProxy pkg) { if (pkg.IsSinglePkg) { PackageReadSingle(pkg); } else { PackageReadFull(pkg); } }
public void Raise_OnFarCallFinished(PackageProxy ret, bool bTimeout) { if (OnFarCallFinished != null) { OnFarCallFinished(ret, bTimeout); } else { //System::Diagnostics::Debugger::Break(); Log.Log.Common.Print("OnFarCallFinished==null"); } }
public virtual void PackageReadFull(PackageProxy pkg) { var desc = IAutoSLClassDescManager.Instance.GetClassDesc(this.GetType()); foreach (IAutoSLField f in desc.Fields) { var i = f.Property; if (ReadPkg(pkg, i)) { } else if (i.PropertyType.IsSubclassOf(typeof(IAutoSaveAndLoad))) { var value = (RPC.IAutoSaveAndLoad)System.Activator.CreateInstance(i.PropertyType); pkg.Read(value); i.SetValue(this, value, null); } } }
protected bool ReadPkg(PackageProxy pkg, System.Reflection.PropertyInfo i) { var propType = i.PropertyType; if (propType == typeof(System.SByte)) { System.SByte value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.Int16)) { System.Int16 value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.Int32)) { System.Int32 value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.Int64)) { System.Int64 value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.Byte)) { System.Byte value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.UInt16)) { System.UInt16 value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.UInt32)) { System.UInt32 value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.UInt64)) { System.UInt64 value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.Single)) { System.Single value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.Double)) { System.Double value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.Guid)) { System.Guid value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(SlimDX.Vector3)) { SlimDX.Vector3 value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(SlimDX.Matrix)) { SlimDX.Matrix value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.DateTime)) { System.DateTime value; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.String)) { System.String value = ""; pkg.Read(out value); i.SetValue(this, value, null); } else if (propType == typeof(System.Byte[])) { System.Byte[] value = new System.Byte[0]; pkg.Read(out value); i.SetValue(this, value, null); } else { return(false); } return(true); }
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 virtual RPCObject Execute(RPCObject obj, PackageProxy pkg) { return(null); }
public RPCObject RPCGetIndexerExecuter(int limitLevel, int Index, RPCObject obj, PackageProxy pkg) { if (mIndexers[Index] == null) { System.Diagnostics.Debug.WriteLine("RPCGetIndexerExecuter Indexer Over Ranged:", Index); return(null); } if (limitLevel < mIndexers[Index].LimitLevel) { //此处应该记录有人越权调用函数 Log.Log.Common.Print("发现有超越权限的索引器调用"); return(null); } return(mIndexers[Index].Execute(obj, pkg)); }
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); }