private Net.NetConnection RouterTargetConnect(ERouteTarget target, RPCRouter router)
        {
            switch (target)
            {
            case ERouteTarget.Reg:
            case ERouteTarget.Log:
            case ERouteTarget.Path:
            case ERouteTarget.Data:
            case ERouteTarget.Keep:
                return(PkgRcver.GetServerConnect(target));

            case ERouteTarget.Hall:
                return(router.ToHConnect);

            case ERouteTarget.Gate:
                return(router.ToGConnect);

            default:
                break;
            }
            return(null);
        }
        public void ReceiveData(Net.NetConnection sender, byte[] pData, int nLength, Int64 recvTime)
        {
            unsafe
            {
                if (nLength < sizeof(RPCHeader))
                {
                    return;
                }
            }

            var router = sender.Router as RPCRouter;

            if (router == null)
            {
                System.Diagnostics.Debug.WriteLine($"connect bind a invalid data");
                return;
            }
            var pkg = new PkgReader(pData, nLength, recvTime);

            if (PkgRcver != null)
            {
                PkgRcver.OnReceivePackage(sender, pkg);
            }

            byte route = 0;

            pkg.Read(out route);
            var isReturn = (route & (byte)ERouteTarget.ReturnFlag) != 0 ? true : false;

            route = (byte)(route & (byte)ERouteTarget.ReturnMask);
            ERouteTarget target = (ERouteTarget)route;

            switch (target)
            {
            case ERouteTarget.Self:
            {
                if (isReturn)
                {
                    UInt16 serialId = 0;
                    pkg.Read(out serialId);
                    DoCallBack(serialId, pkg);
                }
                else
                {
                    Execute(pkg, sender, ref router.RouteInfo);
                }
            }
            break;

            case ERouteTarget.Routed:
            {
                var routeInfo = new RPCRouter.RouteData();
                routeInfo.Load(pkg);
                Execute(pkg, sender, ref routeInfo);
            }
            break;

            case ERouteTarget.Client:
            {        //只有GateServer才有转发到客户端的需求
#if Server
                var routePkg  = new PkgWriter();
                var routeInfo = new RPCRouter.RouteData();
                routeInfo.Load(pkg);
                if (Vise3D.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(Vise3D.Server.IGateServer.Instance.GetClientConnect(routeInfo.RouteSlot));
                }
#endif
            }
            break;

            case ERouteTarget.Hall:
            {
                var routePkg = new PkgWriter(nLength + 64);
                routePkg.Write((byte)ERouteTarget.Routed);
                router.RouteInfo.Save(routePkg, ERouteTarget.Hall);
                routePkg.SetFlags(pkg.GetFlags());
                routePkg.AppendPkg(pkg, pkg.GetPosition());
                routePkg.SendBuffer(RouterTargetConnect(target, router));
                routePkg.Dispose();
            }
            break;

            case ERouteTarget.Data:
            case ERouteTarget.Keep:
            case ERouteTarget.Reg:
            case ERouteTarget.Path:
            case ERouteTarget.Log:
            {
                var routePkg = new PkgWriter(nLength + 64);
                routePkg.Write((byte)ERouteTarget.Routed);
                router.RouteInfo.Save(routePkg, target);
                routePkg.SetFlags(pkg.GetFlags());
                routePkg.AppendPkg(pkg, pkg.GetPosition());
                routePkg.SendBuffer(GetServerConnect(target));
                routePkg.Dispose();
            }
            break;
            }

            pkg.Dispose();
        }
 public Net.NetConnection GetServerConnect(ERouteTarget target)
 {
     return(PkgRcver.GetServerConnect(target));
 }