Ejemplo n.º 1
0
        public void QueryActivityInfo(GameClient client)
        {
            JieriHongBaoKingData result = new JieriHongBaoKingData();

            result.DataAge = TimeUtil.NOW();
            if (this.InActivityTime() || this.InAwardTime())
            {
                lock (this.Mutex)
                {
                    result.RankList = this.orderedRecvList;
                }
                int    rid   = client.ClientData.RoleID;
                string rname = client.ClientData.RoleName;
                JieriHongBaoKingItemData detail = result.RankList.Find((JieriHongBaoKingItemData x) => x.RoleID == rid);
                if (null != detail)
                {
                    result.SelfCount = detail.TotalRecv;
                }
                else
                {
                    List <string> args = new List <string>
                    {
                        this.ActivityKeyStr,
                        rid.ToString()
                    };
                    result.SelfCount = Global.sendToDB <int, List <string> >(1440, args, client.ServerId);
                }
            }
            client.sendCmd <JieriHongBaoKingData>(1429, result, false);
        }
Ejemplo n.º 2
0
        public bool OnRecv(GameClient client, int zuanshi, string strFrom)
        {
            bool result;

            if (!this.InActivityTime())
            {
                LogManager.WriteLog(LogTypes.System, string.Format("领取红包失败#已不在活动时间内#rid={0},zuanshi={1}", client.ClientData.RoleID, zuanshi), null, true);
                result = false;
            }
            else
            {
                int           rid   = client.ClientData.RoleID;
                string        rname = client.ClientData.RoleName;
                List <string> args  = new List <string>
                {
                    this.ActivityKeyStr,
                    rid.ToString(),
                    "1",
                    TimeUtil.NowDataTimeString("yyyy-MM-dd HH:mm:ss"),
                    rname,
                    zuanshi.ToString()
                };
                JieriHongBaoKingItemData detail = Global.sendToDB <JieriHongBaoKingItemData, List <string> >(1436, args, client.ServerId);
                if (detail == null)
                {
                    LogManager.WriteLog(LogTypes.System, string.Format("领取红包失败#红包钻石已扣减但无法记录领取者#rid={0},zuanshi={1}", client.ClientData.RoleID, zuanshi), null, true);
                }
                lock (this.Mutex)
                {
                    if (detail == null)
                    {
                        return(true);
                    }
                    JieriHongBaoKingItemData dictItem;
                    if (!this.recvDict.TryGetValue(rid, out dictItem))
                    {
                        dictItem           = detail;
                        this.recvDict[rid] = dictItem;
                    }
                    else
                    {
                        dictItem.TotalRecv     = detail.TotalRecv;
                        dictItem.GetAwardTimes = detail.GetAwardTimes;
                    }
                    bool bExist = this.orderedRecvList.Any((JieriHongBaoKingItemData x) => x.RoleID == rid);
                    bool bAdd   = false;
                    if (!bExist && (this.orderedRecvList.Count < this.RANK_LVL_CNT || this.orderedRecvList[this.RANK_LVL_CNT - 1].TotalRecv < detail.TotalRecv))
                    {
                        this.orderedRecvList.Add(dictItem);
                        bAdd = true;
                    }
                    if (bExist || bAdd)
                    {
                        this.buildRankingList(this.orderedRecvList);
                    }
                }
                result = true;
            }
            return(result);
        }
