TrinityCore
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#include "Guild.h"
25
27{
29 return &instance;
30}
31
33{
34 // clear current list
35 _whoListStorage.clear();
36 _whoListStorage.reserve(sWorld->GetPlayerCount()+1);
37
39 for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
40 {
41 if (!itr->second->FindMap() || itr->second->GetSession()->PlayerLoading())
42 continue;
43
44 std::string playerName = itr->second->GetName();
45 std::wstring widePlayerName;
46 if (!Utf8toWStr(playerName, widePlayerName))
47 continue;
48
49 wstrToLower(widePlayerName);
50
51 std::string guildName = sGuildMgr->GetGuildNameById(itr->second->GetGuildId());
52 std::wstring wideGuildName;
53 if (!Utf8toWStr(guildName, wideGuildName))
54 continue;
55
56 wstrToLower(wideGuildName);
57
58 Guild* guild = itr->second->GetGuild();
59 ObjectGuid guildGuid;
60
61 if (guild)
62 guildGuid = guild->GetGUID();
63
64 _whoListStorage.emplace_back(itr->second->GetGUID(), itr->second->GetTeam(), itr->second->GetSession()->GetSecurity(), itr->second->GetLevel(),
65 itr->second->GetClass(), itr->second->GetRace(), itr->second->GetZoneId(), itr->second->GetNativeGender(), itr->second->IsVisible(),
66 itr->second->IsGameMaster(), widePlayerName, wideGuildName, playerName, guildName, guildGuid);
67 }
68}
#define sGuildMgr
Definition: GuildMgr.h:70
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
Definition: Guild.h:329
ObjectGuid GetGUID() const
Definition: Guild.h:753
std::unordered_map< ObjectGuid, T * > MapType
WhoListInfoVector _whoListStorage
static WhoListStorageMgr * instance()
#define sWorld
Definition: World.h:931
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()