Ejemplo n.º 1
0
        public RPCExecManager.RPCWait S2C_Call(RPCRouter router, ERouteTarget sender = ERouteTarget.Unknown)
        {
            if (sender == ERouteTarget.Unknown)
            {
                sender = RPCExecManager.Insance.AppTarget;
            }

            switch (sender)
            {
            case ERouteTarget.Gate:
                return(WaitDoCallImpl(0, null, ERouteTarget.Self, router.C2GConnect));

            case ERouteTarget.Hall:
                return(WaitDoCallImpl(0, null, ERouteTarget.Client, router.ToGConnect, router));

            case ERouteTarget.Keep:
                return(WaitDoCallImpl(0, null, ERouteTarget.Client, router.ToGConnect, router));

            case ERouteTarget.Data:
                return(WaitDoCallImpl(0, null, ERouteTarget.Client, router.ToGConnect, router));

            case ERouteTarget.Reg:
                return(WaitDoCallImpl(0, null, ERouteTarget.Client, router.ToGConnect, router));

            default:
                return(null);
            }
        }
Ejemplo n.º 2
0
            public void Save(ref PkgWriter pkg, ERouteTarget target)
            {
                pkg.Write((byte)target);
                pkg.Write(RouteSlot);
                pkg.Write(Authority);
                switch (target)
                {
                case ERouteTarget.Data:
                    pkg.Write(AccountId);
                    break;

                case ERouteTarget.Hall:
                    pkg.Write(MapInHall);
                    pkg.Write(PlayerInMap);
                    break;
                }
            }
Ejemplo n.º 3
0
        public async Task <T> S2S_AwaitCall <T>(long timeOut, ERouteTarget target = ERouteTarget.Data) where T : RPCReturnValue, new()
        {
            AssertReturnType(this.GetType(), typeof(T));

            RPCExecManager.RPCWait writer = null;
            if (timeOut == 0)
            {
                writer = WaitDoCallImpl(timeOut, null, ERouteTarget.Self, RPCExecManager.Insance.GetServerConnect(target));
            }
            else
            {
                writer = WaitDoCallImpl(timeOut, RPCAwaiter.NullCB, ERouteTarget.Self, RPCExecManager.Insance.GetServerConnect(target));
            }

            var result = await RPCAwaiter.RPCWaitReturn <T>(writer);

            return(result);
        }