Ejemplo n.º 3
0
        private JieriHongBaoKingItemData GetRoleRecvKingInfo(GameClient client, int count, int flags, int serverId)
        {
            int rid = client.ClientData.RoleID;
            JieriHongBaoKingItemData item = null;

            lock (this.Mutex)
            {
                if (this.recvDict.TryGetValue(rid, out item))
                {
                    return(item);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        private void RecvJieRiHongBao(GameServerClient client, int nID, byte[] cmdParams, int count)
        {
            JieriHongBaoKingItemData itemData = null;

            try
            {
                List <string> args = DataHelper.BytesToObject <List <string> >(cmdParams, 0, count);
                if (args != null)
                {
                    using (MyDbConnection3 conn = new MyDbConnection3(false))
                    {
                        string cmdText = string.Format("INSERT INTO `t_hongbao_jieri_recv` (`keystr`, `rid`, `count`, `getawardtimes`, `lasttime`, `rname`, `zuanshi`) VALUES('{0}',{1},{2},{3},'{4}','{5}','{6}') ON DUPLICATE KEY UPDATE `count`=`count`+{2},rname='{5}',`zuanshi`=`zuanshi`+{6},`lasttime`='{4}';", new object[]
                        {
                            args[0],
                            args[1],
                            args[2],
                            0,
                            args[3],
                            args[4],
                            args[5]
                        });
                        if (string.IsNullOrEmpty(args[3]) || conn.ExecuteSql(cmdText, new MySQLParameter[0]) >= 0)
                        {
                            cmdText = string.Format("SELECT `rid`,`count`,`getawardtimes`,`lasttime`,`rname` FROM `t_hongbao_jieri_recv` WHERE `keystr`='{0}' AND `rid`={1};", args[0], args[1]);
                            using (MySQLDataReader reader = conn.ExecuteReader(cmdText, new MySQLParameter[0]))
                            {
                                int ranking = 1;
                                if (reader.Read())
                                {
                                    itemData = new JieriHongBaoKingItemData
                                    {
                                        RoleID        = Global.SafeConvertToInt32(reader[0].ToString(), 10),
                                        TotalRecv     = Global.SafeConvertToInt32(reader[1].ToString(), 10),
                                        GetAwardTimes = Global.SafeConvertToInt32(reader[2].ToString(), 10),
                                        Rolename      = reader[4].ToString(),
                                        Rank          = ranking++
                                    };
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteException(ex.ToString());
            }
            client.sendCmd <JieriHongBaoKingItemData>(nID, itemData);
        }
Ejemplo n.º 5
0
 public void OnChangeName(int roleId, string oldName, string newName)
 {
     if (!string.IsNullOrEmpty(oldName) && !string.IsNullOrEmpty(newName))
     {
         lock (this.Mutex)
         {
             JieriHongBaoKingItemData item = null;
             this.recvDict.TryGetValue(roleId, out item);
             if (item != null)
             {
                 item.Rolename = newName;
             }
         }
     }
 }
Ejemplo n.º 6
0
        private void buildRankingList(List <JieriHongBaoKingItemData> rankingList)
        {
            rankingList.Sort(delegate(JieriHongBaoKingItemData left, JieriHongBaoKingItemData right)
            {
                int result;
                if (left.TotalRecv > right.TotalRecv)
                {
                    result = -1;
                }
                else if (left.TotalRecv == right.TotalRecv)
                {
                    result = left.RoleID - right.RoleID;
                }
                else
                {
                    result = 1;
                }
                return(result);
            });
            int procListIdx = 0;
            int i           = 1;

            while (i <= this.RANK_LVL_CNT && procListIdx < rankingList.Count)
            {
                AwardItem award = null;
                if (this.allAwardDict.TryGetValue(i, out award))
                {
                    JieriHongBaoKingItemData kingItem = rankingList[procListIdx];
                    if (kingItem.TotalRecv >= award.MinAwardCondionValue)
                    {
                        kingItem.Rank = i;
                        procListIdx++;
                    }
                }
                i++;
            }
            for (i = rankingList.Count - 1; i >= procListIdx; i--)
            {
                rankingList[i].Rank = -1;
                rankingList.RemoveAt(i);
            }
        }
Ejemplo n.º 7
0
        public new void GetAward(GameClient client, int awardid)
        {
            int result = 0;

            if (!this.InAwardTime())
            {
                result = -2001;
            }
            else if (!this.HasEnoughBagSpaceForAwardGoods(client, awardid))
            {
                result = -100;
            }
            else
            {
                AwardItem           allItem  = null;
                AwardItem           occItem  = null;
                AwardEffectTimeItem timeItem = null;
                if (!this.allAwardDict.TryGetValue(awardid, out allItem) || !this.occAwardDict.TryGetValue(awardid, out occItem) || !this.timeAwardDict.TryGetValue(awardid, out timeItem))
                {
                    result = -3;
                }
                else
                {
                    lock (this.Mutex)
                    {
                        JieriHongBaoKingItemData item;
                        if (!this.recvDict.TryGetValue(client.ClientData.RoleID, out item))
                        {
                            result = -20;
                            goto IL_21F;
                        }
                        if (item.GetAwardTimes > 0)
                        {
                            result = -200;
                            goto IL_21F;
                        }
                        JieriHongBaoKingItemData myData = this.GetRoleRecvKingInfo(client, 0, 0, client.ServerId);
                        if (myData == null || myData.TotalRecv < allItem.MinAwardCondionValue || myData.GetAwardTimes > 0 || myData.Rank != awardid)
                        {
                            result = -20;
                            goto IL_21F;
                        }
                        List <string> dbReq = new List <string>
                        {
                            this.ActivityKeyStr,
                            client.ClientData.RoleID.ToString(),
                            "1"
                        };
                        int ret = Global.sendToDB <int, List <string> >(1428, dbReq, client.ServerId);
                        if (ret < 0)
                        {
                            result = -15;
                            goto IL_21F;
                        }
                        myData.GetAwardTimes = 1;
                    }
                    if (!base.GiveAward(client, allItem) || !base.GiveAward(client, occItem) || !base.GiveEffectiveTimeAward(client, timeItem.ToAwardItem()))
                    {
                        LogManager.WriteLog(LogTypes.Error, string.Format("发送节日红包榜奖励的时候,发送失败,但是已经设置为领取成功, roleid={0}, rolename={1}, awardid={3}", client.ClientData.RoleID, client.ClientData.RoleName, awardid), null, true);
                    }
                    client._IconStateMgr.CheckJieRiHongBaoBang(client);
                }
            }
IL_21F:
            client.sendCmd <int>(1428, result, false);
        }