Core/Command: Improve .group list to feature several notes and features to improve handling.

This commit is contained in:
Ascathor committed 2013-10-17 14:58:37 +02:00
1 parent a0b3863bd1
commit 193f4ed868
2 files changed
+53 -3

No files matched your search

+49 -3
View File
@@ -260,24 +260,36 @@ public:
static bool HandleGroupListCommand(ChatHandler* handler, char const* args)
{
// Get ALL the variables!
Player* playerTarget;
uint32 phase = 0;
uint32 groupCounter = 0;
uint64 guidTarget;
std::string nameTarget;
std::string zoneName;
const char* onlineState = "";
// Parse the guid to uint32...
uint32 parseGUID = MAKE_NEW_GUID(atol((char*)args), 0, HIGHGUID_PLAYER);
// ... and try to extract a player out of it.
if (sObjectMgr->GetPlayerNameByGUID(parseGUID, nameTarget))
{
playerTarget = sObjectMgr->GetPlayerByLowGUID(parseGUID);
guidTarget = parseGUID;
}
// If not, we return false and end right away.
else if (!handler->extractPlayerTarget((char*)args, &playerTarget, &guidTarget, &nameTarget))
return false;
// Next, we need a group. So we define a group variable.
Group* groupTarget = NULL;
// We try to extract a group from an online player.
if (playerTarget)
groupTarget = playerTarget->GetGroup();
// If not, we extract it from the SQL.
if (!groupTarget)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GROUP_MEMBER);
@@ -287,6 +299,7 @@ public:
groupTarget = sGroupMgr->GetGroupByDbStoreId((*resultGroup)[0].GetUInt32());
}
// If both fails, players simply has no party. Return false.
if (!groupTarget)
{
handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, nameTarget.c_str());
@@ -294,12 +307,20 @@ public:
return false;
}
handler->PSendSysMessage(LANG_GROUP_TYPE, (groupTarget->isRaidGroup() ? "raid" : "party"));
// We get the group members after successfully detecting a group.
Group::MemberSlotList const& members = groupTarget->GetMemberSlots();
// To avoid a cluster fuck, namely trying multiple queries to simply get a group member count...
handler->PSendSysMessage(LANG_GROUP_TYPE, (groupTarget->isRaidGroup() ? "raid" : "party"), members.size());
// ... we simply move the group type and member count print after retrieving the slots and simply output it's size.
// While rather dirty codestyle-wise, it saves space (if only a little). For each member, we look several informations up.
for (Group::MemberSlotList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
// Define temporary variable slot to iterator.
Group::MemberSlot const& slot = *itr;
// Check for given flag and assign it to that iterator
std::string flags;
if (slot.flags & MEMBER_FLAG_ASSISTANT)
flags = "Assistant";
@@ -321,13 +342,38 @@ public:
if (flags.empty())
flags = "None";
// Check if iterator is online. If is...
Player* p = ObjectAccessor::FindPlayer((*itr).guid);
const char* onlineState = (p && p->IsInWorld()) ? "online" : "offline";
if (p && p->IsInWorld())
{
// ... than, it prints information like "is online", where he is, etc...
onlineState = "online";
phase = (!p->IsGameMaster() ? p->GetPhaseMask() : -1);
uint32 locale = handler->GetSessionDbcLocale();
AreaTableEntry const* area = GetAreaEntryByAreaID(p->GetAreaId());
if (area)
{
AreaTableEntry const* zone = GetAreaEntryByAreaID(area->zone);
if (zone)
zoneName = zone->area_name[locale];
}
}
else
{
// ... else, everything is set to offline or neutral values.
zoneName = "<ERROR>";
onlineState = "Offline";
phase = 0;
}
// Now we can print those informations for every single member of each group!
handler->PSendSysMessage(LANG_GROUP_PLAYER_NAME_GUID, slot.name.c_str(), onlineState,
GUID_LOPART(slot.guid), flags.c_str(), lfg::GetRolesString(slot.roles).c_str());
zoneName.c_str(), phase, GUID_LOPART(slot.guid), flags.c_str(),
lfg::GetRolesString(slot.roles).c_str());
}
// And finish after every iterator is done.
return true;
}
};