private JieriRecvKingItemData QueryRoleJieriRecvKing(DBManager dbMgr, string fromDate, string toDate, int roleID)
        {
            JieriRecvKingItemData result = null;
            MySQLConnection       conn   = null;

            try
            {
                conn = dbMgr.DBConns.PopDBConnection();
                string          cmdText = "SELECT t_roles.rid, t_roles.rname, t_roles.zoneid, x.totalrecv from t_roles,  (SELECT t_jierizengsong.receiver, SUM(t_jierizengsong.goodscnt) AS totalrecv " + string.Format(" FROM t_jierizengsong WHERE t_jierizengsong.receiver={0} AND sendtime>= '{1}' AND sendtime<='{2}') x ", roleID, fromDate, toDate) + " where t_roles.isdel=0 and t_roles.rid = x.receiver ";
                MySQLCommand    cmd     = new MySQLCommand(cmdText, conn);
                MySQLDataReader reader  = cmd.ExecuteReaderEx();
                if (reader.Read())
                {
                    result           = new JieriRecvKingItemData();
                    result.RoleID    = Convert.ToInt32(reader["rid"].ToString());
                    result.Rolename  = reader["rname"].ToString();
                    result.ZoneID    = Convert.ToInt32(reader["zoneid"].ToString());
                    result.TotalRecv = Convert.ToInt32(reader["totalrecv"].ToString());
                    result.Rank      = -1;
                }
                GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", cmdText), EventLevels.Important);
                cmd.Dispose();
            }
            finally
            {
                if (null != conn)
                {
                    dbMgr.DBConns.PushDBConnection(conn);
                }
            }
            return(result);
        }
        public string ProcRoleGetAward(GameClient client, int awardid)
        {
            JieriGiveErrorCode ec = JieriGiveErrorCode.Success;

            if (!this.InAwardTime())
            {
                ec = JieriGiveErrorCode.NotAwardTime;
            }
            else if (!this.HasEnoughBagSpaceForAwardGoods(client, awardid))
            {
                ec = JieriGiveErrorCode.NoBagSpace;
            }
            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))
                {
                    ec = JieriGiveErrorCode.ConfigError;
                }
                else
                {
                    lock (this._allMemberMutex)
                    {
                        JieriRecvKingItemData myData = this.GetRoleRecvKingInfo(client.ClientData.RoleID, client.ServerId);
                        if (myData == null || myData.TotalRecv < allItem.MinAwardCondionValue || myData.GetAwardTimes > 0 || myData.Rank != awardid)
                        {
                            ec = JieriGiveErrorCode.NotMeetAwardCond;
                            goto IL_1DB;
                        }
                        string   dbReq = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, this.FromDate.Replace(':', '$'), this.ToDate.Replace(':', '$'));
                        string[] dbRsp = Global.ExecuteDBCmd(13208, dbReq, client.ServerId);
                        if (dbRsp == null || dbRsp.Length != 1 || Convert.ToInt32(dbRsp[0]) <= 0)
                        {
                            ec = JieriGiveErrorCode.DBFailed;
                            goto IL_1DB;
                        }
                        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);
                    }
                    ec = JieriGiveErrorCode.Success;
                }
            }
IL_1DB:
            if (ec == JieriGiveErrorCode.Success)
            {
                if (client._IconStateMgr.CheckJieriRecvKing(client))
                {
                    client._IconStateMgr.AddFlushIconState(14000, client._IconStateMgr.IsAnyJieRiTipActived());
                    client._IconStateMgr.SendIconStateToClient(client);
                }
            }
            return(string.Format("{0}:{1}", (int)ec, awardid));
        }
Beispiel #3
0
        public void OnRecv(int receiver, int goods, int cnt, int serverId)
        {
            if (!InActivityTime())
            {
                return;
            }

            lock (_allMemberMutex)
            {
                // 现在本地查找,本地不存在的话,去db取,
                bool bLoadFromDb;
                JieriRecvKingItemData detail = GetRoleRecvKingInfo(receiver, out bLoadFromDb, serverId);
                if (detail == null)
                {
                    return;
                }

                if (!bLoadFromDb)
                {
                    detail.TotalRecv += cnt;
                }

                // 检测是否存在于排行榜中, 数量级很小(10个),先用List
                bool bExist = orderedRecvList.Any((detail1) => { return(detail1.RoleID == receiver); });

                bool bAdd = false;
                //  不存在于排行中,同时排行榜未满,或者该玩家赠送数量超过了排行中最后一名,那么插入到排行榜中
                if (!bExist && (orderedRecvList.Count < RANK_LVL_CNT || orderedRecvList[RANK_LVL_CNT - 1].TotalRecv < detail.TotalRecv))
                {
                    orderedRecvList.Add(detail);
                    bAdd = true;
                }

                if (bExist || bAdd)
                {
                    // 已经存在于排行中,由于更新了赠送数量,需要重建排行信息
                    // 新插入的自然需要重建
                    buildRankingList(orderedRecvList);
                }
            }

            GameClient client = GameManager.ClientMgr.FindClient(receiver);

            if (client != null && client._IconStateMgr.CheckJieriRecvKing(client))
            {
                client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.JieRiActivity, client._IconStateMgr.IsAnyJieRiTipActived());
                client._IconStateMgr.SendIconStateToClient(client);
            }
        }
 public void OnChangeName(int roleId, string oldName, string newName)
 {
     if (!string.IsNullOrEmpty(oldName) && !string.IsNullOrEmpty(newName))
     {
         lock (this._allMemberMutex)
         {
             JieriRecvKingItemData item = null;
             this.recvDict.TryGetValue(roleId, out item);
             if (item != null)
             {
                 item.Rolename = newName;
             }
         }
     }
 }
        private JieriRecvKingItemData GetRoleRecvKingInfo(int roleid, out bool bLoadFromDb, int serverId)
        {
            bLoadFromDb = false;
            JieriRecvKingItemData item = null;

            if (!this.recvDict.TryGetValue(roleid, out item))
            {
                string cmd = string.Format("{0}:{1}:{2}", roleid, this.FromDate.Replace(':', '$'), this.ToDate.Replace(':', '$'));
                item = Global.sendToDB <JieriRecvKingItemData, string>(13207, cmd, serverId);
                if (item != null)
                {
                    bLoadFromDb           = true;
                    this.recvDict[roleid] = item;
                }
            }
            return(item);
        }
        private void buildRankingList(List <JieriRecvKingItemData> rankingList)
        {
            rankingList.Sort(delegate(JieriRecvKingItemData left, JieriRecvKingItemData 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))
                {
                    JieriRecvKingItemData kingItem = rankingList[procListIdx];
                    if (kingItem.TotalRecv >= award.MinAwardCondionValue)
                    {
                        kingItem.Rank = i;
                        procListIdx++;
                    }
                }
                i++;
            }
            this.RoleCountInList = procListIdx;
            for (i = rankingList.Count - 1; i >= procListIdx; i--)
            {
                rankingList[i].Rank = -1;
                if (i >= this.RANK_LVL_CNT)
                {
                    rankingList.RemoveAt(i);
                }
            }
        }
Beispiel #7
0
        // 外部必须锁上 allMemberMutex
        private JieriRecvKingItemData GetRoleRecvKingInfo(int roleid, out bool bLoadFromDb, int serverId)
        {
            bLoadFromDb = false;
            JieriRecvKingItemData item = null;

            if (!recvDict.TryGetValue(roleid, out item))
            {
                string cmd = string.Format("{0}:{1}:{2}", roleid, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));
                item = Global.sendToDB <JieriRecvKingItemData, string>((int)TCPGameServerCmds.CMD_DB_LOAD_ROLE_JIERI_RECV_KING, cmd, serverId);
                if (item != null)
                {
                    bLoadFromDb      = true;
                    recvDict[roleid] = item;
                }
            }
            return(item);
        }
Beispiel #8
0
        // 构建排行榜数据,分两步,外部必须锁上_allMemberMutex
        // 1: 排序
        // 2: 根据每个档次的赠送数量限制,进行剔除
        private void buildRankingList(List <JieriRecvKingItemData> rankingList)
        {
            rankingList.Sort((left, right) =>
            {
                if (left.TotalRecv > right.TotalRecv)
                {
                    return(-1);
                }
                else if (left.TotalRecv == right.TotalRecv)
                {
                    // 按角色id从小到大排序
                    return(left.RoleID - right.RoleID);
                }
                else
                {
                    return(1);
                }
            });

            int procListIdx = 0;

            for (int i = 1; i <= RANK_LVL_CNT && procListIdx < rankingList.Count; ++i)
            {
                AwardItem award = null;
                if (!allAwardDict.TryGetValue(i, out award))
                {
                    continue;
                }

                JieriRecvKingItemData kingItem = rankingList[procListIdx];
                if (kingItem.TotalRecv >= award.MinAwardCondionValue)
                {
                    kingItem.Rank = i;
                    ++procListIdx;
                }
            }

            // 虽然进入了前N名,但是最小赠送次数不满足,剔除数据
            for (int i = rankingList.Count - 1; i >= procListIdx; --i)
            {
                rankingList[i].Rank = -1;
                rankingList.RemoveAt(i);
            }
        }
        public static List <JieriRecvKingItemData> QueryJieriRecvKingRank(DBManager dbMgr, string fromDate, string toDate, int rankCnt)
        {
            List <JieriRecvKingItemData> result = new List <JieriRecvKingItemData>();
            MySQLConnection conn = null;

            try
            {
                conn = dbMgr.DBConns.PopDBConnection();
                string          cmdText = string.Format("SELECT receiver, rname, zoneid, SUM(goodscnt) AS totalrecv FROM t_jierizengsong, t_roles WHERE receiver=rid AND isdel=0 AND sendtime>= '{0}' AND sendtime<='{1}' GROUP BY receiver ORDER BY totalrecv DESC, receiver ASC LIMIT {2}", fromDate, toDate, rankCnt);
                MySQLCommand    cmd     = new MySQLCommand(cmdText, conn);
                MySQLDataReader reader  = cmd.ExecuteReaderEx();
                int             count   = 0;
                while (reader.Read() && count < rankCnt)
                {
                    JieriRecvKingItemData item = new JieriRecvKingItemData
                    {
                        RoleID    = Convert.ToInt32(reader["receiver"].ToString()),
                        Rolename  = reader["rname"].ToString(),
                        ZoneID    = Convert.ToInt32(reader["zoneid"].ToString()),
                        TotalRecv = Convert.ToInt32(reader["totalrecv"].ToString()),
                        Rank      = count + 1
                    };
                    result.Add(item);
                    count++;
                }
                GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", cmdText), EventLevels.Important);
                cmd.Dispose();
            }
            finally
            {
                if (null != conn)
                {
                    dbMgr.DBConns.PushDBConnection(conn);
                }
            }
            return(result);
        }
 public void OnRecv(int receiver, int goods, int cnt, int serverId)
 {
     if (this.InActivityTime())
     {
         lock (this._allMemberMutex)
         {
             bool bLoadFromDb;
             JieriRecvKingItemData detail = this.GetRoleRecvKingInfo(receiver, out bLoadFromDb, serverId);
             if (detail == null)
             {
                 return;
             }
             if (!bLoadFromDb)
             {
                 detail.TotalRecv += cnt;
             }
             bool bExist = this.orderedRecvList.Any((JieriRecvKingItemData detail1) => detail1.RoleID == receiver);
             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(detail);
                 bAdd = true;
             }
             if (bExist || bAdd)
             {
                 this.buildRankingList(this.orderedRecvList);
             }
         }
         GameClient client = GameManager.ClientMgr.FindClient(receiver);
         if (client != null && client._IconStateMgr.CheckJieriRecvKing(client))
         {
             client._IconStateMgr.AddFlushIconState(14000, client._IconStateMgr.IsAnyJieRiTipActived());
             client._IconStateMgr.SendIconStateToClient(client);
         }
     }
 }
        public TCPProcessCmdResults ProcLoadRoleJieriRecvKing(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, "0", 30767);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                JieriRecvKingItemData rankItem = this.QueryRoleJieriRecvKing(dbMgr, fromDate, toDate, roleID);
                if (rankItem == null)
                {
                    rankItem               = new JieriRecvKingItemData();
                    rankItem.RoleID        = roleID;
                    rankItem.Rolename      = roleInfo.RoleName;
                    rankItem.TotalRecv     = 0;
                    rankItem.ZoneID        = roleInfo.ZoneID;
                    rankItem.Rank          = -1;
                    rankItem.GetAwardTimes = 0;
                }
                else
                {
                    int    hasgettimes = 0;
                    string lastgettime = "";
                    DBQuery.GetAwardHistoryForRole(dbMgr, rankItem.RoleID, rankItem.ZoneID, 52, Global.GetHuoDongKeyString(fromDate, toDate), out hasgettimes, out lastgettime);
                    rankItem.GetAwardTimes = hasgettimes;
                }
                tcpOutPacket = DataHelper.ObjectToTCPOutPacket <JieriRecvKingItemData>(rankItem, pool, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "", false, false);
            }
            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
            return(TCPProcessCmdResults.RESULT_DATA);
        }
Beispiel #12
0
        // 客户端请求领取节日收取王奖励 return `ec:awardid`
        public string ProcRoleGetAward(GameClient client, int awardid)
        {
            JieriGiveErrorCode ec = JieriGiveErrorCode.Success;

            do
            {
                if (!InAwardTime())
                {
                    ec = JieriGiveErrorCode.NotAwardTime;
                    break;
                }

                if (!HasEnoughBagSpaceForAwardGoods(client, awardid))
                {
                    ec = JieriGiveErrorCode.NoBagSpace;
                    break;
                }

                AwardItem           allItem = null, occItem = null;
                AwardEffectTimeItem timeItem = null;
                if (!allAwardDict.TryGetValue(awardid, out allItem) || !occAwardDict.TryGetValue(awardid, out occItem) ||
                    !timeAwardDict.TryGetValue(awardid, out timeItem))
                {
                    ec = JieriGiveErrorCode.ConfigError;
                    break;
                }

                lock (_allMemberMutex)
                {
                    JieriRecvKingItemData myData = GetRoleRecvKingInfo(client.ClientData.RoleID, client.ServerId);
                    if (myData == null || myData.TotalRecv < allItem.MinAwardCondionValue || myData.GetAwardTimes > 0 || myData.Rank != awardid)
                    {
                        ec = JieriGiveErrorCode.NotMeetAwardCond;
                        break;
                    }
                    string   dbReq = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));
                    string[] dbRsp = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_GET_JIERI_RECV_KING_AWARD, dbReq, client.ServerId);
                    if (dbRsp == null || dbRsp.Length != 1 || Convert.ToInt32(dbRsp[0]) <= 0)
                    {
                        ec = JieriGiveErrorCode.DBFailed;
                        break;
                    }

                    myData.GetAwardTimes = 1;
                }

                if (!GiveAward(client, allItem) || !GiveAward(client, occItem) || !GiveEffectiveTimeAward(client, timeItem.ToAwardItem()))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("发送节日收取王奖励的时候,发送失败,但是已经设置为领取成功, roleid={0}, rolename={1}, awardid={3}", client.ClientData.RoleID, client.ClientData.RoleName, awardid));
                }

                ec = JieriGiveErrorCode.Success;
            } while (false);

            if (ec == JieriGiveErrorCode.Success)
            {
                if (client._IconStateMgr.CheckJieriRecvKing(client))
                {
                    client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.JieRiActivity, client._IconStateMgr.IsAnyJieRiTipActived());
                    client._IconStateMgr.SendIconStateToClient(client);
                }
            }

            return(string.Format("{0}:{1}", (int)ec, awardid));
        }