Skip to content

Commit

Permalink
Merge pull request #5568 from CatsAndBoats/instance_entry_failure
Browse files Browse the repository at this point in the history
[cpp] Ensure player is booted from failed instance cleanly
  • Loading branch information
claywar authored May 6, 2024
2 parents f41faa4 + 92bc212 commit 2309bb1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
10 changes: 5 additions & 5 deletions scripts/globals/instance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,12 @@ xi.instance.onInstanceCreatedCallback = function(player, instance)
-- this makes the animation trigger reliably
v:release()
v:startEvent(unpack(lookupEntry[4]))
end

v:setInstance(instance)
local npc = player:getEventTarget()
if npc ~= nil then
v:instanceEntry(npc, 4)
v:setInstance(instance)
local npc = player:getEventTarget()
if npc ~= nil then
v:instanceEntry(npc, 4)
end
end

v:timer(35000, function(playerArg)
Expand Down
18 changes: 15 additions & 3 deletions src/map/zone_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ along with this program. If not, see http://www.gnu.org/licenses/
#include "entities/charentity.h"
#include "lua/luautils.h"
#include "status_effect_container.h"
#include "utils/charutils.h"
#include "utils/zoneutils.h"

CZoneInstance::CZoneInstance(ZONEID ZoneID, REGION_TYPE RegionID, CONTINENT_TYPE ContinentID, uint8 levelRestriction)
Expand Down Expand Up @@ -249,19 +250,30 @@ void CZoneInstance::IncreaseZoneCounter(CCharEntity* PChar)
.c_str());

// instance no longer exists: put them outside (at exit)
PChar->loc.prevzone = GetID();

uint16 zoneid = luautils::OnInstanceLoadFailed(this);

CZone* PZone = zoneutils::GetZone(zoneid);
// At this stage, can only send the player to a zone on this map server
// reset position in the case of a zone crash while in an instance
PChar->loc.p.x = 0;
PChar->loc.p.y = 0;
PChar->loc.p.z = 0;
if (PZone)
{
PZone->IncreaseZoneCounter(PChar);
}
else
{
zoneutils::GetZone(PChar->loc.prevzone)->IncreaseZoneCounter(PChar);
// if we can't get the instance failed destination zone, get their previous zone
zoneid = PChar->loc.prevzone;
zoneutils::GetZone(zoneid)->IncreaseZoneCounter(PChar);
}

// They are properly sent to zone, but bypassed the onZoneIn position fixup, do that now
PChar->loc.prevzone = GetID();
PChar->loc.destination = zoneid;
luautils::OnZoneIn(PChar);
charutils::SaveCharPosition(PChar);
}
}

Expand Down

0 comments on commit 2309bb1

Please sign in to comment.