[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

@ -310,7 +310,7 @@ bool Group::AddMember(ObjectGuid guid, const char* name)
SendUpdate(); SendUpdate();
if (Player *player = sObjectMgr.GetPlayer(guid)) if (Player* player = sObjectMgr.GetPlayer(guid))
{ {
if (!IsLeader(player->GetObjectGuid()) && !isBGGroup()) if (!IsLeader(player->GetObjectGuid()) && !isBGGroup())
{ {
@ -1155,20 +1155,26 @@ bool Group::_addMember(ObjectGuid guid, const char* name, bool isAssistant)
bool Group::_addMember(ObjectGuid guid, const char* name, bool isAssistant, uint8 group) bool Group::_addMember(ObjectGuid guid, const char* name, bool isAssistant, uint8 group)
{ {
if(IsFull()) if (IsFull())
return false; return false;
if (!guid) if (!guid)
return false; 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; MemberSlot member;
member.guid = guid; member.guid = guid;
member.name = name; member.name = name;
member.group = group; member.group = group;
member.assistant = isAssistant; member.assistant = isAssistant;
member.lastMap = player->GetMapId(); member.lastMap = lastMap;
m_memberSlots.push_back(member); m_memberSlots.push_back(member);
SubGroupCounterIncrease(group); SubGroupCounterIncrease(group);
@ -1180,16 +1186,19 @@ bool Group::_addMember(ObjectGuid guid, const char* name, bool isAssistant, uint
if (player->GetGroup() && isBGGroup()) if (player->GetGroup() && isBGGroup())
player->SetBattleGroundRaid(this, group); player->SetBattleGroundRaid(this, group);
//if player is in bg raid and we are adding him to normal group, then call SetOriginalGroup() //if player is in bg raid and we are adding him to normal group, then call SetOriginalGroup()
else if ( player->GetGroup() ) else if (player->GetGroup())
player->SetOriginalGroup(this, group); player->SetOriginalGroup(this, group);
//if player is not in group, then call set group //if player is not in group, then call set group
else else
player->SetGroup(this, group); player->SetGroup(this, group);
// if the same group invites the player back, cancel the homebind timer if (player->IsInWorld())
if (InstanceGroupBind *bind = GetBoundInstance(player->GetMapId(), player)) {
if (bind->state->GetInstanceId() == player->GetInstanceId()) // if the same group invites the player back, cancel the homebind timer
player->m_InstanceValid = true; 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 if (!isRaidGroup()) // reset targetIcons for non-raid-groups

View file

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

View file

@ -472,7 +472,7 @@ class ObjectMgr
typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap; typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
static Player* GetPlayer(const char* name) { return ObjectAccessor::FindPlayerByName(name);} 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); } static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }

View file

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