Beispiel #1
0
 private static TCPProcessCmdResults GetRechargeKingAward(DBManager dbMgr, TCPOutPacketPool pool, int nID, int roleID, int activeid, string fromDate, string toDate, List <int> minGateValueList, out TCPOutPacket tcpOutPacket)
 {
     tcpOutPacket = null;
     try
     {
         DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(ref roleID);
         string     strcmd;
         if (null == roleInfo)
         {
             strcmd       = string.Format("{0}:{1}:0", -1001, roleID);
             tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
             return(TCPProcessCmdResults.RESULT_DATA);
         }
         List <PaiHangItemData> listPaiHang = NewZoneActiveMgr.GetRankListByActiveLimit(dbMgr, fromDate, toDate, minGateValueList, activeid, minGateValueList.Count);
         int paiHang            = -1;
         int inputMoneyInPeriod = 0;
         for (int i = 0; i < listPaiHang.Count; i++)
         {
             if (roleInfo.UserID == listPaiHang[i].uid)
             {
                 paiHang            = listPaiHang[i].Val2;
                 inputMoneyInPeriod = listPaiHang[i].Val1;
             }
         }
         if (paiHang <= 0)
         {
             strcmd       = string.Format("{0}:{1}:0", -1003, roleID);
             tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
             return(TCPProcessCmdResults.RESULT_DATA);
         }
         if (inputMoneyInPeriod <= 0)
         {
             strcmd       = string.Format("{0}:{1}:0", -10006, roleID);
             tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
             return(TCPProcessCmdResults.RESULT_DATA);
         }
         if (paiHang <= 0)
         {
             strcmd       = string.Format("{0}:{1}:0", -10007, roleID);
             tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
             return(TCPProcessCmdResults.RESULT_DATA);
         }
         string     huoDongKeyStr = Global.GetHuoDongKeyString(fromDate, toDate);
         int        hasgettimes   = 0;
         string     lastgettime   = "";
         DBUserInfo userInfo      = dbMgr.GetDBUserInfo(roleInfo.UserID);
         lock (userInfo)
         {
             DBQuery.GetAwardHistoryForUser(dbMgr, roleInfo.UserID, 34, huoDongKeyStr, out hasgettimes, out lastgettime);
             if (hasgettimes > 0)
             {
                 strcmd       = string.Format("{0}:{1}:0", -10005, roleID);
                 tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                 return(TCPProcessCmdResults.RESULT_DATA);
             }
             int ret = DBWriter.AddHongDongAwardRecordForUser(dbMgr, roleInfo.UserID, 34, huoDongKeyStr, 1L, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
             if (ret < 0)
             {
                 strcmd       = string.Format("{0}:{1}:0", -1008, roleID);
                 tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                 return(TCPProcessCmdResults.RESULT_DATA);
             }
         }
         strcmd       = string.Format("{0}:{1}:{2}", 1, paiHang, activeid);
         tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
         return(TCPProcessCmdResults.RESULT_DATA);
     }
     catch (Exception ex)
     {
         DataHelper.WriteFormatExceptionLog(ex, "", false, false);
     }
     tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
     return(TCPProcessCmdResults.RESULT_DATA);
 }
        /// <summary>
        /// 充值达人领取
        /// </summary>
        /// <param name="dbMgr"></param>
        /// <param name="pool"></param>
        /// <param name="nID"></param>
        /// <param name="data"></param>
        /// <param name="count"></param>
        /// <param name="tcpOutPacket"></param>
        /// <returns></returns>
        private static TCPProcessCmdResults GetRechargeKingAward(DBManager dbMgr, TCPOutPacketPool pool, int nID, int roleID, int activeid, string fromDate, string toDate, List <int> minGateValueList, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;



            try
            {
                string strcmd = "";

                DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(roleID);
                if (null == roleInfo)
                {
                    strcmd       = string.Format("{0}:{1}:0", -1001, roleID);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }

                //返回排行信息,通过活动限制值过滤后的排名,可能没有第一名等名次
                //  List<InputKingPaiHangData> listPaiHang = Global.GetInputKingPaiHangListByHuoDongLimit(dbMgr, fromDate, toDate, minGateValueList);
                List <PaiHangItemData> listPaiHang = NewZoneActiveMgr.GetRankListByActiveLimit(dbMgr, fromDate, toDate, minGateValueList, activeid, minGateValueList.Count);
                //排行值
                int paiHang = -1;
                //活动时间范围的充值,真实货币单位
                int inputMoneyInPeriod = 0;

                for (int n = 0; n < listPaiHang.Count; n++)
                {
                    if (roleInfo.UserID == listPaiHang[n].uid)
                    {
                        paiHang            = listPaiHang[n].Val2;//得到排行值
                        inputMoneyInPeriod = listPaiHang[n].Val1;
                    }
                }

                //判断是否在排行内
                if (paiHang <= 0)
                {
                    strcmd       = string.Format("{0}:{1}:0", -1003, roleID);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }

                //在排行内但未充值,GetUserInputPaiHang()内已经做了过滤
                if (inputMoneyInPeriod <= 0)
                {
                    strcmd       = string.Format("{0}:{1}:0", -10006, roleID);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }

                //时间范围内获取的元宝数
                int roleGetYuanBaoInPeriod = Global.TransMoneyToYuanBao(inputMoneyInPeriod);

                //对排行进行修正之后,超出了奖励范围,即充值元宝数量没有达到最低的元宝数量要求
                if (paiHang <= 0)
                {
                    strcmd       = string.Format("{0}:{1}:0", -10007, roleID);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }

                //活动关键字,能够唯一标志某内活动的一个实例【在某段时间内的活动】
                string huoDongKeyStr = Global.GetHuoDongKeyString(fromDate, toDate);

                int    hasgettimes = 0;
                string lastgettime = "";

                DBUserInfo userInfo = dbMgr.GetDBUserInfo(roleInfo.UserID);

                //避免同一用户账号同时多次操作
                lock (userInfo)
                {
                    //判断是否领取过---活动关键字字符串唯一确定了每次活动,针对同类型不同时间的活动
                    DBQuery.GetAwardHistoryForUser(dbMgr, roleInfo.UserID, (int)(ActivityTypes.NewZoneRechargeKing), huoDongKeyStr, out hasgettimes, out lastgettime);

                    //这个活动每次每个用户最多领取一次
                    if (hasgettimes > 0)
                    {
                        strcmd       = string.Format("{0}:{1}:0", -10005, roleID);
                        tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                        return(TCPProcessCmdResults.RESULT_DATA);
                    }

                    //更新已领取状态
                    int ret = DBWriter.AddHongDongAwardRecordForUser(dbMgr, roleInfo.UserID, (int)(ActivityTypes.NewZoneRechargeKing), huoDongKeyStr, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    if (ret < 0)
                    {
                        strcmd       = string.Format("{0}:{1}:0", -1008, roleID);
                        tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                        return(TCPProcessCmdResults.RESULT_DATA);
                    }
                }

                strcmd = string.Format("{0}:{1}:{2}", 1, paiHang, activeid);

                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                //System.Windows.Application.Current.Dispatcher.Invoke((MethodInvoker)delegate
                //{
                // 格式化异常错误信息
                DataHelper.WriteFormatExceptionLog(ex, "", false);
                //throw ex;
                //});
            }

            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN);
            return(TCPProcessCmdResults.RESULT_DATA);
        }
Beispiel #3
0
        public static TCPProcessCmdResults ProcessQueryActiveInfo(DBManager dbMgr, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}", (TCPGameServerCmds)nID), null, true);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            try
            {
                string[] fields = cmdData.Split(new char[]
                {
                    ':'
                });
                if (fields.Length != 5)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Recv={1}, CmdData={2}", (TCPGameServerCmds)nID, fields.Length, cmdData), null, true);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                int      roleID        = Convert.ToInt32(fields[0]);
                string   fromDate      = fields[1].Replace('$', ':');
                string   toDate        = fields[2].Replace('$', ':');
                int      activeid      = Global.SafeConvertToInt32(fields[4], 10);
                string[] minYuanBaoArr = fields[3].Split(new char[]
                {
                    '_'
                });
                DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(ref roleID);
                if (null == roleInfo)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID), null, true);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                List <int> minGateValueList = new List <int>();
                foreach (string item in minYuanBaoArr)
                {
                    minGateValueList.Add(Global.SafeConvertToInt32(item, 10));
                }
                List <PaiHangItemData> listPaiHang = NewZoneActiveMgr.GetRankListByActiveLimit(dbMgr, fromDate, toDate, minGateValueList, activeid, minGateValueList.Count);
                int    inputMoneyInPeriod          = 0;
                string huoDongKeyStr = Global.GetHuoDongKeyString(fromDate, toDate);
                int    hasgettimes   = 0;
                string lastgettime   = "";
                switch (activeid)
                {
                case 34:
                    DBQuery.GetAwardHistoryForUser(dbMgr, roleInfo.UserID, 34, huoDongKeyStr, out hasgettimes, out lastgettime);
                    if (hasgettimes > 0)
                    {
                        hasgettimes = 1;
                    }
                    break;

                case 35:
                    DBQuery.GetAwardHistoryForUser(dbMgr, roleInfo.UserID, 35, huoDongKeyStr, out hasgettimes, out lastgettime);
                    if (hasgettimes > 0)
                    {
                        hasgettimes = 1;
                    }
                    break;

                case 36:
                    DBQuery.GetAwardHistoryForRole(dbMgr, roleID, roleInfo.ZoneID, activeid, huoDongKeyStr, out hasgettimes, out lastgettime);
                    if (hasgettimes > 0)
                    {
                        hasgettimes = 1;
                    }
                    break;

                case 37:
                    inputMoneyInPeriod = NewZoneActiveMgr.ComputTotalFanliValue(dbMgr, roleInfo, activeid, fromDate, toDate, minGateValueList);
                    if (inputMoneyInPeriod == 0)
                    {
                        hasgettimes = 1;
                    }
                    break;
                }
                NewZoneActiveData consumedata = new NewZoneActiveData
                {
                    YuanBao  = inputMoneyInPeriod,
                    ActiveId = activeid,
                    Ranklist = listPaiHang,
                    GetState = hasgettimes
                };
                tcpOutPacket = DataHelper.ObjectToTCPOutPacket <NewZoneActiveData>(consumedata, pool, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "", false, false);
            }
            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
            return(TCPProcessCmdResults.RESULT_DATA);
        }
        /// <summary>
        /// 新服活动查询,除了冲级狂人
        /// </summary>
        /// <param name="dbMgr"></param>
        /// <param name="pool"></param>
        /// <param name="nID"></param>
        /// <param name="data"></param>
        /// <param name="count"></param>
        /// <param name="tcpOutPacket"></param>
        /// <returns></returns>
        public static TCPProcessCmdResults ProcessQueryActiveInfo(DBManager dbMgr, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}", (TCPGameServerCmds)nID));

                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN);
                return(TCPProcessCmdResults.RESULT_DATA);
            }

            try
            {
                string[] fields = cmdData.Split(':');
                if (fields.Length != 5)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Recv={1}, CmdData={2}",
                                                                      (TCPGameServerCmds)nID, fields.Length, cmdData));

                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }

                int    roleID   = Convert.ToInt32(fields[0]);
                string fromDate = fields[1].Replace('$', ':');
                string toDate   = fields[2].Replace('$', ':');
                int    activeid = Global.SafeConvertToInt32(fields[4]);
                //排名最低元宝要求列表,依次为第一名的最小元宝,第二名的最小元宝......
                string[] minYuanBaoArr = fields[3].Split('_');

                DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(roleID);

                if (null == roleInfo)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}",
                                                                      (TCPGameServerCmds)nID, roleID));

                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }

                List <int> minGateValueList = new List <int>();
                foreach (var item in minYuanBaoArr)
                {
                    minGateValueList.Add(Global.SafeConvertToInt32(item));
                }

                //返回排行信息,返回消费王排行数据列表,可能没有第一名等名次
                List <PaiHangItemData> listPaiHang = NewZoneActiveMgr.GetRankListByActiveLimit(dbMgr, fromDate, toDate, minGateValueList, activeid, minGateValueList.Count);

                //更新最大等级角色名称 和区号
                //foreach (var item in listPaiHang)
                //{
                //    string id = "";
                //    Global.GetRoleNameAndUserID(dbMgr, item.RoleID, out item.RoleName, out id);
                //}
                //活动时间范围内的充值数,真实货币单位
                int inputMoneyInPeriod = 0;


                //活动关键字,能够唯一标志某内活动的一个实例【在某段时间内的活动】
                string huoDongKeyStr = Global.GetHuoDongKeyString(fromDate, toDate);

                int    hasgettimes = 0;
                string lastgettime = "";

                //判断是否领取过---活动关键字字符串唯一确定了每次活动,针对同类型不同时间的活动
                switch ((ActivityTypes)activeid)
                {
                case ActivityTypes.NewZoneConsumeKing:
                    // huoDongKeyStr = Global.GetHuoDongKeyString(fromDate, toDate);
                    //判断是否领取过---活动关键字字符串唯一确定了每次活动,针对同类型不同时间的活动
                    DBQuery.GetAwardHistoryForUser(dbMgr, roleInfo.UserID, (int)(ActivityTypes.NewZoneConsumeKing), huoDongKeyStr, out hasgettimes, out lastgettime);

                    //这个活动每次每个用户最多领取一次
                    if (hasgettimes > 0)
                    {
                        hasgettimes = 1;
                    }
                    break;

                case ActivityTypes.NewZoneRechargeKing:
                {
                    // huoDongKeyStr = Global.GetHuoDongKeyString(fromDate, toDate);
                    //判断是否领取过---活动关键字字符串唯一确定了每次活动,针对同类型不同时间的活动
                    DBQuery.GetAwardHistoryForUser(dbMgr, roleInfo.UserID, (int)(ActivityTypes.NewZoneRechargeKing), huoDongKeyStr, out hasgettimes, out lastgettime);

                    //这个活动每次每个用户最多领取一次
                    if (hasgettimes > 0)
                    {
                        hasgettimes = 1;
                    }
                }
                break;

                case ActivityTypes.NewZoneBosskillKing:
                {
                    // huoDongKeyStr = Global.GetHuoDongKeyString(fromDate, toDate);
                    //判断是否领取过---活动关键字字符串唯一确定了每次活动,针对同类型不同时间的活动
                    DBQuery.GetAwardHistoryForRole(dbMgr, roleID, roleInfo.ZoneID, activeid, huoDongKeyStr, out hasgettimes, out lastgettime);

                    //这个活动每次每个角色最多领取一次
                    if (hasgettimes > 0)
                    {
                        hasgettimes = 1;
                    }
                }
                break;

                case ActivityTypes.NewZoneFanli:
                {
                    inputMoneyInPeriod = NewZoneActiveMgr.ComputTotalFanliValue(dbMgr, roleInfo, activeid, fromDate, toDate, minGateValueList);
                    if (inputMoneyInPeriod == 0)
                    {
                        hasgettimes = 1;
                    }
                }

                break;
                }


                NewZoneActiveData consumedata = new NewZoneActiveData()
                {
                    YuanBao  = inputMoneyInPeriod,
                    ActiveId = activeid,
                    Ranklist = listPaiHang,
                    GetState = hasgettimes
                };
                //生成排行信息的tcp对象流
                tcpOutPacket = DataHelper.ObjectToTCPOutPacket <NewZoneActiveData>(consumedata, pool, nID);

                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "", false);
            }

            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN);
            return(TCPProcessCmdResults.RESULT_DATA);
        }