private unsafe bool ChangeUserGoldInDB(TGoldChangeInfo GoldChangeInfo) { bool result = false; THumDataInfo HumanRcd = new THumDataInfo(); byte nCode = 0; try { if (GoldChangeInfo != null) { nCode = 4; if (RunDB.LoadHumRcdFromDB("1", GoldChangeInfo.sGetGoldUser, "1", &HumanRcd, 1)) { nCode = 1; if (((HumanRcd.Data.nGold + GoldChangeInfo.nGold) > 0) && ((HumanRcd.Data.nGold + GoldChangeInfo.nGold) < 2000000000)) { HumanRcd.Data.nGold += GoldChangeInfo.nGold; nCode = 2; if (RunDB.SaveHumRcdToDB(new TSaveRcd() { sAccount = "1", sChrName = GoldChangeInfo.sGetGoldUser, nSessionID = 1, boIsHero = false, boisDoubleHero = false, btJob = 0, HumanRcd = HumanRcd })) { nCode = 3; UserEngine.sub_4AE514(GoldChangeInfo); result = true; } } } } } catch { M2Share.MainOutMessage("{异常} TFrontEngine.ChangeUserGoldInDB Code:" + nCode); } return(result); }
/// <summary> /// 取玩家数据 /// </summary> /// <param name="LoadUser"></param> /// <param name="boReTry"></param> /// <returns></returns> private unsafe bool LoadHumFromDB(TLoadDBInfo LoadUser, ref bool boReTry) { bool result = false; THumDataInfo HumanRcd; TUserOpenInfo UserOpenInfo; int nOpenStatus; boReTry = false; if ((!LoadUser.boIsHero) || ((LoadUser.boIsHero) && (LoadUser.btLoadDBType == 0))) { if (InSaveRcdList(LoadUser.sAccount, LoadUser.sCharName)) { boReTry = true;// 反回TRUE,则重新加入队列 return(result); } } if (!LoadUser.boIsHero) { if ((UserEngine.GetPlayObjectEx(LoadUser.sAccount, LoadUser.sCharName) != null)) { UserEngine.KickPlayObjectEx(LoadUser.sAccount, LoadUser.sCharName); boReTry = true;// 反回TRUE,则重新加入队列 return(result); } } if (!LoadUser.boIsHero) { HumanRcd = new THumDataInfo(); if (!RunDB.LoadHumRcdFromDB(LoadUser.sAccount, LoadUser.sCharName, LoadUser.sIPaddr, &HumanRcd, LoadUser.nSessionID)) { M2Share.RunSocket.SendOutConnectMsg(LoadUser.nGateIdx, LoadUser.nSocket, LoadUser.nGSocketIdx); // 强迫用户下线 } else { UserOpenInfo = new TUserOpenInfo(); UserOpenInfo.sAccount = LoadUser.sAccount; UserOpenInfo.sChrName = LoadUser.sCharName; UserOpenInfo.LoadUser = LoadUser; UserOpenInfo.HumanRcd = HumanRcd; UserEngine.AddUserOpenInfo(UserOpenInfo); result = true; } } else { nOpenStatus = -1; HumanRcd = new THumDataInfo(); switch (LoadUser.btLoadDBType) { case 0: if (RunDB.LoadHeroRcdFromDB(LoadUser.sAccount, LoadUser.sCharName, LoadUser.sIPaddr, &HumanRcd, LoadUser.nSessionID)) { nOpenStatus = 1; } break; case 1: nOpenStatus = RunDB.NewHeroRcd(LoadUser.sCharName, LoadUser.sMsg); break; case 2: if (RunDB.DelHeroRcd(LoadUser.sAccount, LoadUser.sCharName, LoadUser.sIPaddr, LoadUser.nSessionID)) { nOpenStatus = 1; } break; case 3: LoadUser.sMsg = RunDB.QueryHeroRcdFromDB(LoadUser.sAccount, LoadUser.sCharName, LoadUser.sIPaddr, LoadUser.sMsg, LoadUser.nSessionID); break; case 4: if (RunDB.LoadDoubleHeroRcdFromDB(LoadUser.sAccount, LoadUser.sCharName, LoadUser.sIPaddr, LoadUser.btJob, &HumanRcd, LoadUser.nSessionID)) { nOpenStatus = 1; } break; case 5: nOpenStatus = RunDB.AssessDoubleHeroRcd(LoadUser.sCharName, LoadUser.sMsg, 0); break; case 6: break; case 7: LoadUser.sMsg = RunDB.QueryHeroRcdFromDB(LoadUser.sAccount, LoadUser.sCharName, LoadUser.sIPaddr, LoadUser.sMsg, LoadUser.nSessionID); break; default: nOpenStatus = 0; break; } UserOpenInfo = new TUserOpenInfo(); UserOpenInfo.sAccount = LoadUser.sAccount; UserOpenInfo.sChrName = LoadUser.sCharName; UserOpenInfo.LoadUser = LoadUser; UserOpenInfo.HumanRcd = HumanRcd; UserOpenInfo.nOpenStatus = nOpenStatus; UserEngine.AddUserOpenInfo(UserOpenInfo); result = true; } return(result); }
/// <summary> /// 处理游戏数据 /// </summary> private void ProcessGameDate() { IList <TLoadDBInfo> TempList; IList <TGoldChangeInfo> ChangeGoldList; TLoadDBInfo LoadDBInfo; TSaveRcd SaveRcd; TGoldChangeInfo GoldChangeInfo; bool boReTryLoadDB = true; bool boSaveRcd; byte nCode = 0; const string sExceptionMsg = "{异常} TFrontEngine::ProcessGameDate Code:{0}"; const string sSaveExceptionMsg = "数据库服务器出现异常,请重新启动数据库服务器(DBServer.exe)!!!"; try { ChangeGoldList = null; nCode = 17; if (M2Share.g_nSaveRcdErrorCount >= 10) { nCode = 18; if (HUtil32.GetTickCount() - M2Share.g_dwShowSaveRcdErrorTick > 5000)//修改秒触发 { nCode = 19; M2Share.g_dwShowSaveRcdErrorTick = HUtil32.GetTickCount(); M2Share.MainOutMessage(sSaveExceptionMsg); } } HUtil32.EnterCriticalSection(m_UserCriticalSection); try { nCode = 20; if (m_SaveRcdList.Count > 0) { nCode = 21; for (int I = 0; I < m_SaveRcdList.Count; I++) { m_SaveRcdTempList.Add(m_SaveRcdList[I]); } } nCode = 1; TempList = m_LoadRcdTempList; nCode = 2; m_LoadRcdTempList = m_LoadRcdList; nCode = 3; m_LoadRcdList = TempList; nCode = 4; if (m_ChangeGoldList.Count > 0) { nCode = 22; ChangeGoldList = new List <TGoldChangeInfo>(); nCode = 23; for (int I = 0; I < m_ChangeGoldList.Count; I++) { if (m_ChangeGoldList[I] != null) { ChangeGoldList.Add(m_ChangeGoldList[I]); } } } } finally { HUtil32.LeaveCriticalSection(m_UserCriticalSection); } if (m_SaveRcdTempList.Count > 0) { for (int I = 0; I < m_SaveRcdTempList.Count; I++) { SaveRcd = m_SaveRcdTempList[I]; if ((!RunDB.DBSocketConnected()) || (M2Share.g_nSaveRcdErrorCount >= 10))// DBSERVER关闭 不保存 { if ((SaveRcd.PlayObject != 0) && (!SaveRcd.boIsHero)) { GetObject <TPlayObject>(SaveRcd.PlayObject).m_boRcdSaved = true; } HUtil32.EnterCriticalSection(m_UserCriticalSection); try { for (int II = m_SaveRcdList.Count - 1; II >= 0; II--) { if (m_SaveRcdList.Count <= 0) { break; } if (m_SaveRcdList[II] == SaveRcd) { m_SaveRcdList.RemoveAt(II); nCode = 5; SaveRcd = null; nCode = 6; break; } } } finally { HUtil32.LeaveCriticalSection(m_UserCriticalSection); } } else { boSaveRcd = false; if (SaveRcd.nReTryCount == 0) { boSaveRcd = true; } else if ((SaveRcd.nReTryCount < 50) && (HUtil32.GetTickCount() - SaveRcd.dwSaveTick > 5000))// 保存错误等待5秒后在保存 { boSaveRcd = true; } else if (SaveRcd.nReTryCount >= 50) // 失败50次后不在保存 { if ((SaveRcd.PlayObject != 0) && (!SaveRcd.boIsHero)) { GetObject <TPlayObject>(SaveRcd.PlayObject).m_boRcdSaved = true; } HUtil32.EnterCriticalSection(m_UserCriticalSection); try { for (int II = m_SaveRcdList.Count - 1; II >= 0; II--) { if (m_SaveRcdList.Count <= 0) { break; } if (m_SaveRcdList[II] == SaveRcd) { m_SaveRcdList.RemoveAt(II); nCode = 7; SaveRcd = null; nCode = 8; break; } } } finally { HUtil32.LeaveCriticalSection(m_UserCriticalSection); } } if (boSaveRcd)// 保存人物 英雄 双英雄数据 { if (RunDB.SaveHumRcdToDB(SaveRcd)) { if ((SaveRcd.PlayObject != 0) && (!SaveRcd.boIsHero)) { GetObject <TPlayObject>(SaveRcd.PlayObject).m_boRcdSaved = true; } HUtil32.EnterCriticalSection(m_UserCriticalSection); try { for (int II = m_SaveRcdList.Count - 1; II >= 0; II--) { if (m_SaveRcdList.Count <= 0) { break; } if (m_SaveRcdList[II] == SaveRcd) { m_SaveRcdList.RemoveAt(II); nCode = 9; SaveRcd = null; nCode = 10; break; } } } finally { HUtil32.LeaveCriticalSection(m_UserCriticalSection); } } else { SaveRcd.nReTryCount++;// 保存失败 SaveRcd.dwSaveTick = HUtil32.GetTickCount(); } } } } m_SaveRcdTempList.Clear(); nCode = 11; } if (m_LoadRcdTempList.Count > 0) { nCode = 17; for (int I = 0; I < m_LoadRcdTempList.Count; I++) { nCode = 18; LoadDBInfo = m_LoadRcdTempList[I]; nCode = 19; if ((!LoadHumFromDB(LoadDBInfo, ref boReTryLoadDB)) && (!LoadDBInfo.boIsHero))// 加载人物 英雄 双英雄数据 { M2Share.RunSocket.CloseUser(LoadDBInfo.nGateIdx, LoadDBInfo.nSocket); } if (!boReTryLoadDB) { Dispose(LoadDBInfo); LoadDBInfo = null; } else { // 如果读取人物数据失败(数据还没有保存),则重新加入队列 HUtil32.EnterCriticalSection(m_UserCriticalSection); try { m_LoadRcdList.Add(LoadDBInfo); } finally { HUtil32.LeaveCriticalSection(m_UserCriticalSection); } } } } m_LoadRcdTempList.Clear(); nCode = 12; if (ChangeGoldList != null) { nCode = 121; try { if (ChangeGoldList.Count > 0) { nCode = 122; for (int I = 0; I < ChangeGoldList.Count; I++) { nCode = 123; GoldChangeInfo = ChangeGoldList[I]; nCode = 125; if (GoldChangeInfo != null) { nCode = 126; ChangeUserGoldInDB(GoldChangeInfo); nCode = 13; Dispose(GoldChangeInfo); nCode = 14; } } } } finally { nCode = 15; Dispose(ChangeGoldList); ChangeGoldList = null; } } } catch { M2Share.MainOutMessage(string.Format(sExceptionMsg, nCode)); } }