private JieriGiveKingItemData GetClientGiveKingInfo(GameClient client, out bool bLoadFromDb) { bLoadFromDb = false; JieriGiveKingItemData item = null; if (!this.giveDict.TryGetValue(client.ClientData.RoleID, out item)) { string cmd = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, this.FromDate.Replace(':', '$'), this.ToDate.Replace(':', '$')); item = Global.sendToDB <JieriGiveKingItemData, string>(13204, cmd, client.ServerId); if (item == null) { item = new JieriGiveKingItemData(); item.RoleID = client.ClientData.RoleID; item.Rolename = client.ClientData.RoleName; item.TotalGive = 0; item.Rank = -1; item.GetAwardTimes = 0; } else { bLoadFromDb = true; } this.giveDict[client.ClientData.RoleID] = item; } return(item); }
// 外部锁_allMemberMutex private JieriGiveKingItemData GetClientGiveKingInfo(GameClient client, out bool bLoadFromDb) { bLoadFromDb = false; JieriGiveKingItemData item = null; if (!giveDict.TryGetValue(client.ClientData.RoleID, out item)) { string cmd = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, FromDate.Replace(':', '$'), ToDate.Replace(':', '$')); item = Global.sendToDB <JieriGiveKingItemData, string>((int)TCPGameServerCmds.CMD_DB_LOAD_ROLE_JIERI_GIVE_KING, cmd, client.ServerId); if (item == null) { item = new JieriGiveKingItemData(); item.RoleID = client.ClientData.RoleID; item.Rolename = client.ClientData.RoleName; item.TotalGive = 0; item.Rank = -1; item.GetAwardTimes = 0; } else { bLoadFromDb = true; } giveDict[client.ClientData.RoleID] = item; } return(item); }
private JieriGiveKingItemData QueryRoleJieriGiveKing(DBManager dbMgr, string fromDate, string toDate, int roleID) { JieriGiveKingItemData result = null; MySQLConnection conn = null; try { conn = dbMgr.DBConns.PopDBConnection(); string cmdText = "SELECT t_roles.rid, t_roles.rname, t_roles.zoneid, x.totalsend from t_roles, (SELECT t_jierizengsong.sender, SUM(t_jierizengsong.goodscnt) AS totalsend " + string.Format(" FROM t_jierizengsong WHERE t_jierizengsong.sender={0} AND sendtime>= '{1}' AND sendtime<='{2}') x ", roleID, fromDate, toDate) + " where t_roles.isdel=0 and t_roles.rid = x.sender "; MySQLCommand cmd = new MySQLCommand(cmdText, conn); MySQLDataReader reader = cmd.ExecuteReaderEx(); if (reader.Read()) { result = new JieriGiveKingItemData(); result.RoleID = Convert.ToInt32(reader["rid"].ToString()); result.Rolename = reader["rname"].ToString(); result.ZoneID = Convert.ToInt32(reader["zoneid"].ToString()); result.TotalGive = Convert.ToInt32(reader["totalsend"].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) { JieriGiveKingItemData myData = this.GetClientGiveKingInfo(client); if (myData == null || myData.TotalGive < allItem.MinAwardCondionValue || myData.GetAwardTimes > 0 || myData.Rank != awardid) { ec = JieriGiveErrorCode.NotMeetAwardCond; goto IL_1CB; } string dbReq = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, this.FromDate.Replace(':', '$'), this.ToDate.Replace(':', '$')); string[] dbRsp = Global.ExecuteDBCmd(13205, dbReq, client.ServerId); if (dbRsp == null || dbRsp.Length != 1 || Convert.ToInt32(dbRsp[0]) <= 0) { ec = JieriGiveErrorCode.DBFailed; goto IL_1CB; } 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_1CB: if (ec == JieriGiveErrorCode.Success) { if (client._IconStateMgr.CheckJieriGiveKing(client)) { client._IconStateMgr.AddFlushIconState(14000, client._IconStateMgr.IsAnyJieRiTipActived()); client._IconStateMgr.SendIconStateToClient(client); } } return(string.Format("{0}:{1}", (int)ec, awardid)); }
// 赠送了礼物 public void OnGive(GameClient client, int goods, int cnt) { if (!InActivityTime()) { return; } if (client == null) { return; } lock (_allMemberMutex) { bool bLoadFromDb; JieriGiveKingItemData detail = GetClientGiveKingInfo(client, out bLoadFromDb); if (detail == null) { return; } if (!bLoadFromDb) { detail.TotalGive += cnt; } // 检测是否存在于排行榜中, 数量级很小(10个),先用List bool bExist = orderedGiveList.Any((detail1) => { return(detail1.RoleID == client.ClientData.RoleID); }); bool bAdd = false; // 不存在于排行中,同时排行榜未满,或者该玩家赠送数量超过了排行中最后一名,那么插入到排行榜中 if (!bExist && (orderedGiveList.Count < RANK_LVL_CNT || orderedGiveList[RANK_LVL_CNT - 1].TotalGive < detail.TotalGive)) { orderedGiveList.Add(detail); bAdd = true; } if (bExist || bAdd) { // 已经存在于排行中,由于更新了赠送数量,需要重建排行信息 // 新插入的自然需要重建 buildRankingList(orderedGiveList); } } if (client._IconStateMgr.CheckJieriGiveKing(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 (_allMemberMutex) { JieriGiveKingItemData item = null; giveDict.TryGetValue(roleId, out item); if (item != null) { item.Rolename = newName; } } } }
private void buildRankingList(List <JieriGiveKingItemData> rankingList) { rankingList.Sort(delegate(JieriGiveKingItemData left, JieriGiveKingItemData right) { int result; if (left.TotalGive > right.TotalGive) { result = -1; } else if (left.TotalGive == right.TotalGive) { 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)) { JieriGiveKingItemData kingItem = rankingList[procListIdx]; if (kingItem.TotalGive >= 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); } } }
// 构建排行榜数据,分两步 // 1: 排序 // 2: 根据每个档次的赠送数量限制,进行剔除 private void buildRankingList(List <JieriGiveKingItemData> rankingList) { rankingList.Sort((left, right) => { if (left.TotalGive > right.TotalGive) { return(-1); } else if (left.TotalGive == right.TotalGive) { // 赠送数量一样,按角色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; } JieriGiveKingItemData kingItem = rankingList[procListIdx]; if (kingItem.TotalGive >= award.MinAwardCondionValue) { kingItem.Rank = i; ++procListIdx; } } // 虽然进入了前N名,但是最小赠送次数不满足,剔除数据 for (int i = rankingList.Count - 1; i >= procListIdx; --i) { rankingList[i].Rank = -1; rankingList.RemoveAt(i); } }
public void OnGive(GameClient client, int goods, int cnt) { if (this.InActivityTime()) { if (client != null) { lock (this._allMemberMutex) { bool bLoadFromDb; JieriGiveKingItemData detail = this.GetClientGiveKingInfo(client, out bLoadFromDb); if (detail == null) { return; } if (!bLoadFromDb) { detail.TotalGive += cnt; } bool bExist = this.orderedGiveList.Any((JieriGiveKingItemData detail1) => detail1.RoleID == client.ClientData.RoleID); bool bAdd = false; if (!bExist && (this.orderedGiveList.Count < this.RANK_LVL_CNT || this.orderedGiveList[this.RANK_LVL_CNT - 1].TotalGive < detail.TotalGive)) { this.orderedGiveList.Add(detail); bAdd = true; } if (bExist || bAdd) { this.buildRankingList(this.orderedGiveList); } } if (client._IconStateMgr.CheckJieriGiveKing(client)) { client._IconStateMgr.AddFlushIconState(14000, client._IconStateMgr.IsAnyJieRiTipActived()); client._IconStateMgr.SendIconStateToClient(client); } } } }
public static List <JieriGiveKingItemData> QueryJieriGiveKingRank(DBManager dbMgr, string fromDate, string toDate, int rankCnt) { List <JieriGiveKingItemData> result = new List <JieriGiveKingItemData>(); MySQLConnection conn = null; try { conn = dbMgr.DBConns.PopDBConnection(); string cmdText = string.Format("SELECT sender, rname, zoneid, SUM(goodscnt) AS totalsend FROM t_jierizengsong, t_roles WHERE sender=rid AND isdel=0 AND sendtime>= '{0}' AND sendtime<='{1}' GROUP BY sender ORDER BY totalsend DESC, sender ASC LIMIT {2}", fromDate, toDate, rankCnt); MySQLCommand cmd = new MySQLCommand(cmdText, conn); MySQLDataReader reader = cmd.ExecuteReaderEx(); int count = 0; while (reader.Read() && count < rankCnt) { JieriGiveKingItemData item = new JieriGiveKingItemData { RoleID = Convert.ToInt32(reader["sender"].ToString()), Rolename = reader["rname"].ToString(), ZoneID = Convert.ToInt32(reader["zoneid"].ToString()), TotalGive = Convert.ToInt32(reader["totalsend"].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); }
// 客户端请求领取奖励 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) { JieriGiveKingItemData myData = GetClientGiveKingInfo(client); if (myData == null || myData.TotalGive < 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_GIVE_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.CheckJieriGiveKing(client)) { client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.JieRiActivity, client._IconStateMgr.IsAnyJieRiTipActived()); client._IconStateMgr.SendIconStateToClient(client); } } return(string.Format("{0}:{1}", (int)ec, awardid)); }
public TCPProcessCmdResults ProcLoadRoleJieriGiveKing(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); } JieriGiveKingItemData rankItem = this.QueryRoleJieriGiveKing(dbMgr, fromDate, toDate, roleID); if (rankItem == null) { rankItem = new JieriGiveKingItemData(); rankItem.RoleID = roleID; rankItem.Rolename = roleInfo.RoleName; rankItem.TotalGive = 0; rankItem.ZoneID = roleInfo.ZoneID; rankItem.Rank = -1; rankItem.GetAwardTimes = 0; } else { int hasgettimes = 0; string lastgettime = ""; DBQuery.GetAwardHistoryForRole(dbMgr, rankItem.RoleID, rankItem.ZoneID, 51, Global.GetHuoDongKeyString(fromDate, toDate), out hasgettimes, out lastgettime); rankItem.GetAwardTimes = hasgettimes; } tcpOutPacket = DataHelper.ObjectToTCPOutPacket <JieriGiveKingItemData>(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); }