Exemple #1
0
        public TCPProcessCmdResults ProcGetJieriGiveKingAward(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 != 3)
                {
                    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('$', ':');
                DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(ref roleID);
                if (null == roleInfo)
                {
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, string.Format("{0}", -1001), nID);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                string huoDongKeyStr = Global.GetHuoDongKeyString(fromDate, toDate);
                lock (roleInfo)
                {
                    int ret = DBWriter.AddHongDongAwardRecordForRole(dbMgr, roleInfo.RoleID, roleInfo.ZoneID, 51, huoDongKeyStr, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    if (ret < 0)
                    {
                        tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, string.Format("{0}", -1008), nID);
                        return(TCPProcessCmdResults.RESULT_DATA);
                    }
                }
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, string.Format("{0}", 1), nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "", false, false);
            }
            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
            return(TCPProcessCmdResults.RESULT_DATA);
        }
        public TCPProcessCmdResults ProcessGetJieriGiveAward(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 != 6)
                {
                    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        actType       = Convert.ToInt32(fields[3]);
                int        todayIdx      = Convert.ToInt32(fields[4]);
                int        awardBitFlags = Convert.ToInt32(fields[5]);
                DBRoleInfo roleInfo      = dbMgr.GetDBRoleInfo(ref roleID);
                if (null == roleInfo)
                {
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, string.Format("{0}", -1001), nID);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                string lastgettime_just_placeholder = string.Empty;
                int    hasgettimes_just_placeholder = 0;
                lock (roleInfo)
                {
                    string actKey = this._GetAwardKey_Ext_DayIdxInPeriod(fromDate, toDate, todayIdx);
                    if (DBQuery.GetAwardHistoryForRole(dbMgr, roleInfo.RoleID, roleInfo.ZoneID, actType, actKey, out hasgettimes_just_placeholder, out lastgettime_just_placeholder) < 0)
                    {
                        int ret = DBWriter.AddHongDongAwardRecordForRole(dbMgr, roleInfo.RoleID, roleInfo.ZoneID, actType, actKey, awardBitFlags, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        if (ret < 0)
                        {
                            string strcmd = string.Format("{0}", -1008);
                            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                            return(TCPProcessCmdResults.RESULT_DATA);
                        }
                    }
                    else
                    {
                        int ret = DBWriter.UpdateHongDongAwardRecordForRole(dbMgr, roleInfo.RoleID, roleInfo.ZoneID, actType, actKey, awardBitFlags, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        if (ret < 0)
                        {
                            string strcmd = string.Format("{0}", -1008);
                            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                            return(TCPProcessCmdResults.RESULT_DATA);
                        }
                    }
                }
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, string.Format("{0}", 1), nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "", false, false);
            }
            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
            return(TCPProcessCmdResults.RESULT_DATA);
        }
Exemple #3
0
 private static TCPProcessCmdResults GetBossKillAward(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);
         }
         string paiHangDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
         if (!Global.IsInActivityPeriod(fromDate, toDate))
         {
             paiHangDate = toDate;
         }
         List <HuoDongPaiHangData> listPaiHang = Global.GetPaiHangItemListByHuoDongLimit(dbMgr, minGateValueList, 36, paiHangDate, 10);
         int paiHang = -1;
         for (int i = 0; i < listPaiHang.Count; i++)
         {
             if (listPaiHang[i] != null && roleInfo.RoleID == listPaiHang[i].RoleID)
             {
                 paiHang = listPaiHang[i].PaiHang;
                 break;
             }
         }
         if (paiHang <= 0)
         {
             strcmd       = string.Format("{0}:{1}:0", -10007, activeid);
             tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
             return(TCPProcessCmdResults.RESULT_DATA);
         }
         string huoDongKeyStr = Global.GetHuoDongKeyString(fromDate, toDate);
         int    hasgettimes   = 0;
         string lastgettime   = "";
         lock (roleInfo)
         {
             DBQuery.GetAwardHistoryForRole(dbMgr, roleInfo.RoleID, roleInfo.ZoneID, 36, huoDongKeyStr, out hasgettimes, out lastgettime);
             if (hasgettimes > 0)
             {
                 strcmd       = string.Format("{0}:{1}:0", -10005, activeid);
                 tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                 return(TCPProcessCmdResults.RESULT_DATA);
             }
             int ret = DBWriter.AddHongDongAwardRecordForRole(dbMgr, roleInfo.RoleID, roleInfo.ZoneID, 36, huoDongKeyStr, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
             if (ret < 0)
             {
                 strcmd       = string.Format("{0}:{1}:0", -1008, activeid);
                 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="cmdData"></param>
        /// <param name="activityType"></param>
        /// <returns></returns>
        private static TCPProcessCmdResults GetBossKillAward(DBManager dbMgr, TCPOutPacketPool pool, int nID, int roleID, int activeid, string fromDate, string toDate, List <int> minGateValueList, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = 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);
                }

                string paiHangDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                //如果今天活动结束,就取活动结束时间作为排行读取时间点,活动介绍之前能否领取,由配置文件配置,gameserver在领取时会进行限制
                if (!Global.IsInActivityPeriod(fromDate, toDate))
                {
                    paiHangDate = toDate;
                }

                //返回排行信息【这个排行信息了处理排行值限制,活动奖励的时候,需要根据配置限制信息动态调整排行】
                List <HuoDongPaiHangData> listPaiHang = Global.GetPaiHangItemListByHuoDongLimit(dbMgr, minGateValueList, (int)ActivityTypes.NewZoneBosskillKing, paiHangDate);

                //排行值
                int paiHang = -1;

                for (int n = 0; n < listPaiHang.Count; n++)
                {
                    if (null != listPaiHang[n] && roleInfo.RoleID == listPaiHang[n].RoleID)
                    {
                        paiHang = listPaiHang[n].PaiHang + minGateValueList.Count - listPaiHang.Count;//这个值和 n+1 是不一样的,因为listPaiHang中的数据可能有排行空缺
                        break;
                    }
                }

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

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

                int    hasgettimes = 0;
                string lastgettime = "";

                //避免同一角色同时多次操作
                lock (roleInfo)
                {
                    //判断是否领取过---活动关键字字符串唯一确定了每次活动,针对同类型不同时间的活动
                    DBQuery.GetAwardHistoryForRole(dbMgr, roleInfo.RoleID, roleInfo.ZoneID, (int)ActivityTypes.NewZoneBosskillKing, huoDongKeyStr, out hasgettimes, out lastgettime);

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

                    //更新已领取状态
                    int ret = DBWriter.AddHongDongAwardRecordForRole(dbMgr, roleInfo.RoleID, roleInfo.ZoneID, (int)ActivityTypes.NewZoneBosskillKing, huoDongKeyStr, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    if (ret < 0)
                    {
                        strcmd       = string.Format("{0}:{1}:0", -1008, activeid);
                        tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                        return(TCPProcessCmdResults.RESULT_DATA);
                    }
                }
                //发送命令给gameserver 由gameserver 统一奖励
                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);
            }

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