More lock fixes. Also fix the .character level command
This commit is contained in:
parent
dbc21ed903
commit
b026642ce2
@ -171,7 +171,7 @@ bool ChatHandler::HandleGMListIngameCommand(char* /*args*/)
|
||||
std::list< std::pair<std::string, bool> > names;
|
||||
|
||||
{
|
||||
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock());
|
||||
ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, g, HashMapHolder<Player>::GetLock(), true)
|
||||
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
{
|
||||
|
@ -93,14 +93,11 @@ Player* ObjectAccessor::FindPlayer(ObjectGuid guid, bool inWorld /*= true*/)
|
||||
|
||||
Player* ObjectAccessor::FindPlayerByName(const char* name)
|
||||
{
|
||||
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock(), true);
|
||||
if (g.locked())
|
||||
{
|
||||
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
if (iter->second->IsInWorld() && (::strcmp(name, iter->second->GetName()) == 0))
|
||||
{ return iter->second; }
|
||||
}
|
||||
ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, guard, HashMapHolder<Player>::GetLock(), NULL)
|
||||
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
|
||||
for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
if (iter->second->IsInWorld() && (::strcmp(name, iter->second->GetName()) == 0))
|
||||
{ return iter->second; }
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -131,16 +128,15 @@ void ObjectAccessor::KickPlayer(ObjectGuid guid)
|
||||
Corpse*
|
||||
ObjectAccessor::GetCorpseForPlayerGUID(ObjectGuid guid)
|
||||
{
|
||||
ACE_Guard<LockType> guard(i_corpseGuard, true);
|
||||
if (guard.locked())
|
||||
{
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
|
||||
if (iter == i_player2corpse.end())
|
||||
{ return NULL; }
|
||||
MANGOS_ASSERT(iter->second->GetType() != CORPSE_BONES);
|
||||
return iter->second;
|
||||
}
|
||||
return NULL;
|
||||
ACE_GUARD_RETURN(LockType, guard, i_corpseGuard, NULL)
|
||||
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
|
||||
|
||||
if (iter == i_player2corpse.end())
|
||||
{ return NULL; }
|
||||
|
||||
MANGOS_ASSERT(iter->second->GetType() != CORPSE_BONES);
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
void
|
||||
@ -148,22 +144,20 @@ ObjectAccessor::RemoveCorpse(Corpse* corpse)
|
||||
{
|
||||
MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
|
||||
|
||||
ACE_Guard<LockType> guard(i_corpseGuard, true);
|
||||
if (guard.locked())
|
||||
{
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGuid());
|
||||
if (iter == i_player2corpse.end())
|
||||
{ return; }
|
||||
ACE_GUARD(LockType, guard, i_corpseGuard)
|
||||
|
||||
// build mapid*cellid -> guid_set map
|
||||
CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGuid());
|
||||
if (iter == i_player2corpse.end())
|
||||
{ return; }
|
||||
|
||||
sObjectMgr.DeleteCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter());
|
||||
corpse->RemoveFromWorld();
|
||||
// build mapid*cellid -> guid_set map
|
||||
CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
|
||||
|
||||
i_player2corpse.erase(iter);
|
||||
}
|
||||
sObjectMgr.DeleteCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter());
|
||||
corpse->RemoveFromWorld();
|
||||
|
||||
i_player2corpse.erase(iter);
|
||||
}
|
||||
|
||||
void
|
||||
@ -171,43 +165,39 @@ ObjectAccessor::AddCorpse(Corpse* corpse)
|
||||
{
|
||||
MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
|
||||
|
||||
ACE_Guard<LockType> guard(i_corpseGuard, true);
|
||||
if (guard.locked())
|
||||
{
|
||||
MANGOS_ASSERT(i_player2corpse.find(corpse->GetOwnerGuid()) == i_player2corpse.end());
|
||||
i_player2corpse[corpse->GetOwnerGuid()] = corpse;
|
||||
ACE_GUARD(LockType, guard, i_corpseGuard)
|
||||
|
||||
// build mapid*cellid -> guid_set map
|
||||
CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
|
||||
MANGOS_ASSERT(i_player2corpse.find(corpse->GetOwnerGuid()) == i_player2corpse.end());
|
||||
i_player2corpse[corpse->GetOwnerGuid()] = corpse;
|
||||
|
||||
sObjectMgr.AddCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter(), corpse->GetInstanceId());
|
||||
}
|
||||
// build mapid*cellid -> guid_set map
|
||||
CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
|
||||
|
||||
sObjectMgr.AddCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter(), corpse->GetInstanceId());
|
||||
}
|
||||
|
||||
void
|
||||
ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map)
|
||||
{
|
||||
ACE_Guard<LockType> guard(i_corpseGuard, true);
|
||||
if (guard.locked())
|
||||
{
|
||||
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
|
||||
if (iter->second->GetGrid() == gridpair)
|
||||
ACE_GUARD(LockType, guard, i_corpseGuard)
|
||||
|
||||
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
|
||||
if (iter->second->GetGrid() == gridpair)
|
||||
{
|
||||
// verify, if the corpse in our instance (add only corpses which are)
|
||||
if (map->Instanceable())
|
||||
{
|
||||
// verify, if the corpse in our instance (add only corpses which are)
|
||||
if (map->Instanceable())
|
||||
{
|
||||
if (iter->second->GetInstanceId() == map->GetInstanceId())
|
||||
{
|
||||
grid.AddWorldObject(iter->second);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (iter->second->GetInstanceId() == map->GetInstanceId())
|
||||
{
|
||||
grid.AddWorldObject(iter->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grid.AddWorldObject(iter->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Corpse*
|
||||
|
@ -54,33 +54,24 @@ class HashMapHolder
|
||||
|
||||
typedef UNORDERED_MAP<ObjectGuid, T*> MapType;
|
||||
typedef ACE_RW_Thread_Mutex LockType;
|
||||
typedef ACE_Read_Guard<LockType> ReadGuard;
|
||||
typedef ACE_Write_Guard<LockType> WriteGuard;
|
||||
|
||||
static void Insert(T* o)
|
||||
{
|
||||
WriteGuard guard(i_lock, true);
|
||||
if (guard.locked())
|
||||
m_objectMap[o->GetObjectGuid()] = o;
|
||||
ACE_WRITE_GUARD(LockType, guard, i_lock)
|
||||
m_objectMap[o->GetObjectGuid()] = o;
|
||||
}
|
||||
|
||||
static void Remove(T* o)
|
||||
{
|
||||
WriteGuard guard(i_lock, true);
|
||||
if (guard.locked())
|
||||
m_objectMap.erase(o->GetObjectGuid());
|
||||
ACE_WRITE_GUARD(LockType, guard, i_lock)
|
||||
m_objectMap.erase(o->GetObjectGuid());
|
||||
}
|
||||
|
||||
static T* Find(ObjectGuid guid)
|
||||
{
|
||||
ReadGuard guard(i_lock, true);
|
||||
if (guard.locked())
|
||||
{
|
||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
||||
return (itr != m_objectMap.end()) ? itr->second : NULL;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
ACE_READ_GUARD_RETURN (LockType, guard, i_lock, NULL)
|
||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
||||
return (itr != m_objectMap.end()) ? itr->second : NULL;
|
||||
}
|
||||
|
||||
static MapType& GetContainer() { return m_objectMap; }
|
||||
|
@ -18960,6 +18960,9 @@ void Player::_LoadSkills(QueryResult* result)
|
||||
case SKILL_RANGE_MONO: // 1..1, grey monolite bar
|
||||
value = max = 1;
|
||||
break;
|
||||
case SKILL_RANGE_LEVEL:
|
||||
max = GetMaxSkillValueForLevel(); // max value can be wrong for the actual level
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user