diff options
author | w12x <none@none> | 2008-10-22 04:05:15 -0500 |
---|---|---|
committer | w12x <none@none> | 2008-10-22 04:05:15 -0500 |
commit | bde02d68298e31eb972ada39e5730786d629d32a (patch) | |
tree | 24309a21138ae8e7822d5c1fae05332999270339 /src | |
parent | 389a9e3cea196275e13f4eb66ef99fb631607631 (diff) |
[svn] Added sanity checks in loading player cache to prevent crashing upon corrupted player data.
--HG--
branch : trunk
Diffstat (limited to 'src')
-rw-r--r-- | src/game/ObjectMgr.cpp | 20 | ||||
-rw-r--r-- | src/game/Player.cpp | 7 |
2 files changed, 12 insertions, 15 deletions
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 6be6307a0f1..0650f4af964 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -185,7 +185,7 @@ void ObjectMgr::LoadPlayerInfoInCache() QueryResult *result = CharacterDatabase.PQuery("SELECT guid, name, data, class FROM characters"); if(!result) { - sLog.outError( "ROGNAR LoadPlayerCache"); + sLog.outError( "Loading Player Cache failed."); return; } @@ -203,17 +203,17 @@ void ObjectMgr::LoadPlayerInfoInCache() tdata.clear(); tdata = StrSplit(fields[2].GetCppString(), " "); - - pPPlayerInfo->unLevel = (uint32)atoi(tdata[UNIT_FIELD_LEVEL].c_str()); - pPPlayerInfo->unfield = (uint32)atoi(tdata[UNIT_FIELD_BYTES_0].c_str()); - pPPlayerInfo->unArenaInfoId0 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (0 * 6)].c_str()); - pPPlayerInfo->unArenaInfoId1 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (1 * 6)].c_str()); - pPPlayerInfo->unArenaInfoId2 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (2 * 6)].c_str()); + pPPlayerInfo->unLevel = Player::GetUInt32ValueFromArray(tdata,UNIT_FIELD_LEVEL); + pPPlayerInfo->unfield = Player::GetUInt32ValueFromArray(tdata,UNIT_FIELD_BYTES_0); - pPPlayerInfo->unArenaInfoSlot0 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 0 * 6 + 5].c_str()); - pPPlayerInfo->unArenaInfoSlot1 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 1 * 6 + 5].c_str()); - pPPlayerInfo->unArenaInfoSlot2 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 2 * 6 + 5].c_str()); + pPPlayerInfo->unArenaInfoId0 = Player::GetUInt32ValueFromArray(tdata,PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 0 * 6); + pPPlayerInfo->unArenaInfoId1 = Player::GetUInt32ValueFromArray(tdata,PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 1 * 6); + pPPlayerInfo->unArenaInfoId2 = Player::GetUInt32ValueFromArray(tdata,PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 2 * 6); + + pPPlayerInfo->unArenaInfoSlot0 = Player::GetUInt32ValueFromArray(tdata,PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 0 * 6 + 5); + pPPlayerInfo->unArenaInfoSlot1 = Player::GetUInt32ValueFromArray(tdata,PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 1 * 6 + 5); + pPPlayerInfo->unArenaInfoSlot2 = Player::GetUInt32ValueFromArray(tdata,PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 2 * 6 + 5); pPPlayerInfo->unClass = (uint32)fields[3].GetUInt32(); m_mPlayerInfoMap[fields[0].GetUInt32()] = pPPlayerInfo; diff --git a/src/game/Player.cpp b/src/game/Player.cpp index c082e18a149..87ada7f8ab5 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -13626,11 +13626,8 @@ float Player::GetFloatValueFromArray(Tokens const& data, uint16 index) uint32 Player::GetUInt32ValueFromDB(uint16 index, uint64 guid) { - //rognar optimization - //must be improved!! "if" and "switch" - it's very not aesthetically :))) - //but we should know whith data is cached - //PLAYER_FIELD_ARENA_TEAM_INFO* very is often using with pvp&arena patch :) - if( index == PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 0 * 6 + 5 + // todo: cleanup in this, move to a separate function. + if( index == PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 0 * 6 + 5 || index == PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 1 * 6 + 5 || index == PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 2 * 6 + 5 || index == PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (0 * 6) |