From 3816e1c5bd106b59abe85ec4360027da8ed8ae19 Mon Sep 17 00:00:00 2001 From: Arthur Charlton Date: Mon, 3 Jul 2023 18:25:14 -0400 Subject: [PATCH 1/4] Add the warp party function that the scripts use --- src/main/java/scripting/AbstractPlayerInteraction.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/scripting/AbstractPlayerInteraction.java b/src/main/java/scripting/AbstractPlayerInteraction.java index 3f8cd0626b..3e54e94043 100644 --- a/src/main/java/scripting/AbstractPlayerInteraction.java +++ b/src/main/java/scripting/AbstractPlayerInteraction.java @@ -133,6 +133,16 @@ public class AbstractPlayerInteraction { warpParty(id, portalId, mapid, mapid); } + public void warpParty(int map, String portalName) { + + int mapid = getMapId(); + var warpMap = c.getChannelServer().getMapFactory().getMap(map); + var portal = warpMap.getPortal(portalName).getId(); + + warpParty(map, portal, mapid, mapid); + + } + public void warpParty(int id, int fromMinId, int fromMaxId) { warpParty(id, 0, fromMinId, fromMaxId); } From cfb5fc25c3df5ba4555e0039f9aa5e3d80500a55 Mon Sep 17 00:00:00 2001 From: Arthur Charlton Date: Wed, 5 Jul 2023 14:12:42 -0400 Subject: [PATCH 2/4] Calling code assumes the pair never null and uses -1 to signify not found. --- src/main/java/client/processor/npc/DueyProcessor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/client/processor/npc/DueyProcessor.java b/src/main/java/client/processor/npc/DueyProcessor.java index 345c135c7a..505b2b9e5b 100644 --- a/src/main/java/client/processor/npc/DueyProcessor.java +++ b/src/main/java/client/processor/npc/DueyProcessor.java @@ -92,14 +92,15 @@ public class DueyProcessor { } private static Pair getAccountCharacterIdFromCNAME(String name) { - Pair ids = null; + Pair ids = new Pair<>(-1, -1); try (Connection con = DatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement("SELECT id,accountid FROM characters WHERE name = ?")) { ps.setString(1, name); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { - ids = new Pair<>(rs.getInt("accountid"), rs.getInt("id")); + ids.left = rs.getInt("accountid"); + ids.right = rs.getInt("id"); } } } catch (SQLException e) { From 07eb0f5e8ee4e2b6e431282327e3c16a9f651956 Mon Sep 17 00:00:00 2001 From: Arthur Charlton Date: Wed, 5 Jul 2023 14:16:09 -0400 Subject: [PATCH 3/4] Untangle nested control flow conditions. --- .../client/processor/npc/DueyProcessor.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/main/java/client/processor/npc/DueyProcessor.java b/src/main/java/client/processor/npc/DueyProcessor.java index 505b2b9e5b..8a8615985b 100644 --- a/src/main/java/client/processor/npc/DueyProcessor.java +++ b/src/main/java/client/processor/npc/DueyProcessor.java @@ -316,30 +316,25 @@ public class DueyProcessor { return; } - Pair accIdCid; - if (c.getPlayer().getMeso() >= finalcost) { - accIdCid = getAccountCharacterIdFromCNAME(recipient); - int recipientAccId = accIdCid.getLeft(); - if (recipientAccId != -1) { - if (recipientAccId == c.getAccID()) { - c.sendPacket(PacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_SAMEACC_ERROR.getCode())); - return; - } - } else { - c.sendPacket(PacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_NAME_DOES_NOT_EXIST.getCode())); - return; - } - } else { + if(c.getPlayer().getMeso() < finalcost) { c.sendPacket(PacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_NOT_ENOUGH_MESOS.getCode())); return; } - int recipientCid = accIdCid.getRight(); - if (recipientCid == -1) { + var accIdCid = getAccountCharacterIdFromCNAME(recipient); + var recipientAccId = accIdCid.getLeft(); + var recipientCid = accIdCid.getRight(); + + if (recipientAccId == -1 || recipientCid == -1) { c.sendPacket(PacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_NAME_DOES_NOT_EXIST.getCode())); return; } + if (recipientAccId == c.getAccID()) { + c.sendPacket(PacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_SAMEACC_ERROR.getCode())); + return; + } + if (quick) { InventoryManipulator.removeById(c, InventoryType.CASH, ItemId.QUICK_DELIVERY_TICKET, (short) 1, false, false); } From b935725096e79b57ea2712a105f6b3847ef86993 Mon Sep 17 00:00:00 2001 From: Arthur Charlton Date: Mon, 10 Jul 2023 17:01:48 -0400 Subject: [PATCH 4/4] Handle the potentially null portal based on the name. Matches the behavior of warping a character to a named portal. --- .../java/scripting/AbstractPlayerInteraction.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/scripting/AbstractPlayerInteraction.java b/src/main/java/scripting/AbstractPlayerInteraction.java index 3e54e94043..f388e70f81 100644 --- a/src/main/java/scripting/AbstractPlayerInteraction.java +++ b/src/main/java/scripting/AbstractPlayerInteraction.java @@ -137,9 +137,16 @@ public class AbstractPlayerInteraction { int mapid = getMapId(); var warpMap = c.getChannelServer().getMapFactory().getMap(map); - var portal = warpMap.getPortal(portalName).getId(); - warpParty(map, portal, mapid, mapid); + var portal = warpMap.getPortal(portalName); + + if (portal == null) { + portal = warpMap.getPortal(0); + } + + var portalId = portal.getId(); + + warpParty(map, portalId, mapid, mapid); }