Skip to content

Commit

Permalink
Core/Game/MiscHandler : Fixed Who List. @TrinityCore 2009.
Browse files Browse the repository at this point in the history
  • Loading branch information
callmephil committed Feb 29, 2016
1 parent cdcf716 commit ed6b7fd
Showing 1 changed file with 159 additions and 147 deletions.
306 changes: 159 additions & 147 deletions src/server/game/Handlers/MiscHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,193 +170,205 @@ void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket & recv_data)
}
}

void WorldSession::HandleWhoOpcode(WorldPacket & recv_data)
{
;//sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Recvd CMSG_WHO Message");

time_t now = time(NULL);
if (now < timeWhoCommandAllowed)
return;
timeWhoCommandAllowed = now+3;

uint32 matchcount = 0;

uint32 level_min, level_max, racemask, classmask, zones_count, str_count;
uint32 zoneids[10]; // 10 is client limit
std::string player_name, guild_name;

recv_data >> level_min; // maximal player level, default 0
recv_data >> level_max; // minimal player level, default 100 (MAX_LEVEL)
recv_data >> player_name; // player name, case sensitive...

recv_data >> guild_name; // guild name, case sensitive...
void WorldSession::HandleWhoOpcode(WorldPacket& recvData)
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Recvd CMSG_WHO Message");

recv_data >> racemask; // race mask
recv_data >> classmask; // class mask
recv_data >> zones_count; // zones count, client limit = 10 (2.0.10)
time_t now = time(NULL);
if (now < timeWhoCommandAllowed)
return;
timeWhoCommandAllowed = now + 3;

if (zones_count > 10)
return; // can't be received from real client or broken packet
uint32 matchcount = 0;

for (uint32 i = 0; i < zones_count; ++i)
{
uint32 temp;
recv_data >> temp; // zone id, 0 if zone is unknown...
zoneids[i] = temp;
;//sLog->outDebug(LOG_FILTER_NETWORKIO, "Zone %u: %u", i, zoneids[i]);
}
uint32 level_min, level_max, racemask, classmask, zones_count, str_count;
uint32 zoneids[10]; // 10 is client limit
std::string player_name, guild_name;

recv_data >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10)
recvData >> level_min; // maximal player level, default 0
recvData >> level_max; // minimal player level, default 100 (MAX_LEVEL)
recvData >> player_name; // player name, case sensitive...

if (str_count > 4)
return; // can't be received from real client or broken packet
recvData >> guild_name; // guild name, case sensitive...

;//sLog->outDebug(LOG_FILTER_NETWORKIO, "Minlvl %u, maxlvl %u, name %s, guild %s, racemask %u, classmask %u, zones %u, strings %u", level_min, level_max, player_name.c_str(), guild_name.c_str(), racemask, classmask, zones_count, str_count);
recvData >> racemask; // race mask
recvData >> classmask; // class mask
recvData >> zones_count; // zones count, client limit = 10 (2.0.10)

std::wstring str[4]; // 4 is client limit
for (uint32 i = 0; i < str_count; ++i)
{
std::string temp;
recv_data >> temp; // user entered string, it used as universal search pattern(guild+player name)?
if (zones_count > 10)
return; // can't be received from real client or broken packet

if (!Utf8toWStr(temp, str[i]))
continue;
for (uint32 i = 0; i < zones_count; ++i)
{
uint32 temp;
recvData >> temp; // zone id, 0 if zone is unknown...
zoneids[i] = temp;
sLog->outDebug(LOG_FILTER_NETWORKIO, "Zone %u: %u", i, zoneids[i]);
}

wstrToLower(str[i]);
recvData >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10)

;//sLog->outDebug(LOG_FILTER_NETWORKIO, "String %u: %s", i, temp.c_str());
}
if (str_count > 4)
return; // can't be received from real client or broken packet

std::wstring wplayer_name;
std::wstring wguild_name;
if (!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name)))
return;
wstrToLower(wplayer_name);
wstrToLower(wguild_name);
sLog->outDebug(LOG_FILTER_NETWORKIO, "Minlvl %u, maxlvl %u, name %s, guild %s, racemask %u, classmask %u, zones %u, strings %u", level_min, level_max, player_name.c_str(), guild_name.c_str(), racemask, classmask, zones_count, str_count);

// client send in case not set max level value 100 but Trinity supports 255 max level,
// update it to show GMs with characters after 100 level
if (level_max >= MAX_LEVEL)
level_max = STRONG_MAX_LEVEL;
std::wstring str[4]; // 4 is client limit
for (uint32 i = 0; i < str_count; ++i)
{
std::string temp;
recvData >> temp; // user entered string, it used as universal search pattern(guild+player name)?

TeamId teamId = _player->GetTeamId();
uint32 security = GetSecurity();
uint32 gmLevelInWhoList = sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_WHO_LIST);
uint32 displaycount = 0;
if (!Utf8toWStr(temp, str[i]))
continue;

WorldPacket data(SMSG_WHO, 500); // guess size
data << uint32(matchcount); // placeholder, count of players matching criteria
data << uint32(displaycount); // placeholder, count of players displayed
wstrToLower(str[i]);

std::vector<WhoListPlayerInfo> * m = WhoListCacheMgr::GetWhoList();
for (std::vector<WhoListPlayerInfo>::const_iterator itr = m->begin(); itr != m->end(); ++itr)
{
if (AccountMgr::IsPlayerAccount(security))
{
if ((*itr).teamId != teamId)
continue;
sLog->outDebug(LOG_FILTER_NETWORKIO, "String %u: %s", i, temp.c_str());
}

// player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
//if ((*itr).security > AccountTypes(gmLevelInWhoList))
// continue;
}
std::wstring wplayer_name;
std::wstring wguild_name;
if (!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name)))
return;
wstrToLower(wplayer_name);
wstrToLower(wguild_name);

