コード例 #1
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                if (message.Account != "abcdef" || message.Password != "111111")
                {
                    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                    reply(response);
                    return;
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                string  innerAddress = $"{config.GetComponent<InnerConfig>().Host}:{config.GetComponent<InnerConfig>().Port}";
                Session gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = await gateSession.Call <R2G_GetLoginKey, G2R_GetLoginKey>(new R2G_GetLoginKey());

                string outerAddress = $"{config.GetComponent<OuterConfig>().Host}:{config.GetComponent<OuterConfig>().Port}";

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #2
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login r2CLogin;

            if (message.Account != "abcdef" || message.Password != "111111")
            {
                r2CLogin = new R2C_Login {
                    Error = ErrorCode.ERR_AccountOrPasswordError, Message = "账号名或者密码错误!"
                };
                reply(r2CLogin);
                return;
            }

            // 随机分配一个Gate
            Entity config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
            //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
            string  innerAddress = $"{config.GetComponent<InnerConfig>().Host}:{config.GetComponent<InnerConfig>().Port}";
            Session gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

            // 向gate请求一个key,客户端可以拿着这个key连接gate
            G2R_GetLoginKey g2RGetLoginKey = await gateSession.Call <R2G_GetLoginKey, G2R_GetLoginKey>(new R2G_GetLoginKey());

            string outerAddress = $"{config.GetComponent<OuterConfig>().Host}:{config.GetComponent<OuterConfig>().Port}";

            r2CLogin = new R2C_Login {
                Address = outerAddress, Key = g2RGetLoginKey.Key
            };
            reply(r2CLogin);
        }
コード例 #3
0
        protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            var db = DBComponent.Instance;
            IList <AccountModel> accountModels = await db.Query <AccountModel>(f => f.Account == request.Account && f.Password == request.Password);

            AccountModel account = null;

            if (accountModels.Count > 0)
            {
                account = accountModels[0];
            }

            account ??= await this.Register(session, request.Account, request.Password);

            // 随机分配一个Gate
            StartSceneConfig config = RealmGateAddressHelper.GetGate(session.DomainZone());
            //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");

            // 向gate请求一个key,客户端可以拿着这个key连接gate
            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await ActorMessageSenderComponent.Instance.Call(
                config.SceneId, new R2G_GetLoginKey()
            {
                UId = account.UId
            });

            response.Address = config.OuterAddress;
            response.Key     = g2RGetLoginKey.Key;
            response.GateId  = g2RGetLoginKey.GateId;
            reply();
        }
コード例 #4
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            Log.Debug(message.ToJson());
            R2C_Login response = new R2C_Login();

            try
            {
                long   roleId = 0;
                string szName = string.Empty;
                string szIcon = string.Empty;
                if (message.channel == 0)
                {
                    try
                    {
                        roleId = System.Convert.ToInt64(message.Account);
                        szName = message.Account;
                    }
                    catch
                    {
                    }
                    if (message.channel == 0)
                    {
                    }
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress(roleId);
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = await gateSession.Call <G2R_GetLoginKey>(new R2G_GetLoginKey()
                {
                    roleId = roleId, icon = szIcon, mName = szName
                });

                string outerAddress = config.GetComponent <OuterConfig>().IPEndPoint2.ToString();

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #5
0
        protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            // 随机分配一个Gate
            StartSceneConfig config = RealmGateAddressHelper.GetGate(session.DomainZone());

            Log.Debug($"gate address: {MongoHelper.ToJson(config)}");

            // 向gate请求一个key,客户端可以拿着这个key连接gate
            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await ActorMessageSenderComponent.Instance.Call(
                config.InstanceId, new R2G_GetLoginKey()
            {
                Account = request.Account
            });

            response.Address = config.InnerIPOutPort.ToString();
            response.Key     = g2RGetLoginKey.Key;
            response.GateId  = g2RGetLoginKey.GateId;
            reply();
        }