From c7ff207017a6c882e2578aa55aded886cb90b024 Mon Sep 17 00:00:00 2001 From: SecretsOTheP Date: Mon, 25 Mar 2013 13:07:58 -0400 Subject: [PATCH] Made Merc::AddMercToGroup handle cleaning up old groups as opposed to doing it in each location before AddMercToGroup. This should fix cases where the Merc's owner is invalid and being referenced, which causes the crash located in: http://www.eqemulator.org/forums/showthread.php?t=36670&page=2 --- zone/client_packet.cpp | 21 ++++++++------------- zone/merc.cpp | 13 ++++++------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index bc74cc148..c29f9d9b9 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -6459,15 +6459,6 @@ void Client::Handle_OP_GroupFollow2(const EQApplicationPacket *app) } } - // Remove the merc from the old group - if (GetMerc()) - { - if(GetMerc()->GetGroup()) - { - Merc::RemoveMercFromGroup(GetMerc(), GetMerc()->GetGroup()); - } - } - Group* group = entity_list.GetGroupByClient(inviter->CastToClient()); if(!group){ @@ -6539,8 +6530,9 @@ void Client::Handle_OP_GroupFollow2(const EQApplicationPacket *app) // Add the merc back into the new group if (GetMerc()) { - if (GetMerc()->AddMercToGroup(GetMerc(), group)) { + if (Merc::AddMercToGroup(GetMerc(), group)) { database.SetGroupID(GetMerc()->GetName(), group->GetID(), inviter->CastToClient()->CharacterID(), true); + database.RefreshGroupFromDB(this); } } @@ -6667,8 +6659,6 @@ void Client::Handle_OP_GroupDisband(const EQApplicationPacket *app) Merc* memberMerc = memberToDisband->CastToClient()->GetMerc(); if(memberClient && memberMerc && group) { - Merc::RemoveMercFromGroup(memberMerc, group); - if(!memberMerc->IsGrouped() && !memberClient->IsGrouped()) { Group *g = new Group(memberClient); @@ -6713,13 +6703,18 @@ void Client::Handle_OP_GroupDisband(const EQApplicationPacket *app) return; } - if(GetMerc()->AddMercToGroup(GetMerc(), g)) { + if(Merc::AddMercToGroup(GetMerc(), g)) { database.SetGroupLeaderName(g->GetID(), this->GetName()); g->SaveGroupLeaderAA(); database.SetGroupID(this->GetName(), g->GetID(), this->CharacterID()); database.SetGroupID(GetMerc()->GetName(), g->GetID(), this->CharacterID(), true); database.RefreshGroupFromDB(this); } + else + { + if(GetMerc()) + GetMerc()->Depop(); + } } } } diff --git a/zone/merc.cpp b/zone/merc.cpp index a91593cbd..077b48cc7 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -5839,16 +5839,15 @@ bool Merc::AddMercToGroup(Merc* merc, Group* group) { if(merc->HasGroup()) { Merc::RemoveMercFromGroup(merc, merc->GetGroup()); } - // Add merc to this group - if(group->AddMember(merc)) { - merc->SetFollowID(merc->GetMercOwner()->GetID()); - Result = true; + //Try and add the member, followed by checking if the merc owner exists. + if(group->AddMember(merc) && merc->GetMercOwner() != NULL) { + merc->SetFollowID(merc->GetMercOwner()->GetID()); + Result = true; } - else - { + else { + //Suspend it if the member is not added and the merc's owner is not valid. merc->Suspend(); } - } return Result;