Example #1
0
        /// <summary>
        /// 获取某个礼品码的平台信息
        /// </summary>
        /// <param name="dbMgr"></param>
        /// <param name="fileName"></param>
        public static int GetLiPinMaPingTaiID2(DBManager dbMgr, int songLiID, string liPinMa, int roleZoneID)
        {
            liPinMa = liPinMa.ToUpper(); //转成大写

            int ptid = -1, ptrepeat = 0, zoneID = 0;

            if (!LiPinMaParse.ParseLiPinMa(liPinMa, out ptid, out ptrepeat, out zoneID))
            {
                return(-1020);
            }

            if (zoneID > 0 && roleZoneID != zoneID)
            {
                return(-1021);
            }

            return(ptid);
        }
Example #2
0
        public static string GenerateLiPinMa(int ptid, int ptrepeat, int zoneID)
        {
            string randStr      = LiPinMaParse.GenerateUniqueId().Substring(0, 12);
            string lipinma_data = string.Format("NZ{0:000}{1:0}{2:000}{3}", new object[]
            {
                ptid,
                ptrepeat,
                zoneID,
                randStr
            });

            byte[] bytesData = new UTF8Encoding().GetBytes(lipinma_data);
            CRC32  crc32     = new CRC32();

            crc32.update(bytesData);
            uint   crc32Val = crc32.getValue() % 255U;
            string str      = string.Format("{0:X}", crc32Val);

            return(lipinma_data + str);
        }
Example #3
0
        public static int GetLiPinMaPingTaiIDNX(DBManager dbMgr, int songLiID, string liPinMa, int roleZoneID)
        {
            liPinMa = liPinMa.ToUpper();
            int ptid      = -1;
            int ptrepeat  = 0;
            int zoneID    = 0;
            int maxUseNum = 0;
            int result;

            if (!LiPinMaParse.ParseLiPinMaNX2(liPinMa, out ptid, out ptrepeat, out zoneID, out maxUseNum))
            {
                result = -1020;
            }
            else if (zoneID > 0 && roleZoneID != zoneID)
            {
                result = -1021;
            }
            else
            {
                result = ptid;
            }
            return(result);
        }
Example #4
0
        public static int UseLiPinMaNX(DBManager dbMgr, int roleID, int songLiID, string liPinMa, int roleZoneID)
        {
            int result;

            if (null == LiPinMaManager._LiPinMaDict)
            {
                result = -1010;
            }
            else
            {
                Dictionary <string, LiPinMaItem> liPinMaDict = LiPinMaManager._LiPinMaDict;
                liPinMa = liPinMa.ToUpper();
                int ptid      = -1;
                int ptrepeat  = 0;
                int zoneID    = 0;
                int maxUseNum = 0;
                if (!LiPinMaParse.ParseLiPinMaNX2(liPinMa, out ptid, out ptrepeat, out zoneID, out maxUseNum))
                {
                    result = -1020;
                }
                else if (zoneID > 0 && roleZoneID != zoneID)
                {
                    result = -1021;
                }
                else
                {
                    lock (LiPinMaManager.Mutex)
                    {
                        LiPinMaItem liPinMaItem = null;
                        bool        bIsNew      = false;
                        if (!liPinMaDict.TryGetValue(liPinMa, out liPinMaItem))
                        {
                            liPinMaItem = new LiPinMaItem
                            {
                                LiPinMa       = liPinMa,
                                HuodongID     = 1,
                                MaxNum        = maxUseNum,
                                UsedNum       = 0,
                                PingTaiID     = ptid,
                                PingTaiRepeat = ptrepeat
                            };
                            liPinMaDict[liPinMa] = liPinMaItem;
                            bIsNew = true;
                        }
                        if (liPinMaItem.HuodongID != songLiID)
                        {
                            return(-1030);
                        }
                        if (liPinMaItem.MaxNum > 0 && liPinMaItem.UsedNum >= liPinMaItem.MaxNum)
                        {
                            return(-1040);
                        }
                        if (liPinMaItem.PingTaiRepeat <= 0)
                        {
                            int pingTaiID = DBQuery.QueryPingTaiIDByHuoDongID(dbMgr, liPinMaItem.HuodongID, roleID, liPinMaItem.PingTaiID);
                            if (pingTaiID == liPinMaItem.PingTaiID)
                            {
                                if (liPinMaItem.MaxNum <= 1 || !bIsNew)
                                {
                                    return(-10000);
                                }
                                int nUseNum = DBQuery.QueryUseNumByHuoDongID(dbMgr, liPinMaItem.HuodongID, roleID, liPinMaItem.PingTaiID);
                                if (nUseNum >= liPinMaItem.MaxNum)
                                {
                                    return(-1040);
                                }
                            }
                        }
                        DBWriter.AddUsedLiPinMa(dbMgr, liPinMaItem.HuodongID, liPinMaItem.LiPinMa, liPinMaItem.PingTaiID, roleID);
                        liPinMaItem.UsedNum++;
                        int usedNum = liPinMaItem.UsedNum;
                    }
                    DBWriter.InsertNewLiPinMa(dbMgr, liPinMa, songLiID.ToString(), "1", ptid.ToString(), ptrepeat.ToString(), "1");
                    result = 0;
                }
            }
            return(result);
        }
