public static async Task Test1()
 {
     for (int i = 0; i < 100; i++)
     {
         new System.Threading.Tasks.Task(() =>
         {
             StatictisLogUtil.Login("123", "123", "ip", "channel", "123", "login");
         }).Start();
     }
 }
        //tag(string):SupplyGold
        //uid(string)
        //todayCount(int)
        //goldNum(int)
        public static void SendSupplyGold(string uid)
        {
            UserInfo userInfo = NHibernateHelper.userInfoManager.GetByUid(uid);

            if (userInfo.Gold < 1500)
            {
                var config = NHibernateHelper.commonConfigManager.GetByUid(uid);
                if (config == null)
                {
                    config = ModelFactory.CreateConfig(uid);
                }
                if (config.free_gold_count > 0)
                {
                    userInfo.Gold += 2000;
                    config.free_gold_count--;
                    NHibernateHelper.commonConfigManager.Update(config);
                    NHibernateHelper.userInfoManager.Update(userInfo);

                    MySqlService.log.Info($"{uid}发放补助金");
                    //给logic服务器推送
                    IntPtr connId;
                    if (MySqlService.serviceDic.TryGetValue(TljServiceType.LogicService, out connId))
                    {
                        var jObject = new JObject();
                        jObject.Add(MyCommon.TAG, Consts.Tag_SupplyGold);
                        jObject.Add(MyCommon.UID, uid);
                        int temp = 0;
                        if (config.free_gold_count == 2)
                        {
                            temp = 1;
                        }
                        else if (config.free_gold_count == 1)
                        {
                            temp = 2;
                        }
                        else if (config.free_gold_count == 0)
                        {
                            temp = 3;
                        }
                        jObject.Add("todayCount", temp);
                        jObject.Add("goldNum", 2000);
                        MySqlService.Instance().sendMessage(connId, jObject.ToString());
                        MySqlService.log.Info($"主动发送给logic:{jObject.ToString()}");


                        //记录玩家财富变化日志
                        int afterGold  = userInfo.Gold;
                        int changeGold = 2000;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.GOLD, "奖励金发放", afterGold - changeGold, changeGold, afterGold);
                    }
                }
            }
        }
        private void OperatorSuccess(User user, string channelName, string ip, string versionName, JObject responseData)
        {
            responseData.Add(MyCommon.CODE, (int)Consts.Code.Code_OK);
            responseData.Add(MyCommon.UID, user.Uid);

            //更新下用户的任务
            MySqlUtil.UpdateUserTask(user.Uid);

            StatisticsHelper.StatisticsLogin(user.Uid);

            StatictisLogUtil.Login(user.Uid, user.Username, ip, channelName, versionName, MyCommon.OpType.Login);
        }
        private bool AddYuanbao(Goods goods, UserInfo userInfo, int num, float price, string orderid)
        {
            string[] strings = goods.props.Split(':');
            int      propId  = Convert.ToInt32(strings[0]);
            int      propNum = Convert.ToInt32(strings[1]);

            if (propId == 2)
            {
                userInfo.YuanBao += propNum * num;
                //之前的vip等级
                int vipFirstLevel = VipUtil.GetVipLevel(userInfo.RechargeVip);

                userInfo.RechargeVip += goods.price * num;
                //充值之后的vip等级
                int vipLevel = VipUtil.GetVipLevel(userInfo.RechargeVip);
                if (NHibernateHelper.userInfoManager.Update(userInfo))
                {
                    //记录玩家财富变化日志
                    int after  = userInfo.YuanBao;
                    int change = propNum * num;
                    StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.YUANBAO, "人民币购买元宝", after - change, change, after);
                    var format = string.Format("花费了{0}元,购买了{1}元宝,订单号:{2}", price, propNum * num, orderid);
                    LogUtil.Log(userInfo.Uid, MyCommon.OpType.BUYYUANBAO, format);

                    var result = vipLevel - vipFirstLevel;

                    //vip等级发生
                    if (result > 0)
                    {
                        for (int i = vipFirstLevel; i < vipLevel; i++)
                        {
                            var reward = $"1:{MySqlService.VipDatas[i].vipOnce.goldNum};{MySqlService.VipDatas[i].vipOnce.prop}";

                            //发送vip一次福利
                            SendEmailUtil.SendEmail(userInfo.Uid, $"贵族一次性福利", $"恭喜您升级到贵族{i + 1}", reward);

                            var temp = string.Format($"恭喜你升级到Vip{i + 1},发送邮件奖励:{reward}");
                            LogUtil.Log(userInfo.Uid, MyCommon.OpType.VIP_ONCE_REWARD, temp);
                        }

                        var level1 = GetLevel(vipFirstLevel);
                        var level2 = GetLevel(vipLevel);

                        userInfo.freeCount += level2 - level1;
                        MySqlService.log.Info($"{userInfo.Uid} vip等级变化:{result},加了转盘次数:{level2 - level1}");
                        NHibernateHelper.userInfoManager.Update(userInfo);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemple #5
0
        public override string OnResponse(string data)
        {
            StatictisLoginReq statictisLoginReq = null;

            try
            {
                statictisLoginReq = JsonConvert.DeserializeObject <StatictisLoginReq>(data);
            }
            catch (Exception e)
            {
                MySqlService.log.Warn("传入的参数有误:" + e);
                return(null);
            }

            string uid         = statictisLoginReq.uid;
            string ip          = statictisLoginReq.ip;
            string apkVersion  = statictisLoginReq.apkVersion;
            string channelname = statictisLoginReq.channelname;
            int    type        = statictisLoginReq.type;

            if (string.IsNullOrWhiteSpace(ip) || string.IsNullOrWhiteSpace(uid) ||
                string.IsNullOrWhiteSpace(apkVersion) || string.IsNullOrWhiteSpace(channelname) || type < 1)
            {
                MySqlService.log.Warn("字段有空:" + data);
                return(null);
            }

            User user = NHibernateHelper.userManager.GetByUid(uid);

            if (user == null)
            {
                MySqlService.log.Warn("uid未注册:" + data);
            }
            switch (type)
            {
            case 1:
                StatictisLogUtil.Login(uid, user.Username, ip, channelname, apkVersion, MyCommon.OpType.Login);
                break;

            case 2:
                StatictisLogUtil.Login(uid, user.Username, ip, channelname, apkVersion, MyCommon.OpType.Register);
                break;
            }
            return(null);
        }
Exemple #6
0
        private bool AddJinbi(Goods goods, UserInfo userInfo, int num, string reason, out string temp)
        {
            string[] strings = goods.props.Split(':');
            int      propId  = Convert.ToInt32(strings[0]);
            int      propNum = Convert.ToInt32(strings[1]);

            if (propId == 1)
            {
                temp           = propNum * num + "";
                userInfo.Gold += propNum * num;
                if (NHibernateHelper.userInfoManager.Update(userInfo))
                {
                    //记录玩家财富变化日志
                    int after  = userInfo.Gold;
                    int change = propNum * num;
                    StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.GOLD, reason,
                                                  after - change, change, after);
                    return(true);
                }
            }

            temp = null;
            return(false);
        }
        public void BuyYuanBaoSql(int goodId, int num, string uid, float price, string orderid, JObject responseData)
        {
            Goods goods     = NHibernateHelper.goodsManager.GetGoods(goodId);
            bool  IsSuccess = false;

            if (goods != null)
            {
                IsSuccess = BuyYuanbao(goods, num, price, orderid, uid);
            }
            if (IsSuccess)
            {
                //加赠元宝
                AddExtraYuanBao(uid, goods);
                //首充礼包
                AddFirstRechargeGift(uid, price);
                //充值数据统计
                Statistics statistics = ModelFactory.CreateStatistics();
                statistics.recharge_total += price;
                NHibernateHelper.statisticsManager.Update(statistics);
                User user = NHibernateHelper.userManager.GetByUid(uid);

                StatictisLogUtil.Recharge(uid, user?.Username, orderid, goodId + "", num + "", price + "");

                //充值人数数据统计
                StatisticsHelper.StatisticsRechargePerson(uid);

                OperatorSuccess(responseData);
            }
            else
            {
                string msg = $"购买元宝失败,uid: {uid},goodid: {goodId},num: {num},price:{price},goodsprice:{goods?.price * num},orderid: {orderid}";
                MySqlService.log.Warn(msg);
                LogUtil.Log(uid, MyCommon.OpType.BUYYUANBAO, msg);
                OperatorFail(responseData, $"购买元宝失败,商品价格:{goods?.price*num},支付的价格:{price}");
            }
        }
Exemple #8
0
        public override string OnResponse(string data)
        {
            OnlinePlayerReq logOnlinePlayer = null;

            try
            {
                logOnlinePlayer = JsonConvert.DeserializeObject <OnlinePlayerReq>(data);
            }
            catch (Exception e)
            {
                MySqlService.log.Warn("传入的参数有误:" + e);
                return(null);
            }

            string uid          = logOnlinePlayer.uid;
            int    type         = logOnlinePlayer.type;
            int    roomId       = logOnlinePlayer.room_id;
            bool   isAi         = logOnlinePlayer.isAI;
            string gameroomtype = logOnlinePlayer.gameroomtype;

            if (type != 3)
            {
                if (string.IsNullOrWhiteSpace(uid) || string.IsNullOrWhiteSpace(gameroomtype))
                {
                    MySqlService.log.Warn("字段有空:" + data);
                    return(null);
                }
            }

            switch (type)
            {
            case 1:
                int ai = isAi ? 1 : 0;
//                    List<Log_Login> logLogins = NHibernateHelper.LogLoginManager.GetListByUid(uid);
//                    if (logLogins.Count == 0)
//                    {
//                        MySqlService.log.Warn("未登录:" + data);
//                        return null;
//                    }
//                    Log_Login logLogin = logLogins[logLogins.Count - 1];

                StatictisLogUtil.Online(uid, "", "", "", gameroomtype, roomId, ai);
                break;

            case 2:
                Log_Online_Player onlinePlayer = NHibernateHelper.LogOnlinePlayerManager.GetByUid(uid);
                if (onlinePlayer != null)
                {
                    NHibernateHelper.LogOnlinePlayerManager.Delete(onlinePlayer);
                }
                break;

            case 3:
                var logOnlinePlayers = NHibernateHelper.LogOnlinePlayerManager.GetAll();
                foreach (var player in logOnlinePlayers)
                {
                    NHibernateHelper.LogOnlinePlayerManager.Delete(player);
                }
                break;

            default:
                MySqlService.log.Warn("type越界:" + data);
                break;
            }


            return(null);
        }
Exemple #9
0
        //购买金币
        private bool BuyJin(Goods goods, int num, string uid, int moneyType)
        {
            bool     IsSuccess = false;
            int      sumPrice  = goods.price * num;
            UserInfo userInfo  = NHibernateHelper.userInfoManager.GetByUid(uid);

            switch (moneyType)
            {
            //元宝购买
            case 2:
                if (userInfo.YuanBao >= sumPrice)
                {
                    userInfo.YuanBao -= sumPrice;
                    //先扣钱,添加金币
                    MySqlService.log.Info("先扣钱,添加金币");
                    string temp = "";
                    if (NHibernateHelper.userInfoManager.Update(userInfo) &&
                        AddJinbi(goods, userInfo, num, "元宝购买金币", out temp))
                    {
                        //记录玩家财富变化日志
                        int after  = userInfo.YuanBao;
                        int change = -sumPrice;
                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.YUANBAO, "元宝购买金币", after - change, change, after);


                        string s = string.Format("花费{0}元宝,购买了{1}个{2}", sumPrice, num, goods.goods_name);
                        LogUtil.Log(uid, MyCommon.OpType.BUYGOLD, s);
                        IsSuccess = true;
                    }
                }

                break;

            case 4:
                sumPrice = goods.price2 * num;

                if (userInfo.Medel >= sumPrice)
                {
                    userInfo.Medel -= sumPrice;
                    //先扣钱,添加金币
                    MySqlService.log.Info("先扣徽章,添加金币");
                    string temp = "";
                    if (NHibernateHelper.userInfoManager.Update(userInfo) && AddJinbi(goods, userInfo, num, "徽章购买金币", out temp))
                    {
                        //记录玩家财富变化日志
                        int after  = userInfo.Medel;
                        int change = -sumPrice;
                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.Medal, "徽章购买金币", after - change, change, after);

                        string s = string.Format("花费{0}徽章,购买了{1}个{2}", sumPrice, num, goods.goods_name);
                        LogUtil.Log(uid, MyCommon.OpType.BUYGOLD, s);
                        IsSuccess = true;
                    }
                }

                break;
            }


            return(IsSuccess);
        }