// client send in case not set max level value 100 but Trinity supports 255 max level,
// update it to show GMs with characters after 100 level
if (level_max >= MAX_LEVEL)
level_max = STRONG_MAX_LEVEL;

uint32 team = _player->GetTeamId();
uint32 security = GetSecurity();
//bool allowTwoSideWhoList = sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST);
uint32 gmLevelInWhoList = sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_WHO_LIST);
uint32 displaycount = 0;

WorldPacket data(SMSG_WHO, 50); // guess size
data << uint32(matchcount); // placeholder, count of players matching criteria
data << uint32(displaycount); // placeholder, count of players displayed

TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
if (AccountMgr::IsPlayerAccount(security))
{
// player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
if (itr->second->GetTeamId() != team /* && !allowTwoSideWhoList*/)
continue;

//do not process players which are not in world
//if (!(itr->second->IsInWorld()))
// continue;
// player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
if ((itr->second->GetSession()->GetSecurity() > AccountTypes(gmLevelInWhoList)))
continue;
}

// check if target is globally visible for player
//if (!(itr->second->IsVisibleGloballyFor(_player)))
// continue;
//do not process players which are not in world
if (!(itr->second->IsInWorld()))
continue;

// check if target's level is in level range
uint8 lvl = (*itr).level;
if (lvl < level_min || lvl > level_max)
continue;
// check if target is globally visible for player
if (!(itr->second->IsVisibleGloballyFor(_player)))
continue;

// check if class matches classmask
uint32 class_ = (*itr).clas;
if (!(classmask & (1 << class_)))
continue;
// check if target's level is in level range
uint8 lvl = itr->second->getLevel();
if (lvl < level_min || lvl > level_max)
continue;

// check if race matches racemask
uint32 race = (*itr).race;
if (!(racemask & (1 << race)))
continue;
// check if class matches classmask
uint32 class_ = itr->second->getClass();
if (!(classmask & (1 << class_)))
continue;

uint32 pzoneid = (*itr).zoneid;
uint8 gender = (*itr).gender;
// check if race matches racemask
uint32 race = itr->second->getRace();
if (!(racemask & (1 << race)))
continue;

bool z_show = true;
for (uint32 i = 0; i < zones_count; ++i)
{
if (zoneids[i] == pzoneid)
{
z_show = true;
break;
}
uint32 pzoneid = itr->second->GetZoneId();
uint8 gender = itr->second->getGender();

z_show = false;
}
if (!z_show)
continue;
bool z_show = true;
for (uint32 i = 0; i < zones_count; ++i)
{
if (zoneids[i] == pzoneid)
{
z_show = true;
break;
}

std::wstring wpname = (*itr).wpname;
z_show = false;
}
if (!z_show)
continue;

if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
continue;
std::string pname = itr->second->GetName();
std::wstring wpname;
if (!Utf8toWStr(pname, wpname))
continue;
wstrToLower(wpname);

std::wstring wgname = (*itr).wgname;
if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
continue;

if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
continue;
std::string gname = sGuildMgr->GetGuildNameById(itr->second->GetGuildId());
std::wstring wgname;
if (!Utf8toWStr(gname, wgname))
continue;
wstrToLower(wgname);

std::string aname = (*itr).aname;
if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
continue;

bool s_show = true;
for (uint32 i = 0; i < str_count; ++i)
{
if (!str[i].empty())
{
if (wgname.find(str[i]) != std::wstring::npos ||
wpname.find(str[i]) != std::wstring::npos ||
Utf8FitTo(aname, str[i]))
{
s_show = true;
break;
}
s_show = false;
}
}
if (!s_show)
continue;
std::string aname;
if (AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(itr->second->GetZoneId()))
aname = areaEntry->area_name[GetSessionDbcLocale()];

// 50 is maximum player count sent to client
if (matchcount >= 50)
bool s_show = true;
for (uint32 i = 0; i < str_count; ++i)
{
++matchcount;
continue;
if (!str[i].empty())
{
if (wgname.find(str[i]) != std::wstring::npos ||
wpname.find(str[i]) != std::wstring::npos ||
Utf8FitTo(aname, str[i]))
{
s_show = true;
break;
}
s_show = false;
}
}
if (!s_show)
continue;

data << (*itr).pname; // player name
data << (*itr).gname; // guild name
data << uint32(lvl); // player level
data << uint32(class_); // player class
data << uint32(race); // player race
data << uint8(gender); // player gender
data << uint32(pzoneid); // player zone id
// 49 is maximum player count sent to client - can be overridden
// through config, but is unstable
if ((matchcount++) >= 50 /*sWorld->getIntConfig(CONFIG_MAX_WHO)*/)
continue;

++matchcount;
++displaycount;
}
data << pname; // player name
data << gname; // guild name
data << uint32(lvl); // player level
data << uint32(class_); // player class
data << uint32(race); // player race
data << uint8(gender); // player gender
data << uint32(pzoneid); // player zone id

data.put(0, displaycount); // insert right count, count displayed
data.put(4, matchcount); // insert right count, count of matches
++displaycount;
}

SendPacket(&data);
;//sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Send SMSG_WHO Message");
data.put(0, displaycount); // insert right count, count displayed
data.put(4, matchcount); // insert right count, count of matches

SendPacket(&data);
;// sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Send SMSG_WHO Message");
}


void WorldSession::HandleLogoutRequestOpcode(WorldPacket & /*recv_data*/)
{
;//sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity());
Expand Down

0 comments on commit ed6b7fd

Please sign in to comment.