Core/Dungeon Finder: Minor optimization in handler code

Note: LfgDungeonSet and LfgLockStatusMap were being used without using the existing typedef (to avoid including LFGMgr.h).
Now those functions use a struct as param that is forward declared so still LFGMgr.h is not needed and redefinition of LfgDungeonSet/LfgLockStatusMap is removed.

--HG--
branch : trunk
This commit is contained in:
Spp
2010-12-13 21:28:36 +01:00
parent 9815847511
commit 865f35a637
6 changed files with 182 additions and 122 deletions
+1
View File
@@ -32,6 +32,7 @@ enum LfgRoles
enum LfgUpdateType enum LfgUpdateType
{ {
LFG_UPDATETYPE_DEFAULT = 0, // Internal Use
LFG_UPDATETYPE_LEADER = 1, LFG_UPDATETYPE_LEADER = 1,
LFG_UPDATETYPE_ROLECHECK_ABORTED = 4, LFG_UPDATETYPE_ROLECHECK_ABORTED = 4,
LFG_UPDATETYPE_JOIN_PROPOSAL = 5, LFG_UPDATETYPE_JOIN_PROPOSAL = 5,
+85 -62
View File
@@ -205,6 +205,10 @@ void LFGMgr::Update(uint32 diff)
time_t currTime = time(NULL); time_t currTime = time(NULL);
// Remove obsolete role checks // Remove obsolete role checks
LfgJoinResultData joinData;
joinData.result = LFG_JOIN_FAILED;
joinData.state = LFG_ROLECHECK_MISSING_ROLE;
for (LfgRoleCheckMap::iterator it = m_RoleChecks.begin(); it != m_RoleChecks.end();) for (LfgRoleCheckMap::iterator it = m_RoleChecks.begin(); it != m_RoleChecks.end();)
{ {
LfgRoleCheckMap::iterator itRoleCheck = it++; LfgRoleCheckMap::iterator itRoleCheck = it++;
@@ -220,7 +224,7 @@ void LFGMgr::Update(uint32 diff)
plr->ClearLfgState(); plr->ClearLfgState();
if (itRoles->first == pRoleCheck->leader) if (itRoles->first == pRoleCheck->leader)
plr->GetSession()->SendLfgJoinResult(LFG_JOIN_FAILED, pRoleCheck->result); plr->GetSession()->SendLfgJoinResult(joinData);
} }
delete pRoleCheck; delete pRoleCheck;
m_RoleChecks.erase(itRoleCheck); m_RoleChecks.erase(itRoleCheck);
@@ -279,13 +283,14 @@ void LFGMgr::Update(uint32 diff)
if (Player* plr = sObjectMgr.GetPlayerByLowGUID(itPlayers->first)) if (Player* plr = sObjectMgr.GetPlayerByLowGUID(itPlayers->first))
{ {
plr->SetLfgState(LFG_STATE_PROPOSAL); plr->SetLfgState(LFG_STATE_PROPOSAL);
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_PROPOSAL_BEGIN, plr->GetLfgDungeons(), plr->GetLfgComment());
if (plr->GetGroup()) if (plr->GetGroup())
{ {
plr->GetGroup()->SetLfgState(LFG_STATE_PROPOSAL); plr->GetGroup()->SetLfgState(LFG_STATE_PROPOSAL);
plr->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_PROPOSAL_BEGIN, plr->GetLfgDungeons(), plr->GetLfgComment()); plr->GetSession()->SendLfgUpdateParty(updateData);
} }
else else
plr->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_PROPOSAL_BEGIN, plr->GetLfgDungeons(), plr->GetLfgComment()); plr->GetSession()->SendLfgUpdatePlayer(updateData);
plr->GetSession()->SendLfgUpdateProposal(m_lfgProposalId, pProposal); plr->GetSession()->SendLfgUpdateProposal(m_lfgProposalId, pProposal);
} }
} }
@@ -425,7 +430,7 @@ void LFGMgr::Join(Player* plr, uint8 roles, LfgDungeonSet& dungeons, std::string
Group* grp = plr->GetGroup(); Group* grp = plr->GetGroup();
uint64 guid = plr->GetGUID(); uint64 guid = plr->GetGUID();
uint64 gguid = grp ? grp->GetGUID() : guid; uint64 gguid = grp ? grp->GetGUID() : guid;
LfgJoinResult result = LFG_JOIN_OK; LfgJoinResultData joinData;
PlayerSet players; PlayerSet players;
uint32 rDungeonId = 0; uint32 rDungeonId = 0;
bool isContinue = grp && grp->isLFGGroup() && grp->GetLfgState() != LFG_STATE_FINISHED_DUNGEON; bool isContinue = grp && grp->isLFGGroup() && grp->GetLfgState() != LFG_STATE_FINISHED_DUNGEON;
@@ -448,12 +453,13 @@ void LFGMgr::Join(Player* plr, uint8 roles, LfgDungeonSet& dungeons, std::string
if (sameDungeons) // Joining the same dungeons -- Send OK if (sameDungeons) // Joining the same dungeons -- Send OK
{ {
plr->GetSession()->SendLfgJoinResult(LFG_JOIN_OK); plr->GetSession()->SendLfgJoinResult(joinData); // Default value of joinData.result = LFG_JOIN_OK
if (grp) if (grp)
{ {
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_ADDED_TO_QUEUE, &dungeons, comment);
for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
if (itr->getSource() && itr->getSource()->GetSession()) if (itr->getSource() && itr->getSource()->GetSession())
itr->getSource()->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_ADDED_TO_QUEUE, &dungeons, comment); itr->getSource()->GetSession()->SendLfgUpdateParty(updateData);
} }
} }
else if (!isContinue) // Different dungeons and it's not an offer to continue else if (!isContinue) // Different dungeons and it's not an offer to continue
@@ -467,36 +473,36 @@ void LFGMgr::Join(Player* plr, uint8 roles, LfgDungeonSet& dungeons, std::string
// Check player or group member restrictions // Check player or group member restrictions
if (plr->InBattleground() || plr->InArena() || plr->InBattlegroundQueue()) if (plr->InBattleground() || plr->InArena() || plr->InBattlegroundQueue())
result = LFG_JOIN_USING_BG_SYSTEM; joinData.result = LFG_JOIN_USING_BG_SYSTEM;
else if (plr->HasAura(LFG_SPELL_DUNGEON_DESERTER)) else if (plr->HasAura(LFG_SPELL_DUNGEON_DESERTER))
result = LFG_JOIN_DESERTER; joinData.result = LFG_JOIN_DESERTER;
else if (plr->HasAura(LFG_SPELL_DUNGEON_COOLDOWN)) else if (plr->HasAura(LFG_SPELL_DUNGEON_COOLDOWN))
result = LFG_JOIN_RANDOM_COOLDOWN; joinData.result = LFG_JOIN_RANDOM_COOLDOWN;
else if (!dungeons.size()) else if (!dungeons.size())
result = LFG_JOIN_NOT_MEET_REQS; joinData.result = LFG_JOIN_NOT_MEET_REQS;
else if (grp) else if (grp)
{ {
if (grp->GetMembersCount() > MAXGROUPSIZE) if (grp->GetMembersCount() > MAXGROUPSIZE)
result = LFG_JOIN_TOO_MUCH_MEMBERS; joinData.result = LFG_JOIN_TOO_MUCH_MEMBERS;
else else
{ {
uint8 memberCount = 0; uint8 memberCount = 0;
for (GroupReference* itr = grp->GetFirstMember(); itr != NULL && result == LFG_JOIN_OK; itr = itr->next()) for (GroupReference* itr = grp->GetFirstMember(); itr != NULL && joinData.result == LFG_JOIN_OK; itr = itr->next())
{ {
if (Player* plrg = itr->getSource()) if (Player* plrg = itr->getSource())
{ {
if (plrg->HasAura(LFG_SPELL_DUNGEON_DESERTER)) if (plrg->HasAura(LFG_SPELL_DUNGEON_DESERTER))
result = LFG_JOIN_PARTY_DESERTER; joinData.result = LFG_JOIN_PARTY_DESERTER;
else if (plrg->HasAura(LFG_SPELL_DUNGEON_COOLDOWN)) else if (plrg->HasAura(LFG_SPELL_DUNGEON_COOLDOWN))
result = LFG_JOIN_PARTY_RANDOM_COOLDOWN; joinData.result = LFG_JOIN_PARTY_RANDOM_COOLDOWN;
else if (plrg->InBattleground() || plrg->InArena() || plrg->InBattlegroundQueue()) else if (plrg->InBattleground() || plrg->InArena() || plrg->InBattlegroundQueue())
result = LFG_JOIN_USING_BG_SYSTEM; joinData.result = LFG_JOIN_USING_BG_SYSTEM;
++memberCount; ++memberCount;
players.insert(plrg); players.insert(plrg);
} }
} }
if (memberCount != grp->GetMembersCount()) if (memberCount != grp->GetMembersCount())
result = LFG_JOIN_DISCONNECTED; joinData.result = LFG_JOIN_DISCONNECTED;
} }
} }
else else
@@ -504,32 +510,32 @@ void LFGMgr::Join(Player* plr, uint8 roles, LfgDungeonSet& dungeons, std::string
// Check if all dungeons are valid // Check if all dungeons are valid
bool isRaid = false; bool isRaid = false;
if (result == LFG_JOIN_OK) if (joinData.result == LFG_JOIN_OK)
{ {
bool isDungeon = false; bool isDungeon = false;
for (LfgDungeonSet::const_iterator it = dungeons.begin(); it != dungeons.end() && result == LFG_JOIN_OK; ++it) for (LfgDungeonSet::const_iterator it = dungeons.begin(); it != dungeons.end() && joinData.result == LFG_JOIN_OK; ++it)
{ {
switch(GetDungeonType(*it)) switch(GetDungeonType(*it))
{ {
case LFG_TYPE_RANDOM: case LFG_TYPE_RANDOM:
if (dungeons.size() > 1) // Only allow 1 random dungeon if (dungeons.size() > 1) // Only allow 1 random dungeon
result = LFG_JOIN_DUNGEON_INVALID; joinData.result = LFG_JOIN_DUNGEON_INVALID;
else else
rDungeonId = (*dungeons.begin()); rDungeonId = (*dungeons.begin());
// No break on purpose (Random can only be dungeon or heroic dungeon) // No break on purpose (Random can only be dungeon or heroic dungeon)
case LFG_TYPE_HEROIC: case LFG_TYPE_HEROIC:
case LFG_TYPE_DUNGEON: case LFG_TYPE_DUNGEON:
if (isRaid) if (isRaid)
result = LFG_JOIN_MIXED_RAID_DUNGEON; joinData.result = LFG_JOIN_MIXED_RAID_DUNGEON;
isDungeon = true; isDungeon = true;
break; break;
case LFG_TYPE_RAID: case LFG_TYPE_RAID:
if (isDungeon) if (isDungeon)
result = LFG_JOIN_MIXED_RAID_DUNGEON; joinData.result = LFG_JOIN_MIXED_RAID_DUNGEON;
isRaid = true; isRaid = true;
break; break;
default: default:
result = LFG_JOIN_DUNGEON_INVALID; joinData.result = LFG_JOIN_DUNGEON_INVALID;
break; break;
} }
} }
@@ -538,27 +544,28 @@ void LFGMgr::Join(Player* plr, uint8 roles, LfgDungeonSet& dungeons, std::string
if (rDungeonId) if (rDungeonId)
dungeons = GetDungeonsByRandom(rDungeonId); dungeons = GetDungeonsByRandom(rDungeonId);
LfgLockStatusMap* lockStatusMap = CheckCompatibleDungeons(dungeons, players); joinData.lockmap = CheckCompatibleDungeons(dungeons, players);
if (!dungeons.size()) if (!dungeons.size())
{ {
joinData.result = LFG_JOIN_PARTY_NOT_MEET_REQS;
sLog.outDebug("LFGMgr::Join: [" UI64FMTD "] joining with %u members. result: LFG_JOIN_PARTY_NOT_MEET_REQS", guid, uint8(players.size())); sLog.outDebug("LFGMgr::Join: [" UI64FMTD "] joining with %u members. result: LFG_JOIN_PARTY_NOT_MEET_REQS", guid, uint8(players.size()));
plr->GetSession()->SendLfgJoinResult(LFG_JOIN_PARTY_NOT_MEET_REQS, 0, lockStatusMap); plr->GetSession()->SendLfgJoinResult(joinData);
} }
if (lockStatusMap) if (joinData.lockmap)
{ {
for (LfgLockStatusMap::iterator it = lockStatusMap->begin(); it != lockStatusMap->end(); ++it) for (LfgLockStatusMap::iterator it = joinData.lockmap->begin(); it != joinData.lockmap->end(); ++it)
delete it->second; delete it->second;
delete lockStatusMap; delete joinData.lockmap;
} }
if (!dungeons.size()) if (!dungeons.size())
return; return;
} }
// Can't join. Send result // Can't join. Send result
if (result != LFG_JOIN_OK) if (joinData.result != LFG_JOIN_OK)
{ {
sLog.outDebug("LFGMgr::Join: [" UI64FMTD "] joining with %u members. result: %u", guid, grp ? grp->GetMembersCount() : 1, result); sLog.outDebug("LFGMgr::Join: [" UI64FMTD "] joining with %u members. result: %u", guid, grp ? grp->GetMembersCount() : 1, joinData.result);
plr->GetSession()->SendLfgJoinResult(result); plr->GetSession()->SendLfgJoinResult(joinData);
return; return;
} }
@@ -591,11 +598,12 @@ void LFGMgr::Join(Player* plr, uint8 roles, LfgDungeonSet& dungeons, std::string
grp->SetLfgState(LFG_STATE_ROLECHECK); grp->SetLfgState(LFG_STATE_ROLECHECK);
// Send update to player // Send update to player
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_JOIN_PROPOSAL, &dungeons, comment);
for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
{ {
if (Player* plrg = itr->getSource()) if (Player* plrg = itr->getSource())
{ {
plrg->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_JOIN_PROPOSAL, &dungeons, comment); plrg->GetSession()->SendLfgUpdateParty(updateData);
plrg->SetLfgState(LFG_STATE_ROLECHECK); plrg->SetLfgState(LFG_STATE_ROLECHECK);
if (!isContinue) if (!isContinue)
{ {
@@ -612,8 +620,9 @@ void LFGMgr::Join(Player* plr, uint8 roles, LfgDungeonSet& dungeons, std::string
else // Add player to queue else // Add player to queue
{ {
// Send update to player // Send update to player
plr->GetSession()->SendLfgJoinResult(LFG_JOIN_OK); LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_JOIN_PROPOSAL, &dungeons, comment);
plr->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_JOIN_PROPOSAL, &dungeons, comment); plr->GetSession()->SendLfgJoinResult(joinData);
plr->GetSession()->SendLfgUpdatePlayer(updateData);
plr->SetLfgState(LFG_STATE_QUEUED); plr->SetLfgState(LFG_STATE_QUEUED);
if (!isContinue) if (!isContinue)
{ {
@@ -674,21 +683,24 @@ void LFGMgr::Leave(Player* plr, Group* grp /* = NULL*/)
switch(state) switch(state)
{ {
case LFG_STATE_QUEUED: case LFG_STATE_QUEUED:
RemoveFromQueue(guid);
if (grp)
{ {
grp->RestoreLfgState(); RemoveFromQueue(guid);
for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_REMOVED_FROM_QUEUE);
if (Player* plrg = itr->getSource()) if (grp)
{ {
plrg->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_REMOVED_FROM_QUEUE); grp->RestoreLfgState();
plrg->ClearLfgState(); for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
} if (Player* plrg = itr->getSource())
} {
else plrg->GetSession()->SendLfgUpdateParty(updateData);
{ plrg->ClearLfgState();
plr->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_REMOVED_FROM_QUEUE); }
plr->ClearLfgState(); }
else
{
plr->GetSession()->SendLfgUpdatePlayer(updateData);
plr->ClearLfgState();
}
} }
break; break;
case LFG_STATE_ROLECHECK: case LFG_STATE_ROLECHECK:
@@ -1031,6 +1043,9 @@ void LFGMgr::UpdateRoleCheck(Group* grp, Player* plr /* = NULL*/, bool newRoleCh
else else
dungeons = pRoleCheck->dungeons; dungeons = pRoleCheck->dungeons;
LfgJoinResultData joinData;
joinData.result = LFG_JOIN_FAILED;
joinData.state = pRoleCheck->result;
for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
{ {
Player* plrg = itr->getSource(); Player* plrg = itr->getSource();
@@ -1048,14 +1063,20 @@ void LFGMgr::UpdateRoleCheck(Group* grp, Player* plr /* = NULL*/, bool newRoleCh
case LFG_ROLECHECK_INITIALITING: case LFG_ROLECHECK_INITIALITING:
continue; continue;
case LFG_ROLECHECK_FINISHED: case LFG_ROLECHECK_FINISHED:
plrg->SetLfgState(LFG_STATE_QUEUED); {
session->SendLfgUpdateParty(LFG_UPDATETYPE_ADDED_TO_QUEUE, &dungeons, plrg->GetLfgComment()); plrg->SetLfgState(LFG_STATE_QUEUED);
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_ADDED_TO_QUEUE, &dungeons, plrg->GetLfgComment());
session->SendLfgUpdateParty(updateData);
}
break; break;
default: default:
if (grp->GetLeaderGUID() == plrg->GetGUID()) {
session->SendLfgJoinResult(LFG_JOIN_FAILED, pRoleCheck->result); if (grp->GetLeaderGUID() == plrg->GetGUID())
session->SendLfgUpdateParty(LFG_UPDATETYPE_ROLECHECK_FAILED); session->SendLfgJoinResult(joinData);
plrg->ClearLfgState(); LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_ROLECHECK_FAILED);
session->SendLfgUpdateParty(updateData);
plrg->ClearLfgState();
}
break; break;
} }
} }
@@ -1334,6 +1355,7 @@ void LFGMgr::UpdateProposal(uint32 proposalId, uint32 lowGuid, bool accept)
} }
// Create a new group (if needed) // Create a new group (if needed)
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_GROUP_FOUND);
Group* grp = pProposal->groupLowGuid ? sObjectMgr.GetGroupByGUID(pProposal->groupLowGuid) : NULL; Group* grp = pProposal->groupLowGuid ? sObjectMgr.GetGroupByGUID(pProposal->groupLowGuid) : NULL;
for (LfgPlayerList::const_iterator it = players.begin(); it != players.end(); ++it) for (LfgPlayerList::const_iterator it = players.begin(); it != players.end(); ++it)
{ {
@@ -1343,12 +1365,12 @@ void LFGMgr::UpdateProposal(uint32 proposalId, uint32 lowGuid, bool accept)
plr->GetSession()->SendLfgUpdateProposal(proposalId, pProposal); plr->GetSession()->SendLfgUpdateProposal(proposalId, pProposal);
if (group) if (group)
{ {
plr->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_GROUP_FOUND); plr->GetSession()->SendLfgUpdateParty(updateData);
if (group != grp) if (group != grp)
plr->RemoveFromGroup(); plr->RemoveFromGroup();
} }
else else
plr->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_GROUP_FOUND); plr->GetSession()->SendLfgUpdatePlayer(updateData);
if (!grp) if (!grp)
{ {
@@ -1460,37 +1482,38 @@ void LFGMgr::RemoveProposal(LfgProposalMap::iterator itProposal, LfgUpdateType t
if (toRemove.find(gguid) != toRemove.end()) // Didn't accept or in same group that someone that didn't accept if (toRemove.find(gguid) != toRemove.end()) // Didn't accept or in same group that someone that didn't accept
{ {
LfgUpdateType updateType; LfgUpdateData updateData;
if (it->second->accept == LFG_ANSWER_DENY) if (it->second->accept == LFG_ANSWER_DENY)
{ {
updateType = type; updateData.updateType = type;
sLog.outDebug("LFGMgr::RemoveProposal: [" UI64FMTD "] didn't accept. Removing from queue and compatible cache", guid); sLog.outDebug("LFGMgr::RemoveProposal: [" UI64FMTD "] didn't accept. Removing from queue and compatible cache", guid);
} }
else else
{ {
updateType = LFG_UPDATETYPE_REMOVED_FROM_QUEUE; updateData.updateType = LFG_UPDATETYPE_REMOVED_FROM_QUEUE;
sLog.outDebug("LFGMgr::RemoveProposal: [" UI64FMTD "] in same group that someone that didn't accept. Removing from queue and compatible cache", guid); sLog.outDebug("LFGMgr::RemoveProposal: [" UI64FMTD "] in same group that someone that didn't accept. Removing from queue and compatible cache", guid);
} }
plr->ClearLfgState(); plr->ClearLfgState();
if (grp) if (grp)
{ {
grp->RestoreLfgState(); grp->RestoreLfgState();
plr->GetSession()->SendLfgUpdateParty(updateType); plr->GetSession()->SendLfgUpdateParty(updateData);
} }
else else
plr->GetSession()->SendLfgUpdatePlayer(updateType); plr->GetSession()->SendLfgUpdatePlayer(updateData);
} }
else else
{ {
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_ADDED_TO_QUEUE, plr->GetLfgDungeons(), plr->GetLfgComment());
sLog.outDebug("LFGMgr::RemoveProposal: Readding [" UI64FMTD "] to queue.", guid); sLog.outDebug("LFGMgr::RemoveProposal: Readding [" UI64FMTD "] to queue.", guid);
plr->SetLfgState(LFG_STATE_QUEUED); plr->SetLfgState(LFG_STATE_QUEUED);
if (grp) if (grp)
{ {
grp->SetLfgState(LFG_STATE_QUEUED); grp->SetLfgState(LFG_STATE_QUEUED);
plr->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_ADDED_TO_QUEUE, plr->GetLfgDungeons(), plr->GetLfgComment()); plr->GetSession()->SendLfgUpdateParty(updateData);
} }
else else
plr->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_ADDED_TO_QUEUE, plr->GetLfgDungeons(), plr->GetLfgComment()); plr->GetSession()->SendLfgUpdatePlayer(updateData);
} }
} }
+21
View File
@@ -113,6 +113,7 @@ enum LfgJoinResult
/// Role check states /// Role check states
enum LfgRoleCheckState enum LfgRoleCheckState
{ {
LFG_ROLECHECK_DEFAULT = 0, // Internal use = Not initialized.
LFG_ROLECHECK_FINISHED = 1, // Role check finished LFG_ROLECHECK_FINISHED = 1, // Role check finished
LFG_ROLECHECK_INITIALITING = 2, // Role check begins LFG_ROLECHECK_INITIALITING = 2, // Role check begins
LFG_ROLECHECK_MISSING_ROLE = 3, // Someone didn't selected a role after 2 mins LFG_ROLECHECK_MISSING_ROLE = 3, // Someone didn't selected a role after 2 mins
@@ -165,6 +166,26 @@ struct LfgLockStatus
LfgLockStatusType lockstatus; ///< Lock type LfgLockStatusType lockstatus; ///< Lock type
}; };
// Data needed by SMSG_LFG_JOIN_RESULT
struct LfgJoinResultData
{
LfgJoinResultData(): result(LFG_JOIN_OK), state(LFG_ROLECHECK_DEFAULT), lockmap(NULL) {}
LfgJoinResult result;
LfgRoleCheckState state;
LfgLockStatusMap* lockmap;
};
// Data needed by SMSG_LFG_UPDATE_PARTY and SMSG_LFG_UPDATE_PLAYER
struct LfgUpdateData
{
LfgUpdateData(LfgUpdateType _type = LFG_UPDATETYPE_DEFAULT, LfgDungeonSet* _dungeons = NULL, std::string _comment = ""):
updateType(_type), dungeons(_dungeons), comment(_comment) {}
LfgUpdateType updateType;
LfgDungeonSet* dungeons;
std::string comment;
};
/// Reward info /// Reward info
struct LfgReward struct LfgReward
{ {
+17 -8
View File
@@ -36,12 +36,13 @@ void LFGScripts::OnAddMember(Group* group, uint64 guid)
return; return;
sLog.outDebug("LFGScripts::OnAddMember [" UI64FMTD "]: added [" UI64FMTD "]", gguid, guid); sLog.outDebug("LFGScripts::OnAddMember [" UI64FMTD "]: added [" UI64FMTD "]", gguid, guid);
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_CLEAR_LOCK_LIST);
for (GroupReference *itr = group->GetFirstMember(); itr != NULL; itr = itr->next()) for (GroupReference *itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
{ {
if (Player *plrg = itr->getSource()) if (Player *plrg = itr->getSource())
{ {
plrg->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_CLEAR_LOCK_LIST); plrg->GetSession()->SendLfgUpdatePlayer(updateData);
plrg->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_CLEAR_LOCK_LIST); plrg->GetSession()->SendLfgUpdateParty(updateData);
} }
} }
@@ -90,7 +91,8 @@ void LFGScripts::OnRemoveMember(Group* group, uint64 guid, RemoveMethod& method,
*/ */
plr->ClearLfgState(); plr->ClearLfgState();
plr->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_LEADER); LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_LEADER);
plr->GetSession()->SendLfgUpdateParty(updateData);
if (plr->GetMap()->IsDungeon()) // Teleport player out the dungeon if (plr->GetMap()->IsDungeon()) // Teleport player out the dungeon
sLFGMgr.TeleportPlayer(plr, true); sLFGMgr.TeleportPlayer(plr, true);
} }
@@ -111,12 +113,18 @@ void LFGScripts::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLe
sLog.outDebug("LFGScripts::OnChangeLeader [" UI64FMTD "]: old [" UI64FMTD "] new [" UI64FMTD "]", gguid, newLeaderGuid, oldLeaderGuid); sLog.outDebug("LFGScripts::OnChangeLeader [" UI64FMTD "]: old [" UI64FMTD "] new [" UI64FMTD "]", gguid, newLeaderGuid, oldLeaderGuid);
Player *plr = sObjectMgr.GetPlayer(newLeaderGuid); Player *plr = sObjectMgr.GetPlayer(newLeaderGuid);
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_LEADER);
if (plr) if (plr)
plr->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_LEADER); plr->GetSession()->SendLfgUpdateParty(updateData);
plr = sObjectMgr.GetPlayer(oldLeaderGuid); plr = sObjectMgr.GetPlayer(oldLeaderGuid);
if (plr) if (plr)
plr->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_GROUP_DISBAND); {
updateData.updateType = LFG_UPDATETYPE_GROUP_DISBAND;
plr->GetSession()->SendLfgUpdateParty(updateData);
}
} }
void LFGScripts::OnInviteMember(Group* group, uint64 guid) void LFGScripts::OnInviteMember(Group* group, uint64 guid)
@@ -137,12 +145,13 @@ void LFGScripts::OnLevelChanged(Player* /*player*/, uint8 /*newLevel*/)
void LFGScripts::OnLogout(Player* player) void LFGScripts::OnLogout(Player* player)
{ {
sLFGMgr.Leave(player); sLFGMgr.Leave(player);
player->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_REMOVED_FROM_QUEUE); LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_REMOVED_FROM_QUEUE);
player->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_REMOVED_FROM_QUEUE); player->GetSession()->SendLfgUpdateParty(updateData);
player->GetSession()->SendLfgUpdatePlayer(updateData);
player->GetSession()->SendLfgUpdateSearch(false); player->GetSession()->SendLfgUpdateSearch(false);
} }
void LFGScripts::OnLogin(Player* /*player*/) void LFGScripts::OnLogin(Player* /*player*/)
{ {
// TODO - Restore LfgPlayerData and send proper status to player if it was in a group // TODO - Restore LfgPlayerData and send proper status to player if it was in a group
} }
@@ -281,30 +281,32 @@ void WorldSession::HandleLfrLeaveOpcode(WorldPacket &recv_data)
//sLFGMgr.LeaveLfr(GetPlayer(), dungeonId); //sLFGMgr.LeaveLfr(GetPlayer(), dungeonId);
} }
void WorldSession::SendLfgUpdatePlayer(uint8 updateType, LfgDungeonSet* dungeons /* = NULL */, std::string comment /* = "" */) void WorldSession::SendLfgUpdatePlayer(LfgUpdateData& updateData)
{ {
bool queued = false; bool queued = false;
bool extrainfo = false; bool extrainfo = false;
switch(updateType) switch(updateData.updateType)
{ {
case LFG_UPDATETYPE_JOIN_PROPOSAL: case LFG_UPDATETYPE_JOIN_PROPOSAL:
case LFG_UPDATETYPE_ADDED_TO_QUEUE: case LFG_UPDATETYPE_ADDED_TO_QUEUE:
queued = true; queued = true;
extrainfo = true; extrainfo = true;
break; break;
//case LFG_UPDATETYPE_CLEAR_LOCK_LIST: // TODO: Sometimes has extrainfo - Check ocurrences... //case LFG_UPDATETYPE_CLEAR_LOCK_LIST: // TODO: Sometimes has extrainfo - Check ocurrences...
case LFG_UPDATETYPE_PROPOSAL_BEGIN: case LFG_UPDATETYPE_PROPOSAL_BEGIN:
extrainfo = true; extrainfo = true;
break; break;
default:
break;
} }
uint64 guid = GetPlayer()->GetGUID(); uint64 guid = GetPlayer()->GetGUID();
uint8 size = dungeons ? dungeons->size() : 0; uint8 size = updateData.dungeons ? updateData.dungeons->size() : 0;
sLog.outDebug("SMSG_LFG_UPDATE_PLAYER [" UI64FMTD "] updatetype: %u", guid, updateType); sLog.outDebug("SMSG_LFG_UPDATE_PLAYER [" UI64FMTD "] updatetype: %u", guid, updateData.updateType);
WorldPacket data(SMSG_LFG_UPDATE_PLAYER, 1 + 1 + (extrainfo ? 1 : 0) * (1 + 1 + 1 + 1 + size * 4 + comment.length())); WorldPacket data(SMSG_LFG_UPDATE_PLAYER, 1 + 1 + (extrainfo ? 1 : 0) * (1 + 1 + 1 + 1 + size * 4 + updateData.comment.length()));
data << uint8(updateType); // Lfg Update type data << uint8(updateData.updateType); // Lfg Update type
data << uint8(extrainfo); // Extra info data << uint8(extrainfo); // Extra info
if (extrainfo) if (extrainfo)
{ {
@@ -314,45 +316,47 @@ void WorldSession::SendLfgUpdatePlayer(uint8 updateType, LfgDungeonSet* dungeons
data << uint8(size); data << uint8(size);
if (size) if (size)
for (LfgDungeonSet::const_iterator it = dungeons->begin(); it != dungeons->end(); ++it) for (LfgDungeonSet::const_iterator it = updateData.dungeons->begin(); it != updateData.dungeons->end(); ++it)
data << uint32(*it); data << uint32(*it);
data << comment; data << updateData.comment;
} }
SendPacket(&data); SendPacket(&data);
} }
void WorldSession::SendLfgUpdateParty(uint8 updateType, LfgDungeonSet* dungeons /* = NULL */, std::string comment /* = "" */) void WorldSession::SendLfgUpdateParty(LfgUpdateData& updateData)
{ {
bool join = false; bool join = false;
bool extrainfo = false; bool extrainfo = false;
bool queued = false; bool queued = false;
switch(updateType) switch(updateData.updateType)
{ {
case LFG_UPDATETYPE_JOIN_PROPOSAL: case LFG_UPDATETYPE_JOIN_PROPOSAL:
extrainfo = true; extrainfo = true;
break; break;
case LFG_UPDATETYPE_ADDED_TO_QUEUE: case LFG_UPDATETYPE_ADDED_TO_QUEUE:
extrainfo = true; extrainfo = true;
join = true; join = true;
queued = true; queued = true;
break; break;
case LFG_UPDATETYPE_CLEAR_LOCK_LIST: case LFG_UPDATETYPE_CLEAR_LOCK_LIST:
// join = true; // TODO: Sometimes queued and extrainfo - Check ocurrences... // join = true; // TODO: Sometimes queued and extrainfo - Check ocurrences...
queued = true; queued = true;
break; break;
case LFG_UPDATETYPE_PROPOSAL_BEGIN: case LFG_UPDATETYPE_PROPOSAL_BEGIN:
extrainfo = true; extrainfo = true;
join = true; join = true;
break; break;
default:
break;
} }
uint64 guid = GetPlayer()->GetGUID(); uint64 guid = GetPlayer()->GetGUID();
uint8 size = dungeons ? dungeons->size() : 0; uint8 size = updateData.dungeons ? updateData.dungeons->size() : 0;
sLog.outDebug("SMSG_LFG_UPDATE_PARTY [" UI64FMTD "] updatetype: %u", guid, updateType); sLog.outDebug("SMSG_LFG_UPDATE_PARTY [" UI64FMTD "] updatetype: %u", guid, updateData.updateType);
WorldPacket data(SMSG_LFG_UPDATE_PARTY, 1 + 1 + (extrainfo ? 1 : 0) * (1 + 1 + 1 + 1 + 1 + size * 4 + comment.length())); WorldPacket data(SMSG_LFG_UPDATE_PARTY, 1 + 1 + (extrainfo ? 1 : 0) * (1 + 1 + 1 + 1 + 1 + size * 4 + updateData.comment.length()));
data << uint8(updateType); // Lfg Update type data << uint8(updateData.updateType); // Lfg Update type
data << uint8(extrainfo); // Extra info data << uint8(extrainfo); // Extra info
if (extrainfo) if (extrainfo)
{ {
@@ -365,9 +369,9 @@ void WorldSession::SendLfgUpdateParty(uint8 updateType, LfgDungeonSet* dungeons
data << uint8(size); data << uint8(size);
if (size) if (size)
for (LfgDungeonSet::const_iterator it = dungeons->begin(); it != dungeons->end(); ++it) for (LfgDungeonSet::const_iterator it = updateData.dungeons->begin(); it != updateData.dungeons->end(); ++it)
data << uint32(*it); data << uint32(*it);
data << comment; data << updateData.comment;
} }
SendPacket(&data); SendPacket(&data);
} }
@@ -439,20 +443,21 @@ void WorldSession::SendLfgRoleCheckUpdate(LfgRoleCheck* pRoleCheck)
SendPacket(&data); SendPacket(&data);
} }
void WorldSession::SendLfgJoinResult(uint8 checkResult, uint8 checkValue /* = 0 */, LfgLockStatusMap* playersLockMap /* = NULL */) void WorldSession::SendLfgJoinResult(LfgJoinResultData& joinData)
{ {
uint32 size = 0; uint32 size = 0;
if (playersLockMap) if (joinData.lockmap)
{ {
for (LfgLockStatusMap::const_iterator it = playersLockMap->begin(); it != playersLockMap->end(); ++it) for (LfgLockStatusMap::const_iterator it = joinData.lockmap->begin(); it != joinData.lockmap->end(); ++it)
size += 8 + 4 + it->second->size() * (4 + 4); size += 8 + 4 + it->second->size() * (4 + 4);
} }
sLog.outDebug("SMSG_LFG_ROLE_CHOSEN [" UI64FMTD "] checkResult: %u checkValue: %u", GetPlayer()->GetGUID(), checkResult, checkValue); sLog.outDebug("SMSG_LFG_JOIN_RESULT [" UI64FMTD "] checkResult: %u checkValue: %u", GetPlayer()->GetGUID(), joinData.result, joinData.state);
WorldPacket data(SMSG_LFG_JOIN_RESULT, 4 + 4 + size); WorldPacket data(SMSG_LFG_JOIN_RESULT, 4 + 4 + size);
data << uint32(checkResult); // Check Result data << uint32(joinData.result); // Check Result
data << uint32(checkValue); // Check Value data << uint32(joinData.state); // Check Value
BuildPartyLockDungeonBlock(data, playersLockMap); if (joinData.lockmap)
BuildPartyLockDungeonBlock(data, joinData.lockmap);
SendPacket(&data); SendPacket(&data);
} }
+5 -4
View File
@@ -48,12 +48,13 @@ class CharacterHandler;
class SpellCastTargets; class SpellCastTargets;
struct AreaTableEntry; struct AreaTableEntry;
struct GM_Ticket; struct GM_Ticket;
struct LfgJoinResultData;
struct LfgLockStatus; struct LfgLockStatus;
struct LfgPlayerBoot; struct LfgPlayerBoot;
struct LfgProposal; struct LfgProposal;
struct LfgReward; struct LfgReward;
struct LfgRoleCheck; struct LfgRoleCheck;
struct LfgUpdateData;
enum AccountDataType enum AccountDataType
{ {
@@ -730,12 +731,12 @@ class WorldSession
void HandleLfrSearchOpcode(WorldPacket &recv_data); void HandleLfrSearchOpcode(WorldPacket &recv_data);
void HandleLfrLeaveOpcode(WorldPacket &recv_data); void HandleLfrLeaveOpcode(WorldPacket &recv_data);
void SendLfgUpdatePlayer(uint8 updateType, std::set<uint32>* dungeons = NULL, std::string comment = ""); void SendLfgUpdatePlayer(LfgUpdateData& updateData);
void SendLfgUpdateParty(uint8 updateType, std::set<uint32>* dungeons = NULL, std::string comment = ""); void SendLfgUpdateParty(LfgUpdateData& updateData);
void SendLfgRoleChosen(uint64 guid, uint8 roles); void SendLfgRoleChosen(uint64 guid, uint8 roles);
void SendLfgRoleCheckUpdate(LfgRoleCheck *pRoleCheck); void SendLfgRoleCheckUpdate(LfgRoleCheck *pRoleCheck);
void SendLfgUpdateSearch(bool update); void SendLfgUpdateSearch(bool update);
void SendLfgJoinResult(uint8 checkResult, uint8 checkValue = 0, std::map<uint32, std::set<LfgLockStatus*>*> *playersLockMap = NULL); void SendLfgJoinResult(LfgJoinResultData& joinData);
void SendLfgQueueStatus(uint32 dungeon, int32 waitTime, int32 avgWaitTime, int32 waitTimeTanks, int32 waitTimeHealer, int32 waitTimeDps, uint32 queuedTime, uint8 tanks, uint8 healers, uint8 dps); void SendLfgQueueStatus(uint32 dungeon, int32 waitTime, int32 avgWaitTime, int32 waitTimeTanks, int32 waitTimeHealer, int32 waitTimeDps, uint32 queuedTime, uint8 tanks, uint8 healers, uint8 dps);
void SendLfgPlayerReward(uint32 rdungeonEntry, uint32 sdungeonEntry, uint8 done, const LfgReward *reward, const Quest *qRew); void SendLfgPlayerReward(uint32 rdungeonEntry, uint32 sdungeonEntry, uint8 done, const LfgReward *reward, const Quest *qRew);
void SendLfgBootPlayer(LfgPlayerBoot *pBoot); void SendLfgBootPlayer(LfgPlayerBoot *pBoot);