[11920] Fix possible crash when trying to add playerto group who is not in world

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
cyberium 2012-02-07 11:41:36 +01:00 committed by Schmoozerd
parent 6c8000705f
commit b984d3f787
5 changed files with 25 additions and 18 deletions

View file

@ -1161,14 +1161,20 @@ bool Group::_addMember(ObjectGuid guid, const char* name, bool isAssistant, uint
if (!guid)
return false;
Player *player = sObjectMgr.GetPlayer(guid);
Player* player = sObjectMgr.GetPlayer(guid, false);
uint32 lastMap = 0;
if (player && player->IsInWorld())
player->GetMapId();
else if (player && player->IsBeingTeleported())
player->GetTeleportDest().mapid;
MemberSlot member;
member.guid = guid;
member.name = name;
member.group = group;
member.assistant = isAssistant;
member.lastMap = player->GetMapId();
member.lastMap = lastMap;
m_memberSlots.push_back(member);
SubGroupCounterIncrease(group);
@ -1186,11 +1192,14 @@ bool Group::_addMember(ObjectGuid guid, const char* name, bool isAssistant, uint
else
player->SetGroup(this, group);
if (player->IsInWorld())
{
// if the same group invites the player back, cancel the homebind timer
if (InstanceGroupBind* bind = GetBoundInstance(player->GetMapId(), player))
if (bind->state->GetInstanceId() == player->GetInstanceId())
player->m_InstanceValid = true;
}
}
if (!isRaidGroup()) // reset targetIcons for non-raid-groups
{

View file

@ -73,21 +73,19 @@ Corpse* ObjectAccessor::GetCorpseInMap(ObjectGuid guid, uint32 mapid)
return ret;
}
Player*
ObjectAccessor::FindPlayer(ObjectGuid guid)
Player* ObjectAccessor::FindPlayer(ObjectGuid guid, bool inWorld /*= true*/)
{
if (!guid)
return NULL;
Player* plr = HashMapHolder<Player>::Find(guid);;
if (!plr || !plr->IsInWorld())
if (!plr || (!plr->IsInWorld() && inWorld))
return NULL;
return plr;
}
Player*
ObjectAccessor::FindPlayerByName(const char *name)
Player* ObjectAccessor::FindPlayerByName(const char *name)
{
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock());
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();

View file

@ -100,7 +100,7 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor,
static Unit* GetUnit(WorldObject const& obj, ObjectGuid guid);
// Player access
static Player* FindPlayer(ObjectGuid guid); // if need player at specific map better use Map::GetPlayer
static Player* FindPlayer(ObjectGuid guid, bool inWorld = true);// if need player at specific map better use Map::GetPlayer
static Player* FindPlayerByName(const char *name);
static void KickPlayer(ObjectGuid guid);

View file

@ -472,7 +472,7 @@ class ObjectMgr
typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
static Player* GetPlayer(const char* name) { return ObjectAccessor::FindPlayerByName(name);}
static Player* GetPlayer(ObjectGuid guid) { return ObjectAccessor::FindPlayer(guid); }
static Player* GetPlayer(ObjectGuid guid, bool inWorld = true) { return ObjectAccessor::FindPlayer(guid, inWorld); }
static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11919"
#define REVISION_NR "11920"
#endif // __REVISION_NR_H__