aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpp <none@none>2010-09-27 23:19:22 +0200
committerSpp <none@none>2010-09-27 23:19:22 +0200
commit1afdd143d91b45a5b54cbae86463e9cd526e0814 (patch)
treeea5331487bb49e9ded6218a4af7343a82db546e6
parent781592d63a393084500f2d668936e31ef120eae2 (diff)
Core/Dungeon Finder: Fix bad use of iterator that made LFG inconsistent and sometimes crash
Closes issue 4009 --HG-- branch : trunk
-rw-r--r--src/server/game/DungeonFinding/LFGMgr.cpp42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/server/game/DungeonFinding/LFGMgr.cpp b/src/server/game/DungeonFinding/LFGMgr.cpp
index 02202db658b..939a48b1dc1 100644
--- a/src/server/game/DungeonFinding/LFGMgr.cpp
+++ b/src/server/game/DungeonFinding/LFGMgr.cpp
@@ -468,32 +468,24 @@ void LFGMgr::Update(uint32 diff)
void LFGMgr::AddGuidToNewQueue(uint64 guid)
{
// Consistency check
- LfgGuidList::const_iterator it;
- for (it = m_newToQueue.begin(); it != m_newToQueue.end(); ++it)
+ LfgGuidList::iterator it = std::find(m_newToQueue.begin(), m_newToQueue.end(), guid);
+
+ if (it != m_newToQueue.end())
{
- if (*it == guid)
- {
- sLog.outError("LFGMgr::AddGuidToNewQueue: [" UI64FMTD "] being added to queue and it was already added. ignoring", guid);
- break;
- }
+ sLog.outError("LFGMgr::AddGuidToNewQueue: [" UI64FMTD "] being added to queue and it was already added. ignoring", guid);
+ return;
}
- if (it == m_newToQueue.end())
+
+ it = std::find(m_currentQueue.begin(), m_currentQueue.end(), guid);
+ if (it != m_currentQueue.end())
{
- LfgGuidList::iterator itRemove;
- for (LfgGuidList::iterator it = m_currentQueue.begin(); it != m_currentQueue.end() && (*it) != guid;)
- {
- itRemove = it++;
- if (*itRemove == guid)
- {
- sLog.outError("LFGMgr::AddGuidToNewQueue: [" UI64FMTD "] being added to queue and already in current queue (removing to readd)", guid);
- m_currentQueue.erase(itRemove);
- break;
- }
- }
- // Add to queue
- m_newToQueue.push_back(guid);
- sLog.outError("DEBUG:LFGMgr::AddGuidToNewQueue: [" UI64FMTD "] added to m_newToQueue (size: %u)", guid, m_newToQueue.size());
+ sLog.outError("LFGMgr::AddGuidToNewQueue: [" UI64FMTD "] being added to queue and already in current queue (removing to readd)", guid);
+ m_currentQueue.erase(it);
}
+
+ // Add to queue
+ m_newToQueue.push_back(guid);
+ sLog.outError("DEBUG:LFGMgr::AddGuidToNewQueue: [" UI64FMTD "] added to m_newToQueue (size: %u)", guid, m_newToQueue.size());
}
/// <summary>
@@ -726,8 +718,8 @@ void LFGMgr::Leave(Player* plr, Group* grp /* = NULL*/)
// Remove from Proposals
bool proposalFound = false;
- LfgProposalMap::iterator it;
- for (it = m_Proposals.begin(); it != m_Proposals.end() && !proposalFound; ++it)
+ LfgProposalMap::iterator it = m_Proposals.begin();
+ while (it != m_Proposals.end() && !proposalFound)
{
// Mark the player/leader of group who left as didn't accept the proposal
for (LfgProposalPlayerMap::iterator itPlayer = it->second->players.begin(); itPlayer != it->second->players.end(); ++itPlayer)
@@ -738,6 +730,8 @@ void LFGMgr::Leave(Player* plr, Group* grp /* = NULL*/)
proposalFound = true;
}
}
+ if (!proposalFound)
+ ++it;
}
// Remove from queue - if proposal is found, RemoveProposal will call RemoveFromQueue