示例#1
0
        protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            //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)}");
            IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
            Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

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

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

            response.Address = outerAddress;
            response.Key     = g2RGetLoginKey.Key;
            reply();
        }
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                //if (message.Account != "hzy" || message.Password != "123")
                //{
                //    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                //    reply(response);
                //    return;
                //}
                DBProxyComponent dBProxy     = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         newUserInfo = ComponentFactory.Create <UserInfo>();
                newUserInfo.Account  = message.Account;
                newUserInfo.PassWord = message.Password;
                await dBProxy.Save(newUserInfo);

                try
                {
                    List <ComponentWithId> users = await dBProxy.Query <UserInfo>(t => t.Account == message.Account);

                    if (users.Count > 0)
                    {
                        UserInfo user = await dBProxy.Query <UserInfo>(users[0].Id);

                        Log.Error("user的内容:" + JsonHelper.ToJson(user));
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("查库错误");
                    throw;
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

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

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#3
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                Log.Info($"登录请求:{{Account:'{message.Account}',Password:'******'}}");

                List <ComponentWithId> result = await dbProxy.Query <AccountInfo>(_account => _account.Account == message.Account);

                if (result.Count == 0)
                {
                    response.Error   = ErrorCode.ERR_AccountDoesnExist;
                    response.Message = "账号不存在";
                    reply(response);
                    return;
                }
                AccountInfo accountInfo = result[0] as AccountInfo;
                if (accountInfo.Password != message.Password)
                {
                    response.Error   = ErrorCode.ERR_LoginError;
                    response.Message = "密码错误";
                    reply(response);
                    return;
                }

                AccountInfo account = result[0] as AccountInfo;

                Log.Info($"账号登录成功{MongoHelper.ToJson(account)}");

                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();

                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;

                Session gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    UserId = account.Id
                });

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

                response.Address = outerAddress;

                response.Key = g2RGetLoginKey.Key;

                response.UserId = account.Id;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        private async static ETTask RealmToGate(Session session, User user, R2C_Authentication response, bool isRefreshToken)
        {
            // 隨機分配GateServer
            StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();

            // Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
            IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
            Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);
            //Game.Scene.GetComponent<PingComponent>().RemoveSession(session.Id);

            // 向Gate請求一個Key,Client可以拿這個Key連接Gate
            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
            {
                Uid = user.Id
            });

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

            // 創造權杖
            if (isRefreshToken)
            {
                SignInCryptographyHelper.Token tok = new SignInCryptographyHelper.Token
                {
                    uid = user.Id,
                    lastCreateTokenAt = user.lastCreateTokenAt,
                    salt = user.salt,
                };

                string token = SignInCryptographyHelper.EncodeToken(tok);
                response.Token = token;
            }

            PlayerRideTotalInfo playerRideTotalInfo = await UserDataHelper.QueryUserRideAllRecord(user);

            response.Error   = ErrorCode.ERR_Success;
            response.Address = outerAddress;
            response.Key     = g2RGetLoginKey.Key;
            response.Data    = new PlayerBaseInfo
            {
                Uid      = user.Id,
                Name     = user.name,
                Sex      = user.gender,
                Location = user.location,
                Height   = user.height,
                Weight   = user.weight,
                Birthday = user.birthday,
                CreateAt = user.createAt,
                // 校時用
                LastOnlineAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
                CharSetting  = user.playerCharSetting,
                TotalInfo    = playerRideTotalInfo,
                Language     = user.language,
            };
            response.LinkTypes.Clear();
            response.LinkTypes.AddRange(await GetAllLinkType(user.Id));
        }