Ejemplo n.º 4
0
        public RPCExecManager.RPCWait S2S_Call <T>(long timeOut, ERouteTarget target = ERouteTarget.Data, FRPCTypeReturnCallBack <T> cb = null) where T : RPCReturnValue, new()
        {
            AssertReturnType(this.GetType(), typeof(T));
            if (cb == null)
            {
                return(WaitDoCallImpl(timeOut, null, ERouteTarget.Self, RPCExecManager.Insance.GetServerConnect(target)));
            }

            RPCExecManager.FRPCReturnCallBack fn = (PkgReader data, bool isTimeOut) =>
            {
                if (isTimeOut)
                {
                    cb(null, true);
                    return;
                }
                T retValue = new T();
                retValue.ReadObject(data);
                cb(retValue, false);
            };
            return(WaitDoCallImpl(timeOut, fn, ERouteTarget.Self, RPCExecManager.Insance.GetServerConnect(target)));
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public async Task <T> C2S_AwaitCall <T>(long timeOut, ERouteTarget route = ERouteTarget.Hall) where T : RPCReturnValue, new()
        {
            AssertReturnType(this.GetType(), typeof(T));
            if (route == ERouteTarget.Gate)
            {
                route = ERouteTarget.Self;
            }

            RPCExecManager.RPCWait waiter = null;
            if (timeOut == 0)
            {
                waiter = WaitDoCallImpl(0, null, route, RPCExecManager.Insance.C2SConnect);
            }
            else
            {
                waiter = WaitDoCallImpl(timeOut, RPCAwaiter.NullCB, route, RPCExecManager.Insance.C2SConnect);
            }

            var result = await RPCAwaiter.RPCWaitReturn <T>(waiter);

            return(result);
        }
Ejemplo n.º 7
0
 public RPCExecManager.RPCWait WaitHashCall <T>(long timeOut, FRPCTypeReturnCallBack <T> cb,
                                                ERouteTarget route     = ERouteTarget.Self,
                                                Net.NetConnection conn = null,
                                                RPCRouter router       = null) where T : RPCReturnValue, new()
 {
     AssertReturnType(this.GetType(), typeof(T));
     if (cb == null)
     {
         return(WaitDoCallImpl_Hash(timeOut, null, route, conn, router));
     }
     RPCExecManager.FRPCReturnCallBack fn = (PkgReader data, bool isTimeOut) =>
     {
         if (isTimeOut)
         {
             cb(null, true);
             return;
         }
         T retValue = new T();
         retValue.ReadObject(data);
         cb(retValue, false);
     };
     return(WaitDoCallImpl_Hash(timeOut, fn, route, conn, router));
 }
Ejemplo n.º 8
0
        public async Task <T> AwaitHashCall <T>(long timeOut, ERouteTarget route = ERouteTarget.Self,
                                                Net.NetConnection conn           = null,
                                                RPCRouter router = null) where T : RPCReturnValue, new()
        {
            AssertReturnType(this.GetType(), typeof(T));
            RPCExecManager.RPCWait pkg = null;
            if (timeOut == 0)
            {
                pkg = WaitDoCallImpl_Hash(timeOut, null, route, conn, router);
            }
            else
            {
                pkg = WaitDoCallImpl_Hash(timeOut, RPCAwaiter.NullCB, route, conn, router);
            }

            var result = await RPCAwaiter.RPCWaitReturn <T>(pkg);

            if (result == null)
            {
                System.Diagnostics.Debug.WriteLine($"RPC Time Out: {this.GetType().FullName}");
                return(null);
            }
            return(result);
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
 public Net.NetConnection GetServerConnect(ERouteTarget target)
 {
     return(PkgRcver.GetServerConnect(target));
 }
Ejemplo n.º 11
0
        private RPCExecManager.RPCWait WaitDoCallImpl_Hash(long timeOut, RPCExecManager.FRPCReturnCallBack cb, ERouteTarget route = ERouteTarget.Self, Net.NetConnection conn = null, RPCRouter router = null)
        {
            var hash = this.GetMethodBinder().MethordHash;
            var pkg  = new PkgWriter(this.GetPkgSize());

            pkg.SetHashIndex(true);
            pkg.Write((byte)route);
            if (router != null)
            {
                router.RouteInfo.Save(pkg, route);
            }
            RPCExecManager.RPCWait waiter = null;
            if (cb != null)
            {
                pkg.SetHasReturn(true);
                waiter        = RPCExecManager.Insance.AddCalBack(cb);
                this.SerialId = waiter.SerialId;
                pkg.Waiter    = waiter;
                if (timeOut < 0)
                {
                    timeOut = long.MaxValue;
                }
                waiter.Timout = timeOut;
                pkg.Write(hash);
                pkg.Write(this.SerialId);
            }
            else
            {
                pkg.SetHasReturn(false);
                pkg.Write(hash);
            }
            WriteObject(pkg);

            if (conn != null)
            {
                pkg.SendBuffer(conn);
            }

            pkg.Dispose();

            return(waiter);
        }
Ejemplo n.º 12
0
        private RPCExecManager.RPCWait WaitDoCallImpl(long timeOut, RPCExecManager.FRPCReturnCallBack cb, ERouteTarget route = ERouteTarget.Self, Net.NetConnection conn = null, RPCRouter router = null)
        {
            var Index = this.GetMethodBinder().Index;
            var pkg   = new PkgWriter(this.GetPkgSize());

            if (Index >= RPCExecManager.MaxRPC)
            {
                System.Diagnostics.Debug.WriteLine($"RPC Index is invalid:{this.GetType().FullName}");
                return(null);
            }
            pkg.Write((byte)route);
            if (router != null)
            {
                router.RouteInfo.Save(pkg, route);
            }

            RPCExecManager.RPCWait waiter = null;
            if (cb != null)
            {
                waiter        = RPCExecManager.Insance.AddCalBack(cb);
                this.SerialId = waiter.SerialId;
                pkg.Waiter    = waiter;
                if (timeOut < 0)
                {
                    timeOut = long.MaxValue;
                }
                waiter.Timout = timeOut;
                Index        |= RPCExecManager.WaitFlag;
                pkg.SetHasReturn(true);
                pkg.Write(Index);
                pkg.Write(this.SerialId);
            }
            else
            {
                pkg.SetHasReturn(false);
                pkg.Write(Index);
            }
            WriteObject(pkg);

            if (conn != null)
            {
                pkg.SendBuffer(conn);
            }

            return(waiter);
        }
Ejemplo n.º 13
0
 public async System.Threading.Tasks.Task <R> AwaitHashCallReturn(long timeOut, ERouteTarget route = ERouteTarget.Self,
                                                                  Net.NetConnection conn           = null,
                                                                  RPCRouter router = null)
 {
     return(await AwaitHashCall <R>(timeOut, route, conn, router));
 }
Ejemplo n.º 14
0
 public async System.Threading.Tasks.Task <R> S2S_AwaitCallReturn(long timeOut, ERouteTarget target = ERouteTarget.Data)
 {
     return(await S2S_AwaitCall <R>(timeOut, target));
 }
Ejemplo n.º 15
0
 public async System.Threading.Tasks.Task <R> C2S_AwaitCallReturn(long timeOut, ERouteTarget route = ERouteTarget.Hall)
 {
     return(await C2S_AwaitCall <R>(timeOut, route));
 }