public void DoHashCall(ref T arg, NetCore.ERouteTarget route = NetCore.ERouteTarget.Self, NetCore.NetConnection conn = null, NetCore.RPCRouter router = null, byte userFlags = 0) { if (conn == null) { conn = RPCProcessor.DefaultConnection; } var pkg = new NetCore.PkgWriter(arg.GetPkgSize()); pkg.SetUserFlags(userFlags); try { WritePkgHeader_Hash <T>(ref pkg, ref arg, 0, null, route, conn, router); OnWriteArugment(ref arg, ref pkg); if (conn != null) { pkg.SendBuffer(conn); } } finally { pkg.Dispose(); } }
public async System.Threading.Tasks.Task <R> DoAwaitCall(T arg, long timeOut, NetCore.ERouteTarget route = NetCore.ERouteTarget.Self, NetCore.NetConnection conn = null, NetCore.RPCRouter router = null, byte userFlags = 0) { if (conn == null) { conn = RPCProcessor.DefaultConnection; } var pkg = new NetCore.PkgWriter(arg.GetPkgSize()); pkg.SetUserFlags(userFlags); RPCExecuter.RPCWait waiter = null; try { waiter = WritePkgHeader <T>(ref pkg, ref arg, timeOut, RPCAwaiter.NullCB, route, conn, router); OnWriteArugment(ref arg, ref pkg); if (conn != null) { pkg.SendBuffer(conn); } } finally { pkg.Dispose(); } waiter.Processor = this; var result = await RPCAwaiter.RPCWaitReturn <R>(waiter); return(result); }
public void DoReturn(ref R arg, UInt16 serialId, NetCore.NetConnection connect) { var pkg = new NetCore.PkgWriter(arg.GetPkgSize()); try { byte route = (byte)NetCore.ERouteTarget.Self | (byte)NetCore.ERouteTarget.ReturnFlag; pkg.Write((byte)route); pkg.Write(serialId); OnWriteReturn(ref pkg, ref arg); pkg.SendBuffer(connect); } finally { pkg.Dispose(); } }
public void ReceiveData(NetCore.NetConnection sender, byte[] pData, int nLength, Int64 recvTime) { unsafe { if (nLength < sizeof(NetCore.PkgHeader)) { return; } } var router = sender.Router as NetCore.RPCRouter; if (router == null) { System.Diagnostics.Debug.WriteLine($"connect bind a invalid data"); return; } var pkg = new NetCore.PkgReader(pData, nLength, recvTime); try { if (PkgRcver != null) { PkgRcver.OnReceivePackage(sender, pkg); } byte route = 0; pkg.Read(out route); var isReturn = (route & (byte)NetCore.ERouteTarget.ReturnFlag) != 0 ? true : false; route = (byte)(route & (byte)NetCore.ERouteTarget.ReturnMask); var target = (NetCore.ERouteTarget)route; switch (target) { case NetCore.ERouteTarget.Self: { if (isReturn) { UInt16 serialId = 0; pkg.Read(out serialId); DoCallBack(serialId, ref pkg); } else { Execute(ref pkg, sender, ref router.RouteInfo); } } break; case NetCore.ERouteTarget.Routed: { var routeInfo = new NetCore.RPCRouter.RouteData(); routeInfo.Load(ref pkg); Execute(ref pkg, sender, ref routeInfo); } break; case NetCore.ERouteTarget.Client: { //只有GateServer才有转发到客户端的需求 #if Server var routePkg = new PkgWriter(); var routeInfo = new RPCRouter.RouteData(); try { routeInfo.Load(pkg); if (Titan3D.Server.IGateServer.Instance != null) { if (isReturn) { route = (byte)((byte)ERouteTarget.Self | (byte)ERouteTarget.ReturnFlag); routePkg.Write(route); UInt16 seriaId; pkg.Read(out seriaId); routePkg.Write(seriaId); } else { route = (byte)ERouteTarget.Self; routePkg.Write(route); } routePkg.AppendPkg(pkg, pkg.GetPosition()); routePkg.SendBuffer(Titan3D.Server.IGateServer.Instance.GetClientConnect(routeInfo.RouteSlot)); } } finally { routePkg.Dispose(); } #endif } break; case NetCore.ERouteTarget.Hall: { var routePkg = new NetCore.PkgWriter(nLength + 64); try { routePkg.Write((byte)NetCore.ERouteTarget.Routed); router.RouteInfo.Save(ref routePkg, NetCore.ERouteTarget.Hall); routePkg.SetFlags(pkg.GetFlags()); routePkg.AppendPkg(pkg, pkg.GetPosition()); routePkg.SendBuffer(RouterTargetConnect(target, router)); } finally { routePkg.Dispose(); } } break; case NetCore.ERouteTarget.Data: case NetCore.ERouteTarget.Keep: case NetCore.ERouteTarget.Reg: case NetCore.ERouteTarget.Path: case NetCore.ERouteTarget.Log: { var routePkg = new NetCore.PkgWriter(nLength + 64); try { routePkg.Write((byte)NetCore.ERouteTarget.Routed); router.RouteInfo.Save(ref routePkg, target); routePkg.SetFlags(pkg.GetFlags()); routePkg.AppendPkg(pkg, pkg.GetPosition()); routePkg.SendBuffer(GetServerConnect(target)); } finally { routePkg.Dispose(); } } break; } } finally { pkg.Dispose(); } }