| 181 | } |
| 182 | |
| 183 | void ObjectMgr::LoadPlayerInfoInCache() |
| 184 | { |
| 185 | QueryResult *result = CharacterDatabase.PQuery("SELECT guid, name, data, class FROM characters"); |
| 186 | if(!result) |
| 187 | { |
| 188 | sLog.outError( "ROGNAR LoadPlayerCache"); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | PCachePlayerInfo pPPlayerInfo = NULL; |
| 193 | Field *fields = NULL; |
| 194 | Tokens tdata; |
| 195 | barGoLink bar( result->GetRowCount() ); |
| 196 | do |
| 197 | { |
| 198 | bar.step(); |
| 199 | fields = result->Fetch(); |
| 200 | pPPlayerInfo = new CachePlayerInfo(); |
| 201 | |
| 202 | pPPlayerInfo->sPlayerName = fields[1].GetString(); |
| 203 | |
| 204 | tdata.clear(); |
| 205 | tdata = StrSplit(fields[2].GetCppString(), " "); |
| 206 | |
| 207 | pPPlayerInfo->unLevel = (uint32)atoi(tdata[UNIT_FIELD_LEVEL].c_str()); |
| 208 | pPPlayerInfo->unfield = (uint32)atoi(tdata[UNIT_FIELD_BYTES_0].c_str()); |
| 209 | |
| 210 | pPPlayerInfo->unArenaInfoId0 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (0 * 6)].c_str()); |
| 211 | pPPlayerInfo->unArenaInfoId1 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (1 * 6)].c_str()); |
| 212 | pPPlayerInfo->unArenaInfoId2 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (2 * 6)].c_str()); |
| 213 | |
| 214 | pPPlayerInfo->unArenaInfoSlot0 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 0 * 6 + 5].c_str()); |
| 215 | pPPlayerInfo->unArenaInfoSlot1 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 1 * 6 + 5].c_str()); |
| 216 | pPPlayerInfo->unArenaInfoSlot2 = (uint32)atoi(tdata[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 2 * 6 + 5].c_str()); |
| 217 | |
| 218 | pPPlayerInfo->unClass = (uint32)fields[3].GetUInt32(); |
| 219 | m_mPlayerInfoMap[fields[0].GetUInt32()] = pPPlayerInfo; |
| 220 | } |
| 221 | while (result->NextRow()); |
| 222 | delete result; |
| 223 | |
| 224 | sLog.outString(); |
| 225 | sLog.outString( ">> Loaded info about %d players", m_mPlayerInfoMap.size()); |
| 226 | } |
| 227 | |
| 228 | PCachePlayerInfo ObjectMgr::GetPlayerInfoFromCache(uint32 unPlayerGuid) const |
| 229 | { |
| 230 | //Now m_mPlayerInfoMap is using only for search, but when dinamic inserting/removing |
| 231 | //will be implemented we should lock it to prevent simultaneous access. |
| 232 | //Inserting - when new created player is saving |
| 233 | //Removing - when player has been deleted |
| 234 | CachePlayerInfoMap::const_iterator ipos = m_mPlayerInfoMap.find(unPlayerGuid); |
| 235 | return ipos == m_mPlayerInfoMap.end() ? NULL : ipos->second; |