示例#5
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                User user = Game.Scene.GetComponent <UserComponent>().GetByAccount(message.Account);
                if (user != null)
                {
                    if (message.Password == user.Password)
                    {
                        Console.WriteLine(" 用户名: " + user.Account + " 验证通过!");

                        // 随机分配一个Gate
                        StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                        //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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                        {
                            Account = message.Account
                        });

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

                        response.Key     = g2RGetLoginKey.Key;
                        response.Address = outerAddress;
                        reply(response);
                    }
                    else
                    {
                        Console.WriteLine(" 用户名: " + message.Account + " 密码验证错误!");

                        response.Error   = ErrorCode.ERR_AccountOrPasswordError;
                        response.Message = " 用户名: " + message.Account + " 密码验证错误!";
                        reply(response);
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("用户名:" + message.Account + "不存在!");

                    response.Error   = ErrorCode.ERR_AccountOrPasswordError;
                    response.Message = " 用户名: " + message.Account + " 不存在!";
                    reply(response);
                    return;
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#6
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                //数据库操作对象
                {
                    DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();
                    Console.WriteLine("dbProxy : " + dbProxy);

                    //查询账号是否存在  使用LINQ和Lambda表达式根据特定条件来查询
                    List <ComponentWithId> result = await dbProxy.Query <AccountInfo>(_account => _account.Account == message.Account && _account.Password == message.Password);

                    Console.WriteLine("result : " + result);

                    if (result.Count <= 0)
                    {
                        Console.WriteLine("result.Count : " + result.Count);

                        response.Error = ErrorCode.ERR_AccountOrPasswordError;
                        reply(response);
                        return;
                    }
                    Console.WriteLine("数据库查询成功");

                    //释放数据库连接
                    dbProxy.Dispose();
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

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

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#7
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.SceneId, new R2G_GetLoginKey() {Account = request.Account});

			response.Address = config.OuterAddress;
			response.Key = g2RGetLoginKey.Key;
			response.GateId = g2RGetLoginKey.GateId;
			reply();
		}
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                DBProxyComponent       dbproy   = Game.Scene.GetComponent <DBProxyComponent>();
                List <ComponentWithId> accounts = await dbproy.Query <Account>($"{{\'username\':\'{message.Account}\'}}");

                if (accounts.Count == 0)
                {
                    Account account = new Account();
                    Log.Debug("账号不存在,正在保存账号");
                    await dbproy.Save(account);
                }
                else
                {
                    Account account = (Account)accounts[0];
                    Log.Debug("查找到了" + accounts);
                    if (message.Password != account.password)
                    {
                        Log.Debug("密码正确");
                        return;
                    }
                }


                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                G2R_GetLoginKey g2R_GetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

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

                response.Address = outerAddress;
                response.Key     = g2R_GetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#9
0
        protected override async void Run(Session session, C2R_CommonLogin message, Action <R2C_CommonLogin> reply)
        {
            R2C_CommonLogin response = new R2C_CommonLogin();

            try
            {
                //向用户服验证(注册/登陆)并获得一个用户ID
                Session        userSession   = Game.Scene.GetComponent <NetInnerSessionComponent>().Get(AppType.User);
                U2R_VerifyUser u2RVerifyUser = (U2R_VerifyUser)await userSession.Call(new R2U_VerifyUser()
                {
                    LoginType    = message.LoginType,
                    PlatformType = message.PlatformType,
                    DataStr      = message.DataStr,
                    // IpAddress=session.RemoteAddress.Address.ToString(),
                });

                //如果Message不为空 说明 验证失败
                if (!string.IsNullOrEmpty(u2RVerifyUser.Message))
                {
                    response.Message = u2RVerifyUser.Message;
                    reply(response);
                    return;
                }
                // 随机分配一个Gate
                StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);
                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    UserId = u2RVerifyUser.UserId
                });

                string outerAddress = config.GetComponent <OuterConfig>().Address2;
                response.Address      = outerAddress;
                response.Key          = g2RGetLoginKey.Key;
                response.LoginVoucher = u2RVerifyUser.UserId.ToString() + '|' + u2RVerifyUser.Password;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#10
0
        protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            //数据库操作对象
            DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

            //验证账号密码是否正确
            List <ComponentWithId> result =
                await dbProxy.Query <AccountInfo>(_account => _account.Account == request.Account && _account.Password == request.Password);

            if (result.Count == 0)
            {
                //给测试场景开个后门
                if (request.Account == "Test123" && request.Password == "Test123")
                {
                    C2R_RegisterHandler.CreateUser(request.Account, request.Password).Coroutine();
                    result = await dbProxy.Query <AccountInfo>(
                        _account => _account.Account == request.Account && _account.Password == request.Password);
                }
                else
                {
                    response.Error = ErrorCode.ERR_LoginError;
                    reply();
                    return;
                }
            }

            // 随机分配一个Gate(内部)
            StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
            IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
            Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

            // 向gate请求一个key,客户端可以拿着这个key连接gate,20秒失效
            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
            {
                playerID = result[0].Id
            });

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

            response.Address  = outerAddress;
            response.Key      = g2RGetLoginKey.Key;
            response.PlayerId = result[0].Id;
            reply();
        }
示例#11
0
        public override async ETTask C2R_LoginHandler(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            Console.WriteLine("C2R_LoginHandler");
            // 随机分配一个Gate
            StartConfig config = RealmGateAddressHelper.GetGate();
            //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");

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

            string outerAddress = config.GetParent <StartConfig>().GetComponent <OuterConfig>().Address2;

            response.Address = outerAddress;
            response.Key     = g2RGetLoginKey.Key;
            response.GateId  = g2RGetLoginKey.GateId;
            reply();
        }
