Skip to content

Commit

Permalink
Fixed buff removal when leaving certain instances
Browse files Browse the repository at this point in the history
Leaving a solo instance while being in a group would not call onLeaveInstance, causing buffs not getting removed for example.
Changed default instanced map handlers to fix undefined behavior when logging into an already destroyed instance. Because instance ID 1 is currently the fallback, not all handlers handle onLeaveInstance with unknown players gracefully (e.g. BasicPvpInstance).
  • Loading branch information
neon-dev committed Jan 12, 2025
1 parent 4fcb0b0 commit 41c724f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void destroyInstance(WorldMapInstance instance) {

map.removeWorldMapInstance(instanceId);

log.info("Destroying instance:" + worldId + " " + instanceId);
log.info("Destroying " + instance);

TemporarySpawnEngine.onInstanceDestroy(instance); // first unregister all temporary spawns, then despawn mobs
for (VisibleObject obj : instance) {
Expand Down Expand Up @@ -257,17 +257,15 @@ public static void onEnterInstance(Player player) {
}

public static void onLeaveInstance(Player player) {
WorldMapInstance registeredInstance = getRegisteredInstance(player.getWorldId(), getLastRegisteredId(player));
if (registeredInstance != null) { // don't get instance via player.getPosition since he maybe isn't registered with it anymore (login after dc)
registeredInstance.getInstanceHandler().onLeaveInstance(player);
if (!registeredInstance.isPersonal()) {
if (registeredInstance.getMaxPlayers() == 1) // solo instance
PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_LEAVE_INSTANCE(getDestroyDelaySeconds(registeredInstance) / 60));
else if (registeredInstance.getRegisteredTeam() != null && registeredInstance.getRegisteredTeam().getMembers().isEmpty())
PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_LEAVE_INSTANCE_PARTY(0));
else if (registeredInstance.getPlayersInside().size() <= 1)
PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_LEAVE_INSTANCE_PARTY(getDestroyDelaySeconds(registeredInstance) / 60));
}
WorldMapInstance instance = player.getWorldMapInstance();
instance.getInstanceHandler().onLeaveInstance(player);
if (instance.getRegisteredCount() > 0) {
if (instance.getMaxPlayers() == 1) // solo instance
PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_LEAVE_INSTANCE(getDestroyDelaySeconds(instance) / 60));
else if (instance.getRegisteredTeam() != null && instance.getRegisteredTeam().getMembers().isEmpty())
PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_LEAVE_INSTANCE_PARTY(0));
else if (instance.getPlayersInside().size() <= 1)
PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_LEAVE_INSTANCE_PARTY(getDestroyDelaySeconds(instance) / 60));
}
removeRestrictedItemsFromInventoryAndStorage(player, item -> item.getItemTemplate().isItemRestrictedToWorld(player.getWorldId()));

Expand Down
6 changes: 5 additions & 1 deletion game-server/src/com/aionemu/gameserver/world/WorldMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import com.aionemu.gameserver.instance.handlers.GeneralInstanceHandler;
import com.aionemu.gameserver.model.templates.world.WorldMapTemplate;
import com.aionemu.gameserver.world.zone.ZoneAttributes;

Expand All @@ -26,7 +27,10 @@ public WorldMap(WorldMapTemplate worldMapTemplate) {
this.worldOptions = worldMapTemplate.getFlags();

for (int i = 1; i <= getInstanceCount(); i++) {
WorldMapInstanceFactory.createWorldMapInstance(this, 0);
if (isInstanceType()) // default instances are inaccessible but its handler methods are sometimes called via MainWorldMapInstance, e.g. on relog
WorldMapInstanceFactory.createWorldMapInstance(this, 0, GeneralInstanceHandler::new, 0);
else
WorldMapInstanceFactory.createWorldMapInstance(this, 0);
}
}

Expand Down

0 comments on commit 41c724f

Please sign in to comment.