From 82157c7bd1ea7b9b8e60859a08fb79529b732cae Mon Sep 17 00:00:00 2001 From: P0nk Date: Thu, 16 Feb 2023 23:46:13 +0100 Subject: [PATCH 1/2] Flatten ChangeMapHandler --- .../channel/handlers/ChangeMapHandler.java | 217 +++++++++--------- 1 file changed, 114 insertions(+), 103 deletions(-) diff --git a/src/main/java/net/server/channel/handlers/ChangeMapHandler.java b/src/main/java/net/server/channel/handlers/ChangeMapHandler.java index 9d11b65c30..faccb0e4aa 100644 --- a/src/main/java/net/server/channel/handlers/ChangeMapHandler.java +++ b/src/main/java/net/server/channel/handlers/ChangeMapHandler.java @@ -58,126 +58,137 @@ public final class ChangeMapHandler extends AbstractPacketHandler { if (chr.getTrade() != null) { Trade.cancelTrade(chr, Trade.TradeResult.UNSUCCESSFUL_ANOTHER_MAP); } - if (p.available() == 0) { //Cash Shop :) - if (!chr.getCashShop().isOpened()) { - c.disconnect(false, false); - return; + + boolean enteringMapFromCashShop = p.available() == 0; + if (enteringMapFromCashShop) { + enterFromCashShop(c); + return; + } + + if (chr.getCashShop().isOpened()) { + c.disconnect(false, false); + return; + } + + try { + p.readByte(); // 1 = from dying 0 = regular portals + int targetMapId = p.readInt(); + String portalName = p.readString(); + Portal portal = chr.getMap().getPortal(portalName); + p.readByte(); + boolean wheel = p.readByte() > 0; + + boolean chasing = p.readByte() == 1 && chr.isGM(); + if (chasing) { + chr.setChasing(true); + chr.setPosition(new Point(p.readInt(), p.readInt())); } - String[] socket = c.getChannelServer().getIP().split(":"); - chr.getCashShop().open(false); - chr.setSessionTransitionState(); - try { - c.sendPacket(PacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]))); - } catch (UnknownHostException ex) { - ex.printStackTrace(); - } - } else { - if (chr.getCashShop().isOpened()) { - c.disconnect(false, false); - return; - } - try { - p.readByte(); // 1 = from dying 0 = regular portals - int targetid = p.readInt(); - String startwp = p.readString(); - Portal portal = chr.getMap().getPortal(startwp); - p.readByte(); - boolean wheel = p.readByte() > 0; + if (targetMapId != -1) { + if (!chr.isAlive()) { + MapleMap map = chr.getMap(); + if (wheel && chr.haveItemWithId(ItemId.WHEEL_OF_FORTUNE, false)) { + // thanks lucasziron (lziron) for showing revivePlayer() triggering by Wheel - boolean chasing = p.readByte() == 1 && chr.isGM(); - if (chasing) { - chr.setChasing(true); - chr.setPosition(new Point(p.readInt(), p.readInt())); - } + InventoryManipulator.removeById(c, InventoryType.CASH, ItemId.WHEEL_OF_FORTUNE, 1, true, false); + chr.sendPacket(PacketCreator.showWheelsLeft(chr.getItemQuantity(ItemId.WHEEL_OF_FORTUNE, false))); - if (targetid != -1) { - if (!chr.isAlive()) { - MapleMap map = chr.getMap(); - if (wheel && chr.haveItemWithId(ItemId.WHEEL_OF_FORTUNE, false)) { - // thanks lucasziron (lziron) for showing revivePlayer() triggering by Wheel - - InventoryManipulator.removeById(c, InventoryType.CASH, ItemId.WHEEL_OF_FORTUNE, 1, true, false); - chr.sendPacket(PacketCreator.showWheelsLeft(chr.getItemQuantity(ItemId.WHEEL_OF_FORTUNE, false))); - - chr.updateHp(50); - chr.changeMap(map, map.findClosestPlayerSpawnpoint(chr.getPosition())); - } else { - boolean executeStandardPath = true; - if (chr.getEventInstance() != null) { - executeStandardPath = chr.getEventInstance().revivePlayer(chr); + chr.updateHp(50); + chr.changeMap(map, map.findClosestPlayerSpawnpoint(chr.getPosition())); + } else { + boolean executeStandardPath = true; + if (chr.getEventInstance() != null) { + executeStandardPath = chr.getEventInstance().revivePlayer(chr); + } + if (executeStandardPath) { + chr.respawn(map.getReturnMapId()); + } + } + } else { + if (chr.isGM()) { + MapleMap to = chr.getWarpMap(targetMapId); + chr.changeMap(to, to.getPortal(0)); + } else { + final int divi = chr.getMapId() / 100; + boolean warp = false; + if (divi == 0) { + if (targetMapId == 10000) { + warp = true; } - if (executeStandardPath) { - chr.respawn(map.getReturnMapId()); + } else if (divi == 20100) { + if (targetMapId == MapId.LITH_HARBOUR) { + c.sendPacket(PacketCreator.lockUI(false)); + c.sendPacket(PacketCreator.disableUI(false)); + warp = true; + } + } else if (divi == 9130401) { // Only allow warp if player is already in Intro map, or else = hack + if (targetMapId == MapId.EREVE || targetMapId / 100 == 9130401) { // Cygnus introduction + warp = true; + } + } else if (divi == 9140900) { // Aran Introduction + if (targetMapId == MapId.ARAN_TUTO_2 || targetMapId == MapId.ARAN_TUTO_3 || targetMapId == MapId.ARAN_TUTO_4 || targetMapId == MapId.ARAN_INTRO) { + warp = true; + } + } else if (divi / 10 == 1020) { // Adventurer movie clip Intro + if (targetMapId == 1020000) { + warp = true; + } + } else if (divi / 10 >= 980040 && divi / 10 <= 980045) { + if (targetMapId == MapId.WITCH_TOWER_ENTRANCE) { + warp = true; } } - } else { - if (chr.isGM()) { - MapleMap to = chr.getWarpMap(targetid); + if (warp) { + final MapleMap to = chr.getWarpMap(targetMapId); chr.changeMap(to, to.getPortal(0)); - } else { - final int divi = chr.getMapId() / 100; - boolean warp = false; - if (divi == 0) { - if (targetid == 10000) { - warp = true; - } - } else if (divi == 20100) { - if (targetid == MapId.LITH_HARBOUR) { - c.sendPacket(PacketCreator.lockUI(false)); - c.sendPacket(PacketCreator.disableUI(false)); - warp = true; - } - } else if (divi == 9130401) { // Only allow warp if player is already in Intro map, or else = hack - if (targetid == MapId.EREVE || targetid / 100 == 9130401) { // Cygnus introduction - warp = true; - } - } else if (divi == 9140900) { // Aran Introduction - if (targetid == MapId.ARAN_TUTO_2 || targetid == MapId.ARAN_TUTO_3 || targetid == MapId.ARAN_TUTO_4 || targetid == MapId.ARAN_INTRO) { - warp = true; - } - } else if (divi / 10 == 1020) { // Adventurer movie clip Intro - if (targetid == 1020000) { - warp = true; - } - } else if (divi / 10 >= 980040 && divi / 10 <= 980045) { - if (targetid == MapId.WITCH_TOWER_ENTRANCE) { - warp = true; - } - } - if (warp) { - final MapleMap to = chr.getWarpMap(targetid); - chr.changeMap(to, to.getPortal(0)); - } } } } + } - if (portal != null && !portal.getPortalStatus()) { - c.sendPacket(PacketCreator.blockedMessage(1)); + if (portal != null && !portal.getPortalStatus()) { + c.sendPacket(PacketCreator.blockedMessage(1)); + c.sendPacket(PacketCreator.enableActions()); + return; + } + + if (chr.getMapId() == MapId.FITNESS_EVENT_LAST) { + chr.getFitness().resetTimes(); + } else if (chr.getMapId() == MapId.OLA_EVENT_LAST_1 || chr.getMapId() == MapId.OLA_EVENT_LAST_2) { + chr.getOla().resetTimes(); + } + + if (portal != null) { + if (portal.getPosition().distanceSq(chr.getPosition()) > 400000) { c.sendPacket(PacketCreator.enableActions()); return; } - if (chr.getMapId() == MapId.FITNESS_EVENT_LAST) { - chr.getFitness().resetTimes(); - } else if (chr.getMapId() == MapId.OLA_EVENT_LAST_1 || chr.getMapId() == MapId.OLA_EVENT_LAST_2) { - chr.getOla().resetTimes(); - } - - if (portal != null) { - if (portal.getPosition().distanceSq(chr.getPosition()) > 400000) { - c.sendPacket(PacketCreator.enableActions()); - return; - } - - portal.enterPortal(c); - } else { - c.sendPacket(PacketCreator.enableActions()); - } - } catch (Exception e) { - e.printStackTrace(); + portal.enterPortal(c); + } else { + c.sendPacket(PacketCreator.enableActions()); } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + private void enterFromCashShop(Client c) { + final Character chr = c.getPlayer(); + + if (!chr.getCashShop().isOpened()) { + c.disconnect(false, false); + return; + } + String[] socket = c.getChannelServer().getIP().split(":"); + chr.getCashShop().open(false); + + chr.setSessionTransitionState(); + try { + c.sendPacket(PacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]))); + } catch (UnknownHostException ex) { + ex.printStackTrace(); } } } \ No newline at end of file From b30e03ffb3b25664618dfe5e8fdbfd7c590af8b9 Mon Sep 17 00:00:00 2001 From: P0nk Date: Fri, 17 Feb 2023 00:42:33 +0100 Subject: [PATCH 2/2] Fix portal in Zenumist society not working for GM chr --- src/main/java/net/server/channel/handlers/ChangeMapHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/server/channel/handlers/ChangeMapHandler.java b/src/main/java/net/server/channel/handlers/ChangeMapHandler.java index faccb0e4aa..9a8648735a 100644 --- a/src/main/java/net/server/channel/handlers/ChangeMapHandler.java +++ b/src/main/java/net/server/channel/handlers/ChangeMapHandler.java @@ -78,7 +78,7 @@ public final class ChangeMapHandler extends AbstractPacketHandler { p.readByte(); boolean wheel = p.readByte() > 0; - boolean chasing = p.readByte() == 1 && chr.isGM(); + boolean chasing = p.readByte() == 1 && chr.isGM() && p.available() == 2 * Integer.BYTES; if (chasing) { chr.setChasing(true); chr.setPosition(new Point(p.readInt(), p.readInt()));