示例#12
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                string query = $"{"{"}'Account':'{message.Account}','Password':'******'{"}"}";
                Log.Info($"----{query}");
                List <AccountInfo> accounts = await Game.Scene.GetComponent <DBProxyComponent>().QueryJson <AccountInfo>(query);

                if (accounts.Count == 0)
                {
                    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                    reply(response);
                    return;
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

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

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

            try
            {
                Console.WriteLine("userLogin:"******"key:" + message.Password);

                /*
                 * 账户密码验证
                 */
                int result = Game.Scene.GetComponent <MySqlComponent>().CheckPassWord(message.Account, message.Password);
                if (result == ErrorCode.ERR_Success)
                {
                    // 随机分配一个Gate
                    StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                    //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                    IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                    Console.WriteLine("userLogin:" + innerAddress);
                    Session gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

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

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

                    response.Address = outerAddress;
                    response.Key     = g2RGetLoginKey.Key;
                }
                response.Error = result;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#14
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                Account ret = await CheckAccount(message, response);

                if (ret == null)
                {
                    reply(response);

                    return;
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    PhoneNum = ret.PhoneNum
                });

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

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#15
0
        private async ETVoid RunAsync(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)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);
                Log.Warning("请求Key+ " + session.Id);
                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

                Log.Warning("返回Key+ " + session.Id);
                string outerAddress = config.GetComponent <OuterConfig>().Address2;

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#16
0
        public override async ETTask R2G_GetLoginKeyHandler(Scene scene, R2G_GetLoginKey request, G2R_GetLoginKey response, Action reply)
        {
            long key = RandomHelper.RandInt64();

            scene.GetComponent <GateSessionKeyComponent>().Add(key, request.Account);
            response.Key    = key;
            response.GateId = scene.Id;
            reply();
            await ETTask.CompletedTask;
        }
示例#17
0
        private async ETVoid RunAsync(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;
                //}



                //TODO 数据库相关功能   mangodb数据库根据json查询条件查询
                DBProxyComponent       dbProxy  = Game.Scene.GetComponent <DBProxyComponent>();
                List <ComponentWithId> accounts = await dbProxy.Query <Account>($"{{\'username\':\'{message.Account}\'}}");

                //如果没有查找到玩家
                if (accounts.Count == 0)
                {
                    Account account = new Account();
                    Log.Debug("账号不存在,正在保存账号");
                    //保存账号
                    await dbProxy.Save(account);
                }
                else
                {
                    Account account = (Account)accounts[0];
                    Log.Debug("查找到了" + accounts);
                    if (message.Password != account.password)
                    {
                        Log.Debug("密码正确");
                        return;
                    }
                }



                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

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

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#18
0
        private async ETVoid RunAsync(Session session, C2R_RegisterAndLogin message, Action <R2C_RegisterAndLogin> reply)
        {
            Console.WriteLine(" --> C2R_RegisterAndLoginHandler");

            R2C_RegisterAndLogin response = new R2C_RegisterAndLogin();

            try
            {
                Console.WriteLine("account : " + message.Account + " password : "******"dbProxy : " + dbProxy);

                    //查询账号是否存在  使用LINQ和Lambda表达式根据特定条件来查询
                    List <ComponentWithId> result = await dbProxy.Query <AccountInfo>(_account => _account.Account == message.Account);

                    Console.WriteLine("result : " + result);

                    if (result.Count > 0)
                    {
                        Console.WriteLine("result.Count : " + result.Count);

                        response.Error = ErrorCode.ERR_AccountAlreadyRegister;
                        reply(response);
                        return;
                    }
                    Console.WriteLine("新建账号 : ");

                    //新建账号
                    AccountInfo newAccount = ComponentFactory.CreateWithId <AccountInfo>(IdGenerater.GenerateId());
                    newAccount.Account  = message.Account;
                    newAccount.Password = message.Password;

                    Log.Info($"注册新账号:{MongoHelper.ToJson(newAccount)}");

                    //新建用户信息
                    UserInfo newUser = ComponentFactory.CreateWithId <UserInfo>(newAccount.Id);
                    newUser.Nickname = $"用户{message.Account}";
                    newUser.Gold     = 10000;

                    //保存到数据库
                    await dbProxy.Save(newAccount);

                    await dbProxy.Save(newUser);

                    //释放数据库连接
                    dbProxy.Dispose();
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

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

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#19
0
        protected override async void Run(Session session, C2R_PhoneLogin message, Action <R2C_PhoneLogin> reply)
        {
            Log.Info(JsonHelper.ToJson(message));
            R2C_PhoneLogin response = new R2C_PhoneLogin();

            try
            {
                DBProxyComponent   proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                List <AccountInfo> accountInfos   = await proxyComponent.QueryJson <AccountInfo>($"{{Phone:'{message.Phone}'}}");

                // 用验证码登录
                if (message.Code.CompareTo("") != 0)
                {
                    // 先校验验证码
                    {
                        string str = HttpUtil.CheckSms("0", message.Phone, message.Code);
                        if (!CommonUtil.checkSmsCode(str))
                        {
                            response.Message = "验证码错误";
                            response.Error   = ErrorCode.ERR_PhoneCodeError;
                            reply(response);
                            return;
                        }
                    }
                    // 用户已存在,走登录流程
                    if (accountInfos.Count > 0)
                    {
                        AccountInfo accountInfo = accountInfos[0];

                        // 黑名单检测
                        if (await DBCommonUtil.CheckIsInBlackList(accountInfo.Id, session))
                        {
                            response.Message = "您的账号存在异常,请联系客服处理。";
                            response.Error   = ErrorCode.ERR_PhoneCodeError;
                            reply(response);
                            return;
                        }

                        // 更新Token
                        accountInfo.Token = CommonUtil.getToken(message.Phone);
                        await proxyComponent.Save(accountInfo);

                        // 随机分配一个Gate
                        StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                        IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                        Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

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

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

                        response.Address = outerAddress;
                        response.Key     = g2RGetLoginKey.Key;
                        response.Token   = accountInfo.Token;
                        reply(response);
                        // 登录日志
                        await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                    }
                    // 用户不存在,走注册流程
                    else
                    {
                        AccountInfo accountInfo = ComponentFactory.CreateWithId <AccountInfo>(UidUtil.createUID());
                        accountInfo.Phone         = message.Phone;
                        accountInfo.Token         = CommonUtil.getToken(message.Phone);
                        accountInfo.MachineId     = message.MachineId;
                        accountInfo.ChannelName   = message.ChannelName;
                        accountInfo.ClientVersion = message.ClientVersion;

                        await proxyComponent.Save(accountInfo);

                        // 添加用户信息
                        PlayerBaseInfo playerBaseInfo = await DBCommonUtil.addPlayerBaseInfo(accountInfo.Id, accountInfo.Phone, "", "");

                        // 随机分配一个Gate
                        StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                        IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                        Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

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

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

                        response.Address = outerAddress;
                        response.Key     = g2RGetLoginKey.Key;
                        response.Token   = accountInfo.Token;
                        reply(response);
                        // 登录日志
                        await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                    }
                }
                // 用Token登录
                else if (message.Token.CompareTo("") != 0)
                {
                    if (accountInfos.Count > 0)
                    {
                        AccountInfo accountInfo = accountInfos[0];

                        // 黑名单检测
                        if (await DBCommonUtil.CheckIsInBlackList(accountInfo.Id, session))
                        {
                            response.Message = "您的账号存在异常,请联系客服处理。";
                            response.Error   = ErrorCode.ERR_PhoneCodeError;
                            reply(response);
                            return;
                        }

                        if (accountInfo?.Token?.CompareTo(message.Token) == 0)
                        {
                            // 随机分配一个Gate
                            StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                            IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                            Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

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

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

                            response.Address = outerAddress;
                            response.Key     = g2RGetLoginKey.Key;
                            response.Token   = accountInfo.Token;
                            reply(response);

                            // 登录日志
                            await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                        }
                        else
                        {
                            response.Message = "Token失效,请重新验证登录";
                            response.Error   = ErrorCode.ERR_TokenError;
                            reply(response);
                            return;
                        }
                    }
                    else
                    {
                        response.Message = "用户不存在";
                        response.Error   = ErrorCode.ERR_AccountNoExist;
                        reply(response);
                        return;
                    }
                }
                // 传的数据错误
                else
                {
                    response.Message = "请求参数缺失";
                    response.Error   = ErrorCode.ERR_ParamError;
                    reply(response);
                    return;
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
            session.Dispose();
        }
示例#20
0
 public virtual async ETTask R2G_GetLoginKeyHandler(Scene scene, R2G_GetLoginKey request, G2R_GetLoginKey response, Action reply)
 {
 }
示例#21
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                if (message.Password != "VisitorPassword")
                {
                    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                    reply(response);
                    return;
                }

                //数据库操作对象
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                Log.Info($"登录请求:{{Account:'{message.Account}',Password:'******'}}");
                //验证账号密码是否正确
                List <AccountInfo> result = await dbProxy.QueryJson <AccountInfo>($"{{Account:'{message.Account}',Password:'******'}}");

                AccountInfo account;
                if (result.Count == 0)
                {
                    //新建账号
                    account          = ComponentFactory.CreateWithId <AccountInfo>(IdGenerater.GenerateId());
                    account.Account  = message.Account;
                    account.Password = message.Password;

                    Log.Info($"注册新账号:{MongoHelper.ToJson(account)}");

                    //新建用户信息
                    UserInfo newUser = ComponentFactory.CreateWithId <UserInfo>(account.Id);
                    newUser.NickName = $"用户{message.Account.Substring(0, 4)}";
                    BaseConfig baseConfig = Game.Scene.GetComponent <ConfigComponent>().Get <BaseConfig>(1);
                    newUser.Gold = baseConfig.Value1;

                    //保存到数据库
                    await dbProxy.Save(account);

                    await dbProxy.Save(newUser, false);
                }
                else
                {
                    account = result[0];
                }
                Log.Info($"账号登录成功{MongoHelper.ToJson(account)}");

                //将已在线玩家踢下线
                await RealmHelper.KickOutPlayer(account.Id);

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    UserId = account.Id
                });

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

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        protected override async void Run(Session session, C2R_ThirdLogin message, Action <R2C_ThirdLogin> reply)
        {
            Log.Info("收到第三方登录");

            R2C_ThirdLogin response = new R2C_ThirdLogin();

            try
            {
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                bool any = (await proxyComponent.Query <AccountInfo>(a => a.Third_Id == message.Third_Id && a.Token == "")).Any();

                List <AccountInfo> accountInfos = await proxyComponent.QueryJson <AccountInfo>($"{{Third_Id:'{message.Third_Id}'}}");

                // 用户已存在,走登录流程
                if (accountInfos.Count > 0)
                {
                    AccountInfo accountInfo = accountInfos[0];
                    // 黑名单检测
                    if (await DBCommonUtil.CheckIsInBlackList(accountInfo.Id, session))
                    {
                        response.Message = "您的账号存在异常,请联系客服处理。";
                        response.Error   = ErrorCode.ERR_PhoneCodeError;
                        reply(response);
                        return;
                    }
                    // 随机分配一个Gate
                    StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                    IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                    Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

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

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

//                    Log.Warning("Gate的ip:" + outerAddress);

                    response.Address = outerAddress;
                    response.Key     = g2RGetLoginKey.Key;
                    reply(response);

                    // 登录日志
                    await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                }
                // 用户不存在,走注册流程
                else
                {
                    AccountInfo accountInfo = ComponentFactory.CreateWithId <AccountInfo>(UidUtil.createUID());
                    accountInfo.Third_Id      = message.Third_Id;
                    accountInfo.MachineId     = message.MachineId;
                    accountInfo.ChannelName   = message.ChannelName;
                    accountInfo.ClientVersion = message.ClientVersion;

                    await proxyComponent.Save(accountInfo);

                    // 添加用户信息
                    PlayerBaseInfo playerBaseInfo = await DBCommonUtil.addPlayerBaseInfo(accountInfo.Id, "", message.Name, message.Head);

                    // 随机分配一个Gate
                    StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                    IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                    Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

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

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

                    response.Address = outerAddress;
                    response.Key     = g2RGetLoginKey.Key;
                    reply(response);

                    // 登录日志
                    await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
            session.Dispose();
        }
示例#23
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                //if (message.LoginType == 1)
                //{
                //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("C2R_LoginHandler1" + $"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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

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

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                response.Message = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name;
                //}
                //else if (message.LoginType == 2)
                //{
                //    //if (message.Account != "abcdef" || message.Password != "")
                //    //{
                //    //	response.Error = ErrorCode.ERR_AccountOrPasswordError;
                //    //	reply(response);
                //    //	return;
                //    //}
                //    // 随机分配一个Gate
                //    StartConfig config = Game.Scene.GetComponent<RealmGateAddressComponent>().GetAddress();
                //    //Log.Debug("C2R_LoginHandler2" + $"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 = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey() { Account = message.Account });

                //    string outerAddress = config.GetComponent<OuterConfig>().Address2;

                //    response.Address = outerAddress;
                //    response.Key = g2RGetLoginKey.Key;
                //}
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }