Core/LFGScript: Split LFG script class to prevent crash caused by deallocating the same memory twice

This commit is contained in:
Shauren
2012-03-24 17:53:33 +01:00
parent 47a597d406
commit 64701c51dc
2 changed files with 57 additions and 45 deletions

View File

@@ -27,9 +27,45 @@
#include "LFGScripts.h"
#include "LFGMgr.h"
LFGScripts::LFGScripts(): GroupScript("LFGScripts"), PlayerScript("LFGScripts") {}
LFGPlayerScript::LFGPlayerScript() : PlayerScript("LFGPlayerScript")
{
}
void LFGScripts::OnAddMember(Group* group, uint64 guid)
void LFGPlayerScript::OnLevelChanged(Player* player, uint8 /*oldLevel*/)
{
sLFGMgr->InitializeLockedDungeons(player);
}
void LFGPlayerScript::OnLogout(Player* player)
{
sLFGMgr->Leave(player);
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_REMOVED_FROM_QUEUE);
player->GetSession()->SendLfgUpdateParty(updateData);
player->GetSession()->SendLfgUpdatePlayer(updateData);
player->GetSession()->SendLfgUpdateSearch(false);
uint64 guid = player->GetGUID();
// TODO - Do not remove, add timer before deleting
sLFGMgr->RemovePlayerData(guid);
}
void LFGPlayerScript::OnLogin(Player* player)
{
sLFGMgr->InitializeLockedDungeons(player);
// TODO - Restore LfgPlayerData and send proper status to player if it was in a group
}
void LFGPlayerScript::OnBindToInstance(Player* player, Difficulty difficulty, uint32 mapId, bool /*permanent*/)
{
MapEntry const* mapEntry = sMapStore.LookupEntry(mapId);
if (mapEntry->IsDungeon() && difficulty > DUNGEON_DIFFICULTY_NORMAL)
sLFGMgr->InitializeLockedDungeons(player);
}
LFGGroupScript::LFGGroupScript() : GroupScript("LFGGroupScript")
{
}
void LFGGroupScript::OnAddMember(Group* group, uint64 guid)
{
uint64 gguid = group->GetGUID();
if (!gguid)
@@ -55,7 +91,7 @@ void LFGScripts::OnAddMember(Group* group, uint64 guid)
sLFGMgr->Leave(player);
}
void LFGScripts::OnRemoveMember(Group* group, uint64 guid, RemoveMethod method, uint64 kicker, const char* reason)
void LFGGroupScript::OnRemoveMember(Group* group, uint64 guid, RemoveMethod method, uint64 kicker, char const* reason)
{
uint64 gguid = group->GetGUID();
if (!gguid || method == GROUP_REMOVEMETHOD_DEFAULT)
@@ -102,7 +138,7 @@ void LFGScripts::OnRemoveMember(Group* group, uint64 guid, RemoveMethod method,
sLFGMgr->OfferContinue(group);
}
void LFGScripts::OnDisband(Group* group)
void LFGGroupScript::OnDisband(Group* group)
{
uint64 gguid = group->GetGUID();
sLog->outDebug(LOG_FILTER_LFG, "LFGScripts::OnDisband [" UI64FMTD "]", gguid);
@@ -110,7 +146,7 @@ void LFGScripts::OnDisband(Group* group)
sLFGMgr->RemoveGroupData(gguid);
}
void LFGScripts::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid)
void LFGGroupScript::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid)
{
uint64 gguid = group->GetGUID();
if (!gguid)
@@ -131,7 +167,7 @@ void LFGScripts::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLe
}
}
void LFGScripts::OnInviteMember(Group* group, uint64 guid)
void LFGGroupScript::OnInviteMember(Group* group, uint64 guid)
{
uint64 gguid = group->GetGUID();
if (!gguid)
@@ -140,33 +176,3 @@ void LFGScripts::OnInviteMember(Group* group, uint64 guid)
sLog->outDebug(LOG_FILTER_LFG, "LFGScripts::OnInviteMember [" UI64FMTD "]: invite [" UI64FMTD "] leader [" UI64FMTD "]", gguid, guid, group->GetLeaderGUID());
sLFGMgr->Leave(NULL, group);
}
void LFGScripts::OnLevelChanged(Player* player, uint8 /*oldLevel*/)
{
sLFGMgr->InitializeLockedDungeons(player);
}
void LFGScripts::OnLogout(Player* player)
{
sLFGMgr->Leave(player);
LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_REMOVED_FROM_QUEUE);
player->GetSession()->SendLfgUpdateParty(updateData);
player->GetSession()->SendLfgUpdatePlayer(updateData);
player->GetSession()->SendLfgUpdateSearch(false);
uint64 guid = player->GetGUID();
// TODO - Do not remove, add timer before deleting
sLFGMgr->RemovePlayerData(guid);
}
void LFGScripts::OnLogin(Player* player)
{
sLFGMgr->InitializeLockedDungeons(player);
// TODO - Restore LfgPlayerData and send proper status to player if it was in a group
}
void LFGScripts::OnBindToInstance(Player* player, Difficulty difficulty, uint32 mapId, bool /*permanent*/)
{
MapEntry const* mapEntry = sMapStore.LookupEntry(mapId);
if (mapEntry->IsDungeon() && difficulty > DUNGEON_DIFFICULTY_NORMAL)
sLFGMgr->InitializeLockedDungeons(player);
}

View File

@@ -26,17 +26,10 @@
class Player;
class Group;
class LFGScripts: public GroupScript, public PlayerScript
class LFGPlayerScript : public PlayerScript
{
public:
LFGScripts();
// Group Hooks
void OnAddMember(Group* group, uint64 guid);
void OnRemoveMember(Group* group, uint64 guid, RemoveMethod method, uint64 kicker, const char* reason);
void OnDisband(Group* group);
void OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid);
void OnInviteMember(Group* group, uint64 guid);
LFGPlayerScript();
// Player Hooks
void OnLevelChanged(Player* player, uint8 oldLevel);
@@ -44,3 +37,16 @@ class LFGScripts: public GroupScript, public PlayerScript
void OnLogin(Player* player);
void OnBindToInstance(Player* player, Difficulty difficulty, uint32 mapId, bool permanent);
};
class LFGGroupScript : public GroupScript
{
public:
LFGGroupScript();
// Group Hooks
void OnAddMember(Group* group, uint64 guid);
void OnRemoveMember(Group* group, uint64 guid, RemoveMethod method, uint64 kicker, char const* reason);
void OnDisband(Group* group);
void OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid);
void OnInviteMember(Group* group, uint64 guid);
};