Example #5
0
        public static bool ParseLiPinMaNX2(string lipinma, out int ptid, out int ptrepeat, out int zoneID, out int nMaxUseNum)
        {
            bool result;

            if (GameDBManager.GameConfigMgr.GetGameConfigItemInt("lipinma_v1", 0) == 1)
            {
                result = LiPinMaParse.ParseLiPinMaNX(lipinma, out ptid, out ptrepeat, out zoneID, out nMaxUseNum);
            }
            else
            {
                ptid       = -1;
                ptrepeat   = 0;
                zoneID     = 0;
                nMaxUseNum = 1;
                int nAddLength = 0;
                if (lipinma.Length > 24)
                {
                    nAddLength = 2;
                }
                if (lipinma.Length < 23 + nAddLength || lipinma.Length > 24 + nAddLength)
                {
                    result = false;
                }
                else
                {
                    lipinma = lipinma.ToUpper();
                    if ("NX" != lipinma.Substring(0, 2))
                    {
                        result = false;
                    }
                    else
                    {
                        ptid     = Convert.ToInt32(lipinma.Substring(2, 4));
                        ptrepeat = Convert.ToInt32(lipinma.Substring(6, 1));
                        zoneID   = Convert.ToInt32(lipinma.Substring(7, 3));
                        if (nAddLength > 0)
                        {
                            nMaxUseNum = Convert.ToInt32(lipinma.Substring(10, 2));
                        }
                        string crc32Str = lipinma.Substring(10 + nAddLength);
                        MD5    md5      = MD5.Create();
                        byte[] data0    = new byte[25];
                        for (int i = 0; i < 5; i++)
                        {
                            data0[i] = Convert.ToByte(crc32Str.Substring(2 * i + 4, 2), 16);
                        }
                        data0[5] = 31;
                        data0[6] = 22;
                        data0[7] = 5;
                        data0[8] = 150;
                        Array.Copy(BitConverter.GetBytes(ptid), 0, data0, 9, 4);
                        Array.Copy(BitConverter.GetBytes(ptrepeat), 0, data0, 13, 4);
                        Array.Copy(BitConverter.GetBytes(zoneID), 0, data0, 17, 4);
                        Array.Copy(BitConverter.GetBytes(nMaxUseNum), 0, data0, 21, 4);
                        byte[] data = md5.ComputeHash(data0);
                        for (int i = 0; i < 2; i++)
                        {
                            if (Convert.ToByte(crc32Str.Substring(2 * i, 2), 16) != data[i])
                            {
                                return(false);
                            }
                        }
                        result = true;
                    }
                }
            }
            return(result);
        }
Example #6
0
        /// <summary>
        /// 使用某个礼品码(自己生成的特定格式的礼品码)
        /// </summary>
        /// <param name="dbMgr"></param>
        /// <param name="fileName"></param>
        public static int UseLiPinMa2(DBManager dbMgr, int roleID, int songLiID, string liPinMa, int roleZoneID)
        {
            if (null == _LiPinMaDict)
            {
                return(-1010);
            }
            Dictionary <string, LiPinMaItem> liPinMaDict = _LiPinMaDict; //先得到

            int usedNum = 0;

            liPinMa = liPinMa.ToUpper(); //转成大写

            int ptid = -1, ptrepeat = 0, zoneID = 0;

            if (!LiPinMaParse.ParseLiPinMa(liPinMa, out ptid, out ptrepeat, out zoneID))
            {
                return(-1020);
            }

            if (zoneID > 0 && roleZoneID != zoneID)
            {
                return(-1021);
            }

            //防止多用户重入
            lock (Mutex)
            {
                LiPinMaItem liPinMaItem = null;
                if (!liPinMaDict.TryGetValue(liPinMa, out liPinMaItem))
                {
                    liPinMaItem = new LiPinMaItem()
                    {
                        LiPinMa       = liPinMa,
                        HuodongID     = 1,
                        MaxNum        = 1,
                        UsedNum       = 0,
                        PingTaiID     = ptid,
                        PingTaiRepeat = ptrepeat,
                    };

                    liPinMaDict[liPinMa] = liPinMaItem;
                }

                if (liPinMaItem.HuodongID != songLiID)
                {
                    return(-1030);
                }

                if (liPinMaItem.MaxNum > 0 && liPinMaItem.UsedNum >= liPinMaItem.MaxNum)
                {
                    return(-1040);
                }

                //如果不允许平台内的礼品码重复领取
                if (liPinMaItem.PingTaiRepeat <= 0)
                {
                    //通过活动ID查询平台ID
                    int pingTaiID = DBQuery.QueryPingTaiIDByHuoDongID(dbMgr, liPinMaItem.HuodongID, roleID, liPinMaItem.PingTaiID);
                    if (pingTaiID == liPinMaItem.PingTaiID)
                    {
                        return(-10000);
                    }
                }

                //添加使用礼品码的平台记录
                DBWriter.AddUsedLiPinMa(dbMgr, liPinMaItem.HuodongID, liPinMaItem.LiPinMa, liPinMaItem.PingTaiID, roleID);

                liPinMaItem.UsedNum++;
                usedNum = liPinMaItem.UsedNum;
            }

            //插入一个新的礼品码的数据
            DBWriter.InsertNewLiPinMa(dbMgr, liPinMa, songLiID.ToString(), "1", ptid.ToString(), ptrepeat.ToString(), "1");

            return(0);
        }