Exemplo n.º 1
0
        //注册 数据库操作
        private void RegisterSQL(User user, string channelname, string machineId, JObject responseData)
        {
            User userByName = NHibernateHelper.userManager.GetByName(user.Username);

            List <User> users = MySqlManager <User> .Instance.GetByPorperty("MachineId", machineId);

            if (users?.Count >= 10)
            {
                OperatorFail(responseData, "每台手机最多注册十个账号");
                return;
            }

            if (userByName != null)
            {
                OperatorFail(responseData, "用户已存在");
            }
            else
            {
                string uid = UidUtil.createUID();
                user.Uid            = uid;
                user.ChannelName    = channelname;
                user.ThirdId        = "";
                user.Secondpassword = "";
                user.IsRobot        = 0;
                user.Userpassword   = CommonUtil.CheckPsw(user.Userpassword);
                user.CreateTime     = DateTime.Now;
                user.MachineId      = machineId;

                var userEmail = new UserEmail()
                {
                    Uid        = uid,
                    Title      = "新用户奖励",
                    Content    = "欢迎来到疯狂升级,为您送上1000金币,快去对战吧!",
                    Reward     = "1:1000",
                    State      = 0,
                    CreateTime = DateTime.Now,
                };


                //注册用户数据 并 注册新手邮箱
                if (NHibernateHelper.userManager.Add(user) && NHibernateHelper.userEmailManager.Add(userEmail))
                {
                    OperatorSuccess(user, responseData);
                }
                else
                {
                    OperatorFail(responseData, "用户注册失败");
                }
            }
        }
Exemplo n.º 2
0
 public static void AddRobotSql()
 {
     for (int i = 0; i < 50; i++)
     {
         User user = new User()
         {
             Uid          = UidUtil.createUID(),
             ThirdId      = "",
             ChannelName  = "javgame",
             Username     = "******" + i,
             Userpassword = "",
             IsRobot      = 1
         };
         NHibernateHelper.userManager.Add(user);
     }
 }
Exemplo n.º 3
0
        protected override async void Run(Session session, C2R_Register message, Action <R2C_Register> reply)
        {
            Log.Info(JsonHelper.ToJson(message));
            R2C_Register response = new R2C_Register();

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

                if (accountInfos.Count > 0)
                {
                    response.Error   = ErrorCode.AccountExist;
                    response.Message = "用户名存在";
                    reply(response);
                    return;
                }
                AccountInfo accountInfo = ComponentFactory.CreateWithId <AccountInfo>(UidUtil.createUID());
                accountInfo.Account  = message.Account;
                accountInfo.Password = message.Password;
                await proxyComponent.Save(accountInfo);

                Stopwatch sw = new Stopwatch();
                sw.Start();
                List <AccountInfo> infos = await proxyComponent.QueryJsonCurrentDay <AccountInfo>();

                AccountInfo info = await proxyComponent.Query <AccountInfo>(accountInfo.Id);

                Log.Info($"根据id查询:{info.Account}");
                sw.Stop();
                Log.Info($"查询时间:{sw.ElapsedMilliseconds}");
                Log.Info($"当天的注册有:{infos.Count}");

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }

            session.Dispose();
        }
        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();
        }
Exemplo n.º 5
0
        private void ThirdLoginSQL(string thirdId, string nickname, string channelname, string ip, JObject responseData)
        {
            //通过第三方查询用户
            List <User> users = NHibernateHelper.userManager.GetUserByTid(thirdId);
            User        user;

            if (users?.Count == 0)
            {
                string uid = UidUtil.createUID();
                user = new User()
                {
                    //去除开头的空白
                    Username       = nickname.TrimStart(),
                    Userpassword   = "",
                    ChannelName    = channelname,
                    ThirdId        = thirdId,
                    Secondpassword = "",
                    Uid            = uid,
                    IsRobot        = 0,
                    CreateTime     = DateTime.Now,
                    MachineId      = ""
                };

                Random random = new Random();

                //注册用户数据 并 注册新手邮箱
                if (NHibernateHelper.userManager.Add(user))
                {
                    OperatorSuccess(user, responseData);
                    StatictisLogUtil.Login(uid, user.Username, ip, channelname, "1.0.43", MyCommon.OpType.Register);
                }
                else
                {
                    bool flag = false;
                    for (int i = 0; i < 10; i++)
                    {
                        int next = random.Next(1, 100);
                        if (user.Username.Length > 0)
                        {
                            user.Username.Remove(user.Username.Length - 1);
                        }

                        user.Username += next;
                        if (NHibernateHelper.userManager.Add(user))
                        {
                            flag = true;
                            break;
                        }
                    }

                    if (flag)
                    {
                        MySqlService.log.Info("第三方重复注册成功 user.Username:"******"\nuser.Uid" + user.Uid);
                        OperatorSuccess(user, responseData);

                        //第三方注册
                        StatisticsHelper.StatisticsRegister(user.Uid);
                        StatictisLogUtil.Login(uid, user.Username, ip, channelname, "1.0.43", MyCommon.OpType.Register);
                    }
                    else
                    {
                        MySqlService.log.Warn("第三方注册失败 user.Username:"******"\nuser.Uid" + user.Uid);
                        OperatorFail(responseData);
                    }
                }

                SendEmailUtil.SendEmail(uid, "新用户奖励", "欢迎来到疯狂升级,为您送上1000金币,快去对战吧!", "1:1000");
//                SendEmailUtil.SendEmail(uid, "“疯狂升级”新手指引",
//                    @"欢迎来到疯狂升级,本游戏有多种玩法供您选择,更有比赛场可以获取丰厚大奖噢!详细规则可在“关于-游戏规则”中查看,祝您游戏愉快~",
//                    "");
//                SendEmailUtil.SendEmail(uid, "“疯狂升级”游戏福利",
//                    @"每日登陆可领取签到奖励,通过游戏可获得抽奖机会,完成任务以达成成就,比赛场中获得胜利有丰厚大礼,更多精彩内容等你来玩噢~",
//                    "");
            }
            else
            {
                //第三方登陆
                user = users?[0];
                OperatorSuccess(user, responseData);
                StatisticsHelper.StatisticsLogin(user.Uid);
            }
        }
Exemplo n.º 6
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();
        }