Exemple #10
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);
            }
        }
        /// <summary>
        /// 1.是金币,2.是话费,4徽章
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="propId">1,2...</param>
        /// <param name="propNum"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        public static bool ChangeProp(string uid, int propId, int propNum, string reason)
        {
            UserInfo userInfo = NHibernateHelper.userInfoManager.GetByUid(uid);

            if (userInfo == null)
            {
                MySqlService.log.Warn("用户不存在");
                return(false);
            }

            if (propId == 1)
            {
                userInfo.Gold += propNum;
                if (userInfo.Gold <= 0)
                {
                    User user = NHibernateHelper.userManager.GetByUid(uid);
                    if (user.IsRobot == 1)
                    {
                        userInfo.Gold = new Random().Next(80000, 100000);
                    }
                    else
                    {
                        userInfo.Gold = 0;
                    }
                }

                if (userInfo.Gold >= 0)
                {
                    if (!NHibernateHelper.userInfoManager.Update(userInfo))
                    {
                        MySqlService.log.Warn("添加金币失败");
                        return(false);
                    }
                    else
                    {
                        int afterGold  = userInfo.Gold;
                        int changeGold = propNum;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.GOLD, reason, afterGold - changeGold, changeGold, afterGold);

//                        string msg = $"改变了{propNum}金币";
//                        LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                    }
                    //发送奖励金;
                    SendSupplyGold(uid);
                }
                else
                {
                    MySqlService.log.Warn("金币不足");
                    return(false);
                }
            }
            else if (propId == 2)
            {
                userInfo.YuanBao += propNum;

                if (userInfo.YuanBao >= 0)
                {
                    if (!NHibernateHelper.userInfoManager.Update(userInfo))
                    {
                        MySqlService.log.Warn("添加元宝失败");
                        return(false);
                    }
                    else
                    {
                        //记录玩家财富变化日志
                        int after  = userInfo.YuanBao;
                        int change = propNum;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.YUANBAO, reason, after - change, change, after);
                        //                        string msg = $"改变了{propNum}元宝";
                        //                        LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                    }
                }
                else
                {
                    MySqlService.log.Warn("元宝不足");
                    return(false);
                }
            }
            else if (propId == 110)
            {
                userInfo.Medel += propNum;
                if (userInfo.Medel >= 0)
                {
                    if (!NHibernateHelper.userInfoManager.Update(userInfo))
                    {
                        MySqlService.log.Warn($"添加徽章失败-medal:{userInfo.Medel}-改变的数量:{propNum}");
                        return(false);
                    }
                    else
                    {
                        //记录玩家财富变化日志
                        int after  = userInfo.Medel;
                        int change = propNum;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.Medal, reason, after - change, change, after);
                        //                        string msg = $"改变了{propNum}徽章";
                        //                        LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                    }
                }
                else
                {
                    MySqlService.log.Warn($"徽章不足-medal:{userInfo.Medel}-改变的数量:{propNum}");
                    return(false);
                }
            }
            else
            {
                UserProp userProp = NHibernateHelper.userPropManager.GetUserProp(uid, propId);
                if (userProp == null)
                {
                    userProp = new UserProp()
                    {
                        Uid     = uid,
                        PropId  = propId,
                        PropNum = propNum
                    };
                    if (!NHibernateHelper.userPropManager.Add(userProp))
                    {
                        MySqlService.log.Warn($"添加道具失败-propId:{propId}-propNum:{propNum}");
                        return(false);
                    }
                    else
                    {
                        //记录玩家财富变化日志
                        int after  = propNum;
                        int change = propNum;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, propId + "", reason, after - change, change, after);
                        //                        string msg = $"改变了{propId}道具,{propNum}个";
                        //                        LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                    }
                }
                else
                {
                    userProp.PropNum += propNum;
                    if (userProp.PropNum >= 0)
                    {
                        if (!NHibernateHelper.userPropManager.Update(userProp))
                        {
                            MySqlService.log.Warn("更新道具失败");
                            return(false);
                        }
                        else
                        {
                            //记录玩家财富变化日志
                            int after  = userProp.PropNum;
                            int change = propNum;

                            StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, propId + "", reason, after - change, change, after);
                            //string msg = $"改变了{propId}道具,{propNum}个";
                            //LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                        }
                    }
                    else
                    {
                        MySqlService.log.Warn("道具不足");
                        return(false);
                    }
                }
            }
            return(true);
        }