/// <summary> /// 获取某个时间段内的返利,这里是返回某一天的返利 /// </summary> /// <param name="dbMgr"></param> /// <param name="roleInfo"></param> /// <param name="activeid"></param> /// <param name="fromdate"></param> /// <param name="todate"></param> /// <param name="minGateValueList"></param> /// <returns></returns> static int ComputNewFanLiValue(DBManager dbMgr, DBRoleInfo roleInfo, int activeid, string fromdate, string todate, List <int> minGateValueList) { int retvalue = 0; //返回排行信息,通过活动限制值过滤后的排名,可能没有第一名等名次 List <InputKingPaiHangData> listPaiHang = Global.GetInputKingPaiHangListByHuoDongLimit(dbMgr, fromdate, todate, minGateValueList, minGateValueList.Count); //查询时如果当前时间小于结束时间,就用采用结束时间也行 //活动时间范围内的充值数,真实货币单位 int inputMoneyInPeriod = DBQuery.GetUserInputMoney(dbMgr, roleInfo.UserID, roleInfo.ZoneID, fromdate, todate); if (inputMoneyInPeriod < 0) { inputMoneyInPeriod = 0; } for (int i = 0; i < listPaiHang.Count; i++) { if (listPaiHang[i].UserID == roleInfo.UserID) { inputMoneyInPeriod = inputMoneyInPeriod * minGateValueList[listPaiHang[i].PaiHang - 1] / 100; //转换为元宝数 retvalue = Global.TransMoneyToYuanBao(inputMoneyInPeriod); break; } } return(retvalue); }
public static Dictionary <int, RebornEquipData> GetRebornEquipHoleData(DBRoleInfo dbRoleInfo) { Dictionary <int, RebornEquipData> data = null; DBQuery.GetAllRebornEquipHole(DBManager.getInstance(), dbRoleInfo.RoleID, out data); return(data); }
private void CheckRoleZuoQiData(GameServerClient client, int nID, byte[] cmdParams, int count) { try { string cmdData = new UTF8Encoding().GetString(cmdParams, 0, count); int roleID = Convert.ToInt32(cmdData); DBRoleInfo dbRoleInfo = DBManager.getInstance().FindDBRoleInfo(ref roleID); if (null == dbRoleInfo) { LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID), null, true); client.sendCmd(30767, "0"); } else { using (MyDbConnection3 conn = new MyDbConnection3(false)) { string cmdText = string.Format("update t_zuoqi set isnew=0 where rid={0}", roleID); conn.ExecuteNonQuery(cmdText, 0); } foreach (MountData item in dbRoleInfo.MountList) { item.IsNew = false; } client.sendCmd <int>(nID, 1); } } catch (Exception ex) { LogManager.WriteException(ex.Message); client.sendCmd <int>(nID, -8); } }
private void RoleCustomDataQuery(GameServerClient client, int nID, byte[] cmdParams, int count) { DBManager dbMgr = DBManager.getInstance(); int roleId = DataHelper.BytesToObject <int>(cmdParams, 0, count); RoleCustomData roleCustomData = new RoleCustomData(); roleCustomData.roleId = roleId; try { DBRoleInfo dbRoleInfo = dbMgr.GetDBRoleInfo(ref roleId); if (null != dbRoleInfo) { if (null == dbRoleInfo.roleCustomData) { dbRoleInfo.roleCustomData = this.QueryRoleCustomData(roleId); } if (null != dbRoleInfo.roleCustomData) { roleCustomData.customDataList = dbRoleInfo.roleCustomData.customDataList; } } } catch (Exception ex) { LogManager.WriteException(ex.ToString()); } client.sendCmd <RoleCustomData>(nID, roleCustomData); }
public UserRankValue InitRankValue(RankDataKey key) { DBManager dbMgr = DBManager.getInstance(); UserRankValue result; if (null == dbMgr) { result = null; } else { UserRankValue DBRankValue = null; if (RankType.Charge == key.rankType) { DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(ref this.roleID); if (null != roleInfo) { DBRankValue = this.GetUserInputRankVaule(dbMgr, roleInfo.UserID, roleInfo.ZoneID, key.StartDate, key.EndDate); } } else if (RankType.Consume == key.rankType) { DBRankValue = this.GetUserConsumeRankValue(dbMgr, key.StartDate, key.EndDate); } result = DBRankValue; } return(result); }
private void HandleClear(GameServerClient client, int nID, byte[] cmdParams, int count) { bool bResult = false; try { int roleId = DataHelper.BytesToObject <int>(cmdParams, 0, count); DBRoleInfo dbRole = DBManager.getInstance().GetDBRoleInfo(ref roleId); if (dbRole == null) { throw new Exception("SevenDayActivityManager.HandleClear not Find DBRoleInfo, roleid=" + roleId); } string sql = string.Format("DELETE FROM t_seven_day_act where roleid={0}", roleId); if (!this.ExecNonQuery(sql)) { throw new Exception("SevenDayActivityManager.HandleClear ExecSql Failed, sql= " + sql); } lock (dbRole.SevenDayActDict) { dbRole.SevenDayActDict.Clear(); } bResult = true; } catch (Exception ex) { LogManager.WriteLog(LogTypes.Error, ex.Message, null, true); bResult = false; } client.sendCmd <bool>(nID, bResult); }
private void ProcessArmorLevelStarUpCmd(GameServerClient client, int nID, byte[] cmdParams, int count) { int ret = 0; RoleDataCmdT <RoleArmorData> data = DataHelper.BytesToObject <RoleDataCmdT <RoleArmorData> >(cmdParams, 0, count); if (data != null && data.RoleID > 0) { DBManager dbMgr = DBManager.getInstance(); DBRoleInfo dbRoleInfo = dbMgr.GetDBRoleInfo(ref data.RoleID); if (null != dbRoleInfo) { if (dbRoleInfo.ArmorData.Armor != data.Value.Armor || dbRoleInfo.ArmorData.Exp != data.Value.Exp) { dbRoleInfo.ArmorData.Armor = data.Value.Armor; dbRoleInfo.ArmorData.Exp = data.Value.Exp; using (MyDbConnection3 conn = new MyDbConnection3(false)) { string cmdText = string.Format("update t_roles set armor={1},armorexp={2} where rid={0}", data.RoleID, data.Value.Armor, data.Value.Exp); ret = conn.ExecuteSql(cmdText, new MySQLParameter[0]); } } } } client.sendCmd(nID, string.Format("{0}", ret)); }
public bool RemovePreDeleteRole(DBUserInfo dbUserInfo, DBRoleInfo dbRoleInfo) { bool result; lock (this._PreDeleteRoleDict) { string userID = dbUserInfo.UserID; int roleID = dbRoleInfo.RoleID; DBManager dbMgr = DBManager.getInstance(); bool ret = false; bool hasrole = DBQuery.GetUserRole(dbMgr, userID, roleID); if (hasrole) { ret = DBWriter.UnPreRemoveRole(dbMgr, roleID); } if (!ret) { result = false; } else { this._PreDeleteRoleDict.Remove(roleID); lock (dbUserInfo) { int index = dbUserInfo.ListRoleIDs.IndexOf(roleID); if (index >= 0 && index < dbUserInfo.ListRoleIDs.Count) { dbUserInfo.ListRolePreRemoveTime[index] = ""; } } result = true; } } return(result); }
/// <summary> /// 定位用户信息 /// </summary> /// <param name="userID"></param> /// <returns></returns> public DBRoleInfo FindDBRoleInfo(int roleID) { DBRoleInfo dbRoleInfo = null; MyWeakReference weakRef = null; lock (DictRoleInfos) { if (DictRoleInfos.Count > 0) { if (DictRoleInfos.TryGetValue(roleID, out weakRef)) { if (weakRef.IsAlive) //判断是否仍在存活 { dbRoleInfo = weakRef.Target as DBRoleInfo; } } } } if (null != dbRoleInfo) { lock (dbRoleInfo) { dbRoleInfo.LastReferenceTicks = DateTime.Now.Ticks / 10000; } } return(dbRoleInfo); }
/// <summary> /// 释放空闲的角色信息 /// </summary> public void ReleaseIdleDBRoleInfos(int ticksSlot) { long nowTicks = DateTime.Now.Ticks / 10000; List <int> idleRoleIDList = new List <int>(); lock (DictRoleInfos) { foreach (var weakRef in DictRoleInfos.Values) { if (weakRef.IsAlive) //判断是否仍在存活 { DBRoleInfo dbRoleInfo = (weakRef.Target as DBRoleInfo); if (null != dbRoleInfo) { if (dbRoleInfo.ServerLineID <= 0 && nowTicks - dbRoleInfo.LastReferenceTicks >= ticksSlot) { idleRoleIDList.Add(dbRoleInfo.RoleID); } } } } } for (int i = 0; i < idleRoleIDList.Count; i++) { RemoveDBRoleInfo(idleRoleIDList[i]); LogManager.WriteLog(LogTypes.Info, string.Format("释放空闲的角色数据: {0}", idleRoleIDList[i])); } }
/// <summary> /// 获取指定的角色信息(不管角色是否删除) /// </summary> /// <param name="roleID"></param> /// <returns></returns> public DBRoleInfo GetDBAllRoleInfo(int roleID) { DBRoleInfo dbRoleInfo = _DBRoleMgr.FindDBRoleInfo(roleID); if (null == dbRoleInfo) { dbRoleInfo = new DBRoleInfo(); MySQLConnection conn = _DBConns.PopDBConnection(); try { if (!dbRoleInfo.Query(conn, roleID, false)) { return(null); } } finally { _DBConns.PushDBConnection(conn); } //更新点将积分数据 DBQuery.QueryDJPointData(this, dbRoleInfo); //放入缓存 _DBRoleMgr.AddDBRoleInfo(dbRoleInfo); } return(dbRoleInfo); }
public DBRoleInfo AddDBRoleInfo(DBRoleInfo dbRoleInfo) { MyWeakReference weakRef = null; lock (this.DictRoleInfos) { if (this.DictRoleInfos.TryGetValue(dbRoleInfo.RoleID, out weakRef)) { DBRoleInfo old = weakRef.Target as DBRoleInfo; if (null != old) { return(old); } weakRef.Target = dbRoleInfo; } else { this.DictRoleInfos.Add(dbRoleInfo.RoleID, new MyWeakReference(dbRoleInfo)); } } lock (this.DictRoleName2ID) { string formatedRoleName = Global.FormatRoleName(dbRoleInfo); this.DictRoleName2ID[formatedRoleName] = dbRoleInfo.RoleID; } return(dbRoleInfo); }
public static TCPProcessCmdResults ProcessUpdateOrnamentDataCmd(DBManager dbMgr, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket) { tcpOutPacket = null; try { OrnamentUpdateDbData dbData = DataHelper.BytesToObject <OrnamentUpdateDbData>(data, 0, count); DBRoleInfo dbRoleInfo = dbMgr.GetDBRoleInfo(ref dbData.RoleId); if (null == dbRoleInfo) { LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, dbData.RoleId), null, true); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); } lock (dbRoleInfo) { if (null == dbRoleInfo.OrnamentDataDict) { dbRoleInfo.OrnamentDataDict = new Dictionary <int, OrnamentData>(); } dbRoleInfo.OrnamentDataDict[dbData.Data.ID] = dbData.Data; } DBWriter.UpdateOramentData(dbMgr, dbData); tcpOutPacket = DataHelper.ObjectToTCPOutPacket <bool>(true, pool, nID); return(TCPProcessCmdResults.RESULT_DATA); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "", false, false); } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); }
public static TCPProcessCmdResults ProcessDBUpdateUserLimitGoodsUsedNumCmd(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 != 5) { 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]); int goodsID = Convert.ToInt32(fields[1]); int dayID = Convert.ToInt32(fields[2]); int usedNum = Convert.ToInt32(fields[3]); string stage = fields[4]; DBRoleInfo dbRoleInfo = dbMgr.GetDBRoleInfo(ref roleID); if (null == dbRoleInfo) { LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID), null, true); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); } int ret = DBWriter.AddUserLimitGoodsBuyItem(dbMgr, dbRoleInfo.UserID, goodsID, dayID, usedNum, stage); string strcmd; if (ret < 0) { strcmd = string.Format("{0}:{1}", roleID, -1); LogManager.WriteLog(LogTypes.Error, string.Format("添加限购物品的历史记录失败,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID), null, true); } else { strcmd = string.Format("{0}:{1}", roleID, 0); } 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); }
public static Dictionary <int, MazingerStoreData> GetMazingerStoreData(DBRoleInfo dbRoleInfo) { Dictionary <int, MazingerStoreData> data = null; DBQuery.GetMazingerStoreInfo(DBManager.getInstance(), dbRoleInfo.RoleID, out data); return(data); }
public void processCmdUpdateBuildData(GameServerClient client, int nID, byte[] cmdParams, int count) { string cmdData = null; try { cmdData = new UTF8Encoding().GetString(cmdParams, 0, count); } catch (Exception) { LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}", (TCPGameServerCmds)nID), null, true); client.sendCmd(30767, "0"); return; } string[] fields = cmdData.Split(new char[] { ':' }); if (fields.Length != 9) { LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Recv={1}, CmdData={2}", (TCPGameServerCmds)nID, fields.Length, cmdData), null, true); client.sendCmd(30767, "0"); } else { BuildingData myBuildData = new BuildingData(); int roleID = Convert.ToInt32(fields[0]); myBuildData.BuildId = Convert.ToInt32(fields[1]); myBuildData.BuildLev = Convert.ToInt32(fields[2]); myBuildData.BuildExp = Convert.ToInt32(fields[3]); myBuildData.TaskID_1 = Convert.ToInt32(fields[5]); myBuildData.TaskID_2 = Convert.ToInt32(fields[6]); myBuildData.TaskID_3 = Convert.ToInt32(fields[7]); myBuildData.TaskID_4 = Convert.ToInt32(fields[8]); myBuildData.BuildTime = fields[4].Replace('$', ':'); DBManager dbMgr = DBManager.getInstance(); DBRoleInfo dbRoleInfo = dbMgr.GetDBRoleInfo(ref roleID); if (null == dbRoleInfo) { LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID), null, true); client.sendCmd(30767, "0"); } else { lock (dbRoleInfo) { if (null == dbRoleInfo.BuildingDataList) { dbRoleInfo.BuildingDataList = new List <BuildingData>(); } this.UpdateBuildData(dbRoleInfo.BuildingDataList, myBuildData); } DBWriter.UpdateBuildingData(dbMgr, roleID, myBuildData); string strcmd = string.Format("{0}", 0); client.sendCmd(nID, strcmd); } } }
/// <summary> /// 新区充值返利领取 /// </summary> /// <param name="dbMgr"></param> /// <param name="pool"></param> /// <param name="nID"></param> /// <param name="data"></param> /// <param name="count"></param> /// <param name="tcpOutPacket"></param> /// <returns></returns> private static TCPProcessCmdResults GetNewFanliAward(DBManager dbMgr, TCPOutPacketPool pool, int nID, int roleID, int activeid, string fromDate, string todate, List <int> minGateValueList, out TCPOutPacket tcpOutPacket) { tcpOutPacket = null; string cmdData = null; string strcmd = ""; try { DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(roleID); if (null == roleInfo) { strcmd = string.Format("{0}:{1}:{2}", -1001, roleID, activeid); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID); return(TCPProcessCmdResults.RESULT_DATA); } int roleYuanBaoInPeriod = NewZoneActiveMgr.ComputTotalFanliValue(dbMgr, roleInfo, activeid, fromDate, todate, minGateValueList); DBUserInfo userInfo = dbMgr.GetDBUserInfo(roleInfo.UserID); //避免同一用户账号同时多次操作 lock (userInfo) { if (roleYuanBaoInPeriod > 0) { //活动时间取前一天的 DateTime sub1DayDateTime = Global.GetAddDaysDataTime(DateTime.Now, -1, true); DateTime startTime = new DateTime(sub1DayDateTime.Year, sub1DayDateTime.Month, sub1DayDateTime.Day, 0, 0, 0); DateTime endTime = new DateTime(sub1DayDateTime.Year, sub1DayDateTime.Month, sub1DayDateTime.Day, 23, 59, 59); string huoDongKeyStr = Global.GetHuoDongKeyString(startTime.ToString("yyyy-MM-dd HH:mm:ss"), endTime.ToString("yyyy-MM-dd HH:mm:ss")); //更新已领取状态 int ret = DBWriter.AddHongDongAwardRecordForUser(dbMgr, roleInfo.UserID, (int)(ActivityTypes.NewZoneFanli), huoDongKeyStr, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); if (ret < 0) { strcmd = string.Format("{0}:{1}:{2}", -1008, roleID, activeid); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID); return(TCPProcessCmdResults.RESULT_DATA); } } } strcmd = string.Format("{0}:{1}:{2}", 1, roleYuanBaoInPeriod, 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); }
public void OnUserDoSomething(int roleID, RankType rankType, int value) { DBManager dbMgr = DBManager.getInstance(); if (null != dbMgr) { DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(ref roleID); if (null != roleInfo) { double currSecond = Global.GetOffsetSecond(DateTime.Now); roleInfo.RankValue.AddUserRankValue(rankType, value); lock (this.RankDataDictLock) { foreach (KeyValuePair <string, RankData> item in this.RankDataDict) { RankDataKey rankDataKey = RankDataKey.GetKeyFromStr(item.Key); if (null != rankDataKey) { if (rankType == rankDataKey.rankType) { double startTime = Global.GetOffsetSecond(DateTime.Parse(rankDataKey.StartDate)); double endTime = Global.GetOffsetSecond(DateTime.Parse(rankDataKey.EndDate)); if (currSecond >= startTime && currSecond <= endTime) { bool bExist = false; foreach (InputKingPaiHangData rankData in item.Value.RankDataList) { if ((RankType.Charge == rankType && rankData.UserID == roleInfo.UserID) || (RankType.Consume == rankType && rankData.UserID == roleInfo.RoleID.ToString())) { rankData.PaiHangTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); rankData.PaiHangValue += value; bExist = true; break; } } if (!bExist) { int userRankValue = roleInfo.RankValue.GetRankValue(rankDataKey); InputKingPaiHangData phData = new InputKingPaiHangData { UserID = ((RankType.Charge == rankType) ? roleInfo.UserID : roleInfo.RoleID.ToString()), PaiHang = 0, PaiHangTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), PaiHangValue = userRankValue }; item.Value.RankDataList.Add(phData); } this.BuildRank(item.Value); } } } } } } } }
public TCPProcessCmdResults ProcAddBangHuiChangeNameTimes(DBManager dbMgr, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket) { tcpOutPacket = null; try { string cmdData = new UTF8Encoding().GetString(data, 0, count); string[] fields = cmdData.Split(new char[] { ':' }); if (fields.Length != 2) { 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]); int addValue = Convert.ToInt32(fields[1]); DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(ref roleId); int ne; if (null == roleInfo) { ne = -1; } else { int factionId = roleInfo.Faction; string sql = string.Format("UPDATE t_banghui SET can_mod_name_times=can_mod_name_times+{0} WHERE bhid={1}", addValue, factionId); if (!this._Util_ExecNonQuery(dbMgr, sql)) { ne = -3; } else { BangHuiDetailData detail = DBQuery.QueryBangHuiInfoByID(dbMgr, factionId); if (detail == null) { ne = -2; } else { ne = detail.CanModNameTimes; } } } byte[] bytesData = DataHelper.ObjectToBytes <int>(ne); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, bytesData, 0, bytesData.Length, nID); return(TCPProcessCmdResults.RESULT_DATA); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "", false, false); } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); }
private void HandleLoad(GameServerClient client, int nID, byte[] cmdParams, int count) { List <TradeBlackHourItem> items = null; MySQLConnection conn = null; try { string reqCmd = new UTF8Encoding().GetString(cmdParams, 0, count); string[] fields = reqCmd.Split(new char[] { ':' }); int roleid = Convert.ToInt32(fields[0]); string currDay = fields[1].Trim(); int currHour = Convert.ToInt32(fields[2]); DBRoleInfo dbRole = DBManager.getInstance().GetDBRoleInfo(ref roleid); if (dbRole == null) { throw new Exception("TradeBlackManager.HandleLoad not Find DBRoleInfo, roleid=" + roleid); } conn = DBManager.getInstance().DBConns.PopDBConnection(); string sql = string.Format("SELECT day,hour,distinct_roles,market_times,market_in_price,market_out_price,trade_times,trade_in_price,trade_out_price FROM t_ban_trade WHERE rid={0} AND ((TO_DAYS('{1}') - TO_DAYS(day) = 0 AND hour <= {2}) or (TO_DAYS('{1}') - TO_DAYS(day) = 1 AND hour > {2}))", roleid, currDay, currHour); GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", sql), EventLevels.Important); MySQLCommand cmd = new MySQLCommand(sql, conn); MySQLDataReader reader = cmd.ExecuteReaderEx(); items = new List <TradeBlackHourItem>(); while (reader.Read()) { items.Add(new TradeBlackHourItem { RoleId = roleid, Day = reader["day"].ToString().Trim(), Hour = Convert.ToInt32(reader["hour"].ToString()), TradeDistinctRoleCount = Convert.ToInt32(reader["distinct_roles"].ToString()), MarketInPrice = Convert.ToInt64(reader["market_in_price"]), MarketTimes = Convert.ToInt32(reader["market_times"]), MarketOutPrice = Convert.ToInt64(reader["market_out_price"]), TradeInPrice = Convert.ToInt64(reader["Trade_in_price"]), TradeTimes = Convert.ToInt32(reader["Trade_times"]), TradeOutPrice = Convert.ToInt64(reader["Trade_out_price"]) }); } } catch (Exception ex) { LogManager.WriteException("TradeBlackManager.HandleLoad " + ex.Message); } finally { if (null != conn) { DBManager.getInstance().DBConns.PushDBConnection(conn); } } client.sendCmd <List <TradeBlackHourItem> >(nID, items); }
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 ProcQueryJieriGiveInfo(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 != 5) { 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]); int actType = Convert.ToInt32(fields[1]); string fromDate = fields[2].Replace('$', ':'); string toDate = fields[3].Replace('$', ':'); int todayIdxInActPeriod = Convert.ToInt32(fields[4]); DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(ref roleID); if (null == roleInfo) { tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "-1", nID); return(TCPProcessCmdResults.RESULT_DATA); } int awardBitFlag = 0; int totalGive = 0; int totalRecv = 0; string lastgettime_just_placeholder = string.Empty; JieriGiveActHandler.GetTotalGiveAndRecv(dbMgr, roleID, fromDate, toDate, out totalGive, out totalRecv); DBQuery.GetAwardHistoryForRole(dbMgr, roleID, roleInfo.ZoneID, actType, this._GetAwardKey_Ext_DayIdxInPeriod(fromDate, toDate, todayIdxInActPeriod), out awardBitFlag, out lastgettime_just_placeholder); string strcmd = string.Format("{0}:{1}:{2}", totalGive, totalRecv, awardBitFlag); 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); }
public void ReleaseDBRoleInfoByID(int roleID) { DBRoleInfo dbRoleInfo = this.FindDBRoleInfo(ref roleID); if (null != dbRoleInfo) { GlobalEventSource.getInstance().fireEvent(new PlayerLogoutEventObject(dbRoleInfo)); this.RemoveDBRoleInfo(dbRoleInfo.RoleID); LogManager.WriteLog(LogTypes.SQL, string.Format("释放指定角色的数据: {0}", dbRoleInfo.RoleID), null, true); } }
public TCPProcessCmdResults ProcUpdateAward(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 != 5) { 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]); int awardId = Convert.ToInt32(fields[1]); string fromDate = fields[2].Replace('$', ':'); string toDate = fields[3].Replace('$', ':'); int awardFlag = Convert.ToInt32(fields[4]); DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(ref roleID); if (null == roleInfo) { tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "-1", nID); return(TCPProcessCmdResults.RESULT_DATA); } DBUserInfo userInfo = dbMgr.GetDBUserInfo(roleInfo.UserID); int result = 1; lock (userInfo) { result = this._UpdateAwardFlag(dbMgr, roleInfo.UserID, fromDate, toDate, roleInfo.ZoneID, awardId, awardFlag); } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, string.Format("{0}", result), nID); return(TCPProcessCmdResults.RESULT_DATA); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "", false, false); } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); }
public static TCPProcessCmdResults ProcessDBQueryUserAllLimitGoodsUsedNumInfoCmd(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]); int dayID = Convert.ToInt32(fields[1]); string stage = fields[2]; DBRoleInfo dbRoleInfo = dbMgr.GetDBRoleInfo(ref roleID); if (null == dbRoleInfo) { LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID), null, true); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); } Dictionary <int, int> GoodsInfo; if (!DBQuery.QueryUserLimitGoodsUsedNumInfoByRoleID(dbMgr, dbRoleInfo.UserID, dayID, stage, out GoodsInfo)) { LogManager.WriteLog(LogTypes.Error, string.Format("通过UserID和DayID查询当天商城购买信息失败,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID), null, true); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); } tcpOutPacket = DataHelper.ObjectToTCPOutPacket <Dictionary <int, int> >(GoodsInfo, pool, nID); return(TCPProcessCmdResults.RESULT_DATA); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "", false, false); } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); }
private void UpdateRoleJueXingData(GameServerClient client, int nID, byte[] cmdParams, int count) { try { string cmdData = new UTF8Encoding().GetString(cmdParams, 0, count); 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); client.sendCmd <int>(nID, -4); } int roleID = Convert.ToInt32(fields[0]); int suitid = Convert.ToInt32(fields[1]); string activite = fields[2]; DBRoleInfo dbRoleInfo = DBManager.getInstance().FindDBRoleInfo(ref roleID); if (null == dbRoleInfo) { LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID), null, true); client.sendCmd(30767, "0"); } else { using (MyDbConnection3 conn = new MyDbConnection3(false)) { string cmdText = string.Format("REPLACE INTO t_juexing(rid, suitid, activite) VALUES('{0}', '{1}', '{2}')", roleID, suitid, activite); conn.ExecuteNonQuery(cmdText, 0); } TaoZhuangData suitData = dbRoleInfo.JueXingTaoZhuangList.Find((TaoZhuangData _g) => _g.ID == suitid); if (null == suitData) { suitData = new TaoZhuangData { ID = suitid, ActiviteList = new List <int>() }; dbRoleInfo.JueXingTaoZhuangList.Add(suitData); } suitData.ActiviteList = Array.ConvertAll <string, int>(activite.Split(new char[] { ',' }), (string x) => Convert.ToInt32(x)).ToList <int>(); client.sendCmd <int>(nID, 0); } } catch (Exception ex) { LogManager.WriteException(ex.Message); client.sendCmd <int>(nID, -8); } }
public TCPProcessCmdResults ProcessQueryMerlinDataCmd(DBManager dbMgr, TCPOutPacketPool pool, GameServerClient client, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket) { tcpOutPacket = null; MerlinGrowthSaveDBData updateMerlinData = null; int nRoleID = -1; 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 { nRoleID = Convert.ToInt32(cmdData); DBRoleInfo dbRoleInfo = dbMgr.GetDBRoleInfo(ref nRoleID); if (null != dbRoleInfo) { lock (dbRoleInfo) { updateMerlinData = dbRoleInfo.MerlinData; } } else { updateMerlinData = MerlinDBOperate.QueryMerlinData(dbMgr, nRoleID); } if (null != updateMerlinData) { tcpOutPacket = DataHelper.ObjectToTCPOutPacket <MerlinGrowthSaveDBData>(updateMerlinData, pool, nID); return(TCPProcessCmdResults.RESULT_DATA); } updateMerlinData = new MerlinGrowthSaveDBData(); for (int i = 0; i < 4; i++) { updateMerlinData._ActiveAttr[i] = 0.0; updateMerlinData._UnActiveAttr[i] = 0.0; } tcpOutPacket = DataHelper.ObjectToTCPOutPacket <MerlinGrowthSaveDBData>(updateMerlinData, pool, nID); return(TCPProcessCmdResults.RESULT_DATA); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "", false, false); } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); }
public static TCPProcessCmdResults ProcessQueryGetResourceInfo(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)); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN); return(TCPProcessCmdResults.RESULT_DATA); } try { string[] fields = cmdData.Split(':'); if (fields.Length != 1) { LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Recv={1}, CmdData={2}", (TCPGameServerCmds)nID, fields.Length, cmdData)); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN); return(TCPProcessCmdResults.RESULT_DATA); } int roleID = Convert.ToInt32(fields[0]); DBRoleInfo dbRoleInfo = dbMgr.GetDBRoleInfo(roleID); if (null == dbRoleInfo) { LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID)); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN); return(TCPProcessCmdResults.RESULT_DATA); } //将用户的请求发起写数据库的操作 Dictionary <int, OldResourceInfo> TmpDict = DBQuery.QueryResourceGetInfo(dbMgr, roleID); tcpOutPacket = DataHelper.ObjectToTCPOutPacket <Dictionary <int, OldResourceInfo> >(TmpDict, pool, nID); return(TCPProcessCmdResults.RESULT_DATA); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "", false); } return(TCPProcessCmdResults.RESULT_FAILED); }
private void SetRoleZuoQiData(GameServerClient client, int nID, byte[] cmdParams, int count) { try { string cmdData = new UTF8Encoding().GetString(cmdParams, 0, count); 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); client.sendCmd <int>(nID, -4); } int roleID = Convert.ToInt32(fields[0]); int goodsID = Convert.ToInt32(fields[1]); int isNew = Convert.ToInt32(fields[2]); DBRoleInfo dbRoleInfo = DBManager.getInstance().FindDBRoleInfo(ref roleID); if (null == dbRoleInfo) { LogManager.WriteLog(LogTypes.Error, string.Format("发起请求的角色不存在,CMD={0}, RoleID={1}", (TCPGameServerCmds)nID, roleID), null, true); client.sendCmd(30767, "0"); } else { using (MyDbConnection3 conn = new MyDbConnection3(false)) { string cmdText = string.Format("REPLACE INTO t_zuoqi(rid, goodsid, isnew) VALUES('{0}', '{1}', '{2}')", roleID, goodsID, isNew); conn.ExecuteNonQuery(cmdText, 0); } MountData mountData = dbRoleInfo.MountList.Find((MountData _g) => _g.GoodsID == goodsID); if (null == mountData) { mountData = new MountData { GoodsID = goodsID, IsNew = (1 == isNew) }; dbRoleInfo.MountList.Add(mountData); } else { mountData.IsNew = (1 == isNew); } client.sendCmd <int>(nID, 1); } } catch (Exception ex) { LogManager.WriteException(ex.Message); client.sendCmd <int>(nID, -8); } }
public static TCPProcessCmdResults ProcessSprQueryUserActivityInfoCmd(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]); int activityType = Global.SafeConvertToInt32(fields[1], 10); string stage = fields[2]; DBRoleInfo roleInfo = dbMgr.GetDBRoleInfo(ref roleID); if (null == roleInfo) { string strcmd = string.Format("{0}:{1}:0:0", -1001, roleID); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID); return(TCPProcessCmdResults.RESULT_DATA); } Dictionary <string, string> SignData; if (!DBQuery.GetRegressAwardHistoryForUser(dbMgr, roleInfo.UserID, activityType, stage, out SignData)) { tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); } tcpOutPacket = DataHelper.ObjectToTCPOutPacket <Dictionary <string, string> >(SignData, pool, nID); return(TCPProcessCmdResults.RESULT_DATA); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "", false, false); } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); }