TrinityCore
Loading...
Searching...
No Matches
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
28
34
36{
37 // clear current list
38 _whoListStorage.clear();
39 _whoListStorage.reserve(sWorld->GetPlayerCount()+1);
40
42 for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
43 {
44 if (!itr->second->FindMap() || itr->second->GetSession()->PlayerLoading())
45 continue;
46
47 std::string playerName = itr->second->GetName();
48 std::wstring widePlayerName;
49 if (!Utf8toWStr(playerName, widePlayerName))
50 continue;
51
52 wstrToLower(widePlayerName);
53
54 std::string guildName = sGuildMgr->GetGuildNameById(itr->second->GetGuildId());
55 std::wstring wideGuildName;
56 if (!Utf8toWStr(guildName, wideGuildName))
57 continue;
58
59 wstrToLower(wideGuildName);
60
61 Guild* guild = itr->second->GetGuild();
62 ObjectGuid guildGuid;
63
64 if (guild)
65 guildGuid = guild->GetGUID();
66
67 _whoListStorage.emplace_back(itr->second->GetGUID(), itr->second->GetTeam(), itr->second->GetSession()->GetSecurity(), itr->second->GetLevel(),
68 itr->second->GetClass(), itr->second->GetRace(), itr->second->GetZoneId(), itr->second->GetNativeGender(), itr->second->IsVisible(),
69 itr->second->IsGameMaster(), widePlayerName, wideGuildName, playerName, guildName, guildGuid);
70 }
71}
#define sGuildMgr
Definition GuildMgr.h:76
void wstrToLower(std::wstring &str)
Definition Util.cpp:433
bool Utf8toWStr(char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
Definition Util.cpp:336
Definition Guild.h:329
ObjectGuid GetGUID() const
Definition Guild.h:755
std::unordered_map< ObjectGuid, T * > MapType
WhoListInfoVector _whoListStorage
static WhoListStorageMgr * instance()
#define sWorld
Definition World.h:916
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()