TrinityCore
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WhoListStorage.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "WhoListStorage.h"
19#include "World.h"
20#include "ObjectAccessor.h"
21#include "Player.h"
22#include "GuildMgr.h"
23#include "WorldSession.h"
24
26{
28 return &instance;
29}
30
32{
33 // clear current list
34 _whoListStorage.clear();
35 _whoListStorage.reserve(sWorld->GetPlayerCount()+1);
36
38 for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
39 {
40 if (!itr->second->FindMap() || itr->second->GetSession()->PlayerLoading())
41 continue;
42
43 std::string playerName = itr->second->GetName();
44 std::wstring widePlayerName;
45 if (!Utf8toWStr(playerName, widePlayerName))
46 continue;
47
48 wstrToLower(widePlayerName);
49
50 std::string guildName = sGuildMgr->GetGuildNameById(itr->second->GetGuildId());
51 std::wstring wideGuildName;
52 if (!Utf8toWStr(guildName, wideGuildName))
53 continue;
54
55 wstrToLower(wideGuildName);
56
57 _whoListStorage.emplace_back(itr->second->GetGUID(), itr->second->GetTeam(), itr->second->GetSession()->GetSecurity(), itr->second->GetLevel(),
58 itr->second->GetClass(), itr->second->GetRace(), itr->second->GetZoneId(), itr->second->GetNativeGender(), itr->second->IsVisible(),
59 widePlayerName, wideGuildName, playerName, guildName);
60 }
61}
#define sGuildMgr
Definition: GuildMgr.h:59
void wstrToLower(std::wstring &str)
Definition: Util.cpp:480
bool Utf8toWStr(char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
Definition: Util.cpp:383
std::unordered_map< ObjectGuid, T * > MapType
WhoListInfoVector _whoListStorage
static WhoListStorageMgr * instance()
#define sWorld
Definition: World.h:893
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()