//The background handles the release of memory events private void releaseMemoryWorker_DoWork(object sender, DoWorkEventArgs e) { try { int ticksSlot = (30 * 60 * 1000); //int ticksSlot = (60 * 1000); //Release user information (no more than 30 minutes) _DBManger.dbUserMgr.ReleaseIdleDBUserInfos(ticksSlot); //Release role information (no more than 30 minutes) _DBManger.DBRoleMgr.ReleaseIdleDBRoleInfos(ticksSlot); //Clear the used name PreNamesManager.ClearUsedPreNames(); } catch (Exception ex) { //System.Windows.Application.Current.Dispatcher.Invoke((MethodInvoker)delegate //{ // Formatting exception error message DataHelper.WriteFormatExceptionLog(ex, "releaseMemoryWorker_DoWork", false); //throw ex; //}); } }
public void LoadDatabase(MySQLConnectionString connstr, int MaxConns, int codePage) { TianMaCharSet.ConvertToCodePage = codePage; this._DBConns.BuidConnections(connstr, MaxConns); MySQLConnection conn = this._DBConns.PopDBConnection(); try { GameDBManager.BulletinMsgMgr.LoadBulletinMsgFromDB(this); GameDBManager.GameConfigMgr.LoadGameConfigFromDB(this); LiPinMaManager.LoadLiPinMaDB(this); PreNamesManager.LoadPremNamesFromDB(this); FuBenHistManager.LoadFuBenHist(this); PaiHangManager.ProcessPaiHang(this, true); GameDBManager.BangHuiJunQiMgr.LoadBangHuiJunQiItemFromDB(this); GameDBManager.PreDelRoleMgr.LoadPreDeleteRoleFromDB(this); GameDBManager.BangHuiLingDiMgr.LoadBangHuiLingDiItemsDictFromDB(this); HuangDiTeQuanMgr.LoadHuangDiTeQuan(this); GameDBManager.MarryPartyDataC.LoadPartyList(this); SingletonTemplate <NameUsedMgr> .Instance().LoadFromDatabase(this); GameDBManager.BangHuiListMgr.RefreshBangHuiListData(this); BanManager.GmBanCheckClear(this); FuMoMailManager.getInstance().LoadFuMoInfoFromDB(this); RebornStampManager.InitRebornYinJi(this); GlodAuctionMsgProcess.getInstance().LoadDataFromDB(this); BoCaiManager.getInstance().LoadDataFromDB(this); } finally { this._DBConns.PushDBConnection(conn); } this.CreateMemTables(); }
private void updatePreNamesWorker_DoWork(object sender, DoWorkEventArgs e) { try { PreNamesManager.LoadFromFiles(this._DBManger); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "updatePreNamesWorker_DoWork", false, false); } }
//The background loads events from the file that preallocated names private void updatePreNamesWorker_DoWork(object sender, DoWorkEventArgs e) { try { PreNamesManager.LoadFromFiles(_DBManger); } catch (Exception ex) { ////System.Windows.Application.Current.Dispatcher.Invoke((MethodInvoker)delegate //{ // Formatting exception error message DataHelper.WriteFormatExceptionLog(ex, "updatePreNamesWorker_DoWork", false); //throw ex; //}); } }
/// <summary> /// 从数据库中加载数据缓存 /// </summary> /// <param name="connstr">数据库连接串对象</param> public void LoadDatabase(MySQLConnectionString connstr, int MaxConns, int codePage) { TianMaCharSet.ConvertToCodePage = codePage; _DBConns.BuidConnections(connstr, MaxConns); MySQLConnection conn = _DBConns.PopDBConnection(); try { //预先加载角色信息 //_DBRoleMgr.LoadDBRoleInfos(this, conn); //查询系统公告 GameDBManager.BulletinMsgMgr.LoadBulletinMsgFromDB(this); //从数据库中获取配置参数 GameDBManager.GameConfigMgr.LoadGameConfigFromDB(this); //从数据库中加载品码 LiPinMaManager.LoadLiPinMaDB(this); //从数据库中加载预先分配的名字 PreNamesManager.LoadPremNamesFromDB(this); //副本历史记录管理 FuBenHistManager.LoadFuBenHist(this); //处理排行榜 PaiHangManager.ProcessPaiHang(this, true); //从数据库中获取帮旗列表 GameDBManager.BangHuiJunQiMgr.LoadBangHuiJunQiItemFromDB(this); //从数据库中获取领地占领列表 GameDBManager.BangHuiLingDiMgr.LoadBangHuiLingDiItemsDictFromDB(this); //皇帝特权数据项 HuangDiTeQuanMgr.LoadHuangDiTeQuan(this); } finally { _DBConns.PushDBConnection(conn); } //创建内存表 CreateMemTables(); }
private void releaseMemoryWorker_DoWork(object sender, DoWorkEventArgs e) { try { long ticks = TimeUtil.NOW(); if (ticks >= this.NextReleaseIdleDataTicks) { this.NextReleaseIdleDataTicks = ticks + 30000L; int ticksSlot = 1800000; this._DBManger.dbUserMgr.ReleaseIdleDBUserInfos(ticksSlot); this._DBManger.DBRoleMgr.ReleaseIdleDBRoleInfos(ticksSlot); PreNamesManager.ClearUsedPreNames(); } } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "releaseMemoryWorker_DoWork", false, false); } }
public TCPProcessCmdResults ProcChangeName(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 != 8) { 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); } string uid = fields[0]; int zoneId = Convert.ToInt32(fields[1]); int roleId = Convert.ToInt32(fields[2]); string newName = fields[3]; int costZuanShiBase = Convert.ToInt32(fields[4]); int costZuanShiMax = Convert.ToInt32(fields[5]); int canFreeMod = Convert.ToInt32(fields[6]); int canZuanShiMod = Convert.ToInt32(fields[7]); string oldName = ""; string failedMsg = ""; int needZuanShi = 0; DBUserInfo userInfo = null; DBRoleInfo roleInfo = null; ChangeNameType cnt = ChangeNameType.CNT_Unknown; ChangeNameError cne = ChangeNameError.Success; bool bNewNameTakePlaceHolder = false; userInfo = dbMgr.GetDBUserInfo(uid); if (userInfo == null) { failedMsg = "账号找不到 : " + uid; cne = ChangeNameError.DBFailed; } else { lock (userInfo) { int i; for (i = 0; i < userInfo.ListRoleIDs.Count; i++) { if (userInfo.ListRoleZoneIDs[i] == zoneId && userInfo.ListRoleIDs[i] == roleId) { break; } } if (i == userInfo.ListRoleIDs.Count) { failedMsg = string.Concat(new object[] { "账号: ", uid, " 在 ", zoneId.ToString(), " 区,不包含角色 ", roleId }); cne = ChangeNameError.NotContainRole; goto IL_641; } } roleInfo = dbMgr.GetDBRoleInfo(ref roleId); if (null == roleInfo) { failedMsg = "查找不到dbroleinfo,roleid=" + roleId.ToString(); cne = ChangeNameError.DBFailed; } else if (GameDBManager.PreDelRoleMgr.IfInPreDeleteState(roleId)) { failedMsg = "处在预删除状态dbroleinfo,roleid=" + roleId.ToString(); cne = ChangeNameError.DBFailed; } else { oldName = roleInfo.RoleName; int leftFreeTimes = Global.GetRoleParamsInt32(roleInfo, "LeftFreeChangeNameTimes"); if (leftFreeTimes > 0 && 1 == canFreeMod) { cnt = ChangeNameType.CNT_Free; } else { cnt = ChangeNameType.CNT_ZuanShi; } if ((cnt == ChangeNameType.CNT_Free && 1 != canFreeMod) || (cnt == ChangeNameType.CNT_ZuanShi && 1 != canZuanShiMod)) { failedMsg = "服务器没有开放改名功能, " + cnt.ToString(); cne = ChangeNameError.ServerDenied; } else { SingletonTemplate <NameUsedMgr> .Instance().AddCannotUse_Ex(oldName); if (!SingletonTemplate <NameUsedMgr> .Instance().AddCannotUse_Ex(newName) || dbMgr.IsRolenameExist(newName) || !SingletonTemplate <NameManager> .Instance().IsNameCanUseInDb(dbMgr, newName)) { failedMsg = "新名字: " + newName + " 已被占用"; cne = ChangeNameError.NameAlreayUsed; } else { bNewNameTakePlaceHolder = true; if (PreNamesManager.SetUsedPreName(newName)) { DBWriter.UpdatePreNameUsedState(dbMgr, newName, 1); } string updateKey = ""; string updateVal = ""; if (cnt == ChangeNameType.CNT_Free) { LogManager.WriteLog(LogTypes.Error, string.Format("角色请求免费改名,roleid={0}, old name={1}, new name={2}", roleId, oldName, newName), null, true); leftFreeTimes = Math.Max(0, leftFreeTimes - 1); updateKey = "LeftFreeChangeNameTimes"; updateVal = leftFreeTimes.ToString(); } else if (cnt == ChangeNameType.CNT_ZuanShi) { int alreadyZuanShiTimes = Global.GetRoleParamsInt32(roleInfo, "AlreadyZuanShiChangeNameTimes"); needZuanShi = Math.Min(costZuanShiMax, costZuanShiBase * (alreadyZuanShiTimes + 1)); LogManager.WriteLog(LogTypes.Error, string.Format("角色请求钻石改名,roleid={0}, old name={1}, new name={2}, costzuanshi={3}", new object[] { roleId, oldName, newName, needZuanShi }), null, true); lock (userInfo) { if (userInfo.Money < needZuanShi) { failedMsg = "钻石不足"; cne = ChangeNameError.ZuanShiNotEnough; goto IL_641; } int tmpMoney = userInfo.Money; userInfo.Money -= needZuanShi; if (!DBWriter.UpdateUserInfo(dbMgr, userInfo)) { userInfo.Money = tmpMoney; failedMsg = string.Format("改名时更新用户的元宝失败,UserID={0}", userInfo.UserID); cne = ChangeNameError.DBFailed; goto IL_641; } alreadyZuanShiTimes++; updateKey = "AlreadyZuanShiChangeNameTimes"; updateVal = alreadyZuanShiTimes.ToString(); } } Global.UpdateRoleParamByName(dbMgr, roleInfo, updateKey, updateVal, null); string cmdText = string.Format("UPDATE t_roles SET rname='{0}' WHERE rid={1} AND userid='{2}' AND zoneid={3}", new object[] { newName, roleId, uid, zoneId }); if (!this._Util_ExecNonQuery(dbMgr, cmdText)) { failedMsg = "更新t_roles的名字失败"; cne = ChangeNameError.DBFailed; } else { lock (userInfo) { for (int i = 0; i < userInfo.ListRoleIDs.Count; i++) { if (userInfo.ListRoleZoneIDs[i] == zoneId && userInfo.ListRoleIDs[i] == roleId) { userInfo.ListRoleNames[i] = newName; break; } } } lock (roleInfo) { oldName = roleInfo.RoleName; roleInfo.RoleName = newName; } cne = ChangeNameError.Success; } } } } } IL_641: if (cne == ChangeNameError.Success) { LogManager.WriteLog(LogTypes.Error, string.Format("角色改名成功,roleid={0}, old name={1},new name={2}", roleId, oldName, newName), null, true); this.AddChangeNameDBRecord(dbMgr, roleId, oldName, newName, cnt, needZuanShi); this._OnChangeNameSuccess(dbMgr, roleId, zoneId, oldName, newName); } else { LogManager.WriteLog(LogTypes.Error, string.Format("角色改名失败,roleid={0}, name={1}, reason={2}", roleId, oldName, failedMsg), null, true); if (bNewNameTakePlaceHolder) { SingletonTemplate <NameUsedMgr> .Instance().DelCannotUse_Ex(newName); } } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, string.Format("{0}:{1}:{2}:{3}", new object[] { (int)cne, oldName, needZuanShi, userInfo.Money }), nID); return(TCPProcessCmdResults.RESULT_DATA); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "", false, false); } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); }