Search in sources :

Example 1 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class DueyHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!ServerConstants.USE_DUEY) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    byte operation = slea.readByte();
    if (operation == Actions.TOSERVER_SEND_ITEM.getCode()) {
        final int fee = 5000;
        byte inventId = slea.readByte();
        short itemPos = slea.readShort();
        short amount = slea.readShort();
        int mesos = slea.readInt();
        String recipient = slea.readMapleAsciiString();
        if (mesos < 0 || ((long) mesos + fee + getFee(mesos)) > Integer.MAX_VALUE || (amount < 1 && mesos == 0)) {
            AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with duey.");
            FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use duey with mesos " + mesos + " and amount " + amount + "\r\n");
            c.disconnect(true, false);
            return;
        }
        int finalcost = mesos + fee + getFee(mesos);
        boolean send = false;
        if (c.getPlayer().getMeso() >= finalcost) {
            int accid = getAccIdFromCNAME(recipient, true);
            if (accid != -1) {
                if (accid != c.getAccID()) {
                    send = true;
                } else {
                    c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_SAMEACC_ERROR.getCode()));
                }
            } else {
                c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_NAME_DOES_NOT_EXIST.getCode()));
            }
        } else {
            c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_NOT_ENOUGH_MESOS.getCode()));
        }
        MapleClient rClient = null;
        int channel = c.getWorldServer().find(recipient);
        if (channel > -1) {
            Channel rcserv = c.getWorldServer().getChannel(channel);
            rClient = rcserv.getPlayerStorage().getCharacterByName(recipient).getClient();
        }
        if (send) {
            if (inventId > 0) {
                MapleInventoryType inv = MapleInventoryType.getByType(inventId);
                Item item = c.getPlayer().getInventory(inv).getItem(itemPos);
                if (item != null && c.getPlayer().getItemQuantity(item.getItemId(), false) >= amount) {
                    c.getPlayer().gainMeso(-finalcost, false);
                    c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
                    if (ItemConstants.isRechargable(item.getItemId())) {
                        MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, item.getQuantity(), true);
                    } else {
                        MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, amount, true, false);
                    }
                    addItemToDB(item, amount, mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
                } else {
                    if (item != null) {
                        c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_INCORRECT_REQUEST.getCode()));
                    }
                    return;
                }
            } else {
                c.getPlayer().gainMeso(-finalcost, false);
                c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
                addMesoToDB(mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
            }
            if (rClient != null && rClient.isLoggedIn() && !rClient.getPlayer().isAwayFromWorld()) {
                showDueyNotification(rClient, rClient.getPlayer());
            }
        }
    } else if (operation == Actions.TOSERVER_REMOVE_PACKAGE.getCode()) {
        int packageid = slea.readInt();
        removeItemFromDB(packageid);
        c.announce(MaplePacketCreator.removeItemFromDuey(true, packageid));
    } else if (operation == Actions.TOSERVER_CLAIM_PACKAGE.getCode()) {
        int packageid = slea.readInt();
        List<DueyPackages> packages = new LinkedList<>();
        DueyPackages dp = null;
        Connection con = null;
        try {
            con = DatabaseConnection.getConnection();
            DueyPackages dueypack;
            try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages LEFT JOIN dueyitems USING (PackageId) WHERE PackageId = ?")) {
                ps.setInt(1, packageid);
                try (ResultSet rs = ps.executeQuery()) {
                    dueypack = null;
                    if (rs.next()) {
                        dueypack = getItemByPID(rs);
                        dueypack.setSender(rs.getString("SenderName"));
                        dueypack.setMesos(rs.getInt("Mesos"));
                        dueypack.setSentTime(rs.getString("TimeStamp"));
                        packages.add(dueypack);
                    }
                }
            }
            dp = dueypack;
            if (dp == null) {
                c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
                FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to receive package from duey with id " + packageid + "\r\n");
                return;
            }
            if (dp.getItem() != null) {
                if (!MapleInventoryManipulator.checkSpace(c, dp.getItem().getItemId(), dp.getItem().getQuantity(), dp.getItem().getOwner())) {
                    int itemid = dp.getItem().getItemId();
                    if (MapleItemInformationProvider.getInstance().isPickupRestricted(itemid) && c.getPlayer().getInventory(ItemConstants.getInventoryType(itemid)).findById(itemid) != null) {
                        c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_RECEIVER_WITH_UNIQUE.getCode()));
                    } else {
                        c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_NO_FREE_SLOTS.getCode()));
                    }
                    return;
                } else {
                    MapleInventoryManipulator.addFromDrop(c, dp.getItem(), false);
                }
            }
            long gainmesos = 0;
            long totalmesos = (long) dp.getMesos() + (long) c.getPlayer().getMeso();
            if (totalmesos < 0 || dp.getMesos() < 0)
                gainmesos = 0;
            else {
                totalmesos = Math.min(totalmesos, Integer.MAX_VALUE);
                gainmesos = totalmesos - c.getPlayer().getMeso();
            }
            c.getPlayer().gainMeso((int) gainmesos, false);
            removeItemFromDB(packageid);
            c.announce(MaplePacketCreator.removeItemFromDuey(false, packageid));
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
Also used : SQLException(java.sql.SQLException) Channel(net.server.channel.Channel) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) LinkedList(java.util.LinkedList) Item(client.inventory.Item) DueyPackages(server.DueyPackages) MapleInventoryType(client.inventory.MapleInventoryType) ResultSet(java.sql.ResultSet) MapleClient(client.MapleClient)

Example 2 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class MapleMap method spawnItemDrop.

public final void spawnItemDrop(final MapleMapObject dropper, final MapleCharacter owner, final Item item, Point pos, final byte dropType, final boolean playerDrop) {
    final Point droppos = calcDropPos(pos, pos);
    final MapleMapItem mdrop = new MapleMapItem(item, droppos, dropper, owner, owner.getClient(), dropType, playerDrop);
    mdrop.setDropTime(System.currentTimeMillis());
    spawnAndAddRangedMapObject(mdrop, new DelayedPacketCreation() {

        @Override
        public void sendPackets(MapleClient c) {
            c.announce(MaplePacketCreator.dropItemFromMapObject(mdrop, dropper.getPosition(), droppos, (byte) 1));
        }
    }, null);
    broadcastMessage(MaplePacketCreator.dropItemFromMapObject(mdrop, dropper.getPosition(), droppos, (byte) 0));
    instantiateItemDrop(mdrop);
    activateItemReactors(mdrop, owner.getClient());
}
Also used : MapleClient(client.MapleClient) Point(java.awt.Point) SpawnPoint(server.life.SpawnPoint)

Example 3 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class MapleMap method spawnMonster.

public void spawnMonster(final MapleMonster monster, int difficulty, boolean isPq) {
    if (mobCapacity != -1 && mobCapacity == spawnedMonstersOnMap.get()) {
        // PyPQ
        return;
    }
    monster.changeDifficulty(difficulty, isPq);
    monster.setMap(this);
    if (getEventInstance() != null)
        getEventInstance().registerMonster(monster);
    spawnAndAddRangedMapObject(monster, new DelayedPacketCreation() {

        @Override
        public void sendPackets(MapleClient c) {
            c.announce(MaplePacketCreator.spawnMonster(monster, true));
        }
    }, null);
    updateMonsterController(monster);
    if (monster.getDropPeriodTime() > 0) {
        // 9300102 - Watchhog, 9300061 - Moon Bunny (HPQ), 9300093 - Tylus
        if (monster.getId() == 9300102) {
            monsterItemDrop(monster, monster.getDropPeriodTime());
        } else if (monster.getId() == 9300061) {
            monsterItemDrop(monster, monster.getDropPeriodTime() / 3);
        } else if (monster.getId() == 9300093) {
            monsterItemDrop(monster, monster.getDropPeriodTime());
        } else {
            FilePrinter.printError(FilePrinter.UNHANDLED_EVENT, "UNCODED TIMED MOB DETECTED: " + monster.getId() + "\r\n");
        }
    }
    spawnedMonstersOnMap.incrementAndGet();
    final selfDestruction selfDestruction = monster.getStats().selfDestruction();
    if (monster.getStats().removeAfter() > 0 || selfDestruction != null && selfDestruction.getHp() < 0) {
        if (selfDestruction == null) {
            TimerManager.getInstance().schedule(new Runnable() {

                @Override
                public void run() {
                    killMonster(monster, null, false);
                }
            }, monster.getStats().removeAfter() * 1000);
        } else {
            TimerManager.getInstance().schedule(new Runnable() {

                @Override
                public void run() {
                    killMonster(monster, null, false, selfDestruction.getAction());
                }
            }, selfDestruction.removeAfter() * 1000);
        }
    }
}
Also used : MapleLifeFactory.selfDestruction(server.life.MapleLifeFactory.selfDestruction) MapleClient(client.MapleClient)

Example 4 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class MapleMap method spawnMesoDrop.

public final void spawnMesoDrop(final int meso, final Point position, final MapleMapObject dropper, final MapleCharacter owner, final boolean playerDrop, final byte droptype) {
    final Point droppos = calcDropPos(position, position);
    final MapleMapItem mdrop = new MapleMapItem(meso, droppos, dropper, owner, owner.getClient(), droptype, playerDrop);
    mdrop.setDropTime(System.currentTimeMillis());
    spawnAndAddRangedMapObject(mdrop, new DelayedPacketCreation() {

        @Override
        public void sendPackets(MapleClient c) {
            c.announce(MaplePacketCreator.dropItemFromMapObject(mdrop, dropper.getPosition(), droppos, (byte) 1));
        }
    }, null);
    instantiateItemDrop(mdrop);
}
Also used : MapleClient(client.MapleClient) Point(java.awt.Point) SpawnPoint(server.life.SpawnPoint)

Example 5 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class ItemAction method check.

@Override
public boolean check(MapleCharacter chr, Integer extSelection) {
    List<Pair<Item, MapleInventoryType>> gainList = new LinkedList<>();
    List<Pair<Item, MapleInventoryType>> selectList = new LinkedList<>();
    List<Pair<Item, MapleInventoryType>> randomList = new LinkedList<>();
    List<Integer> allSlotUsed = new ArrayList(5);
    for (byte i = 0; i < 5; i++) allSlotUsed.add(0);
    for (ItemData item : items) {
        if (!canGetItem(item, chr)) {
            continue;
        }
        MapleInventoryType type = ItemConstants.getInventoryType(item.getId());
        if (item.getProp() != null) {
            Item toItem = new Item(item.getId(), (short) 0, (short) item.getCount());
            if (item.getProp() < 0) {
                selectList.add(new Pair<>(toItem, type));
            } else {
                randomList.add(new Pair<>(toItem, type));
            }
        } else {
            if (item.getCount() > 0) {
                // Make sure they can hold the item.
                Item toItem = new Item(item.getId(), (short) 0, (short) item.getCount());
                gainList.add(new Pair<>(toItem, type));
            } else {
                // Make sure they actually have the item.
                int quantity = item.getCount() * -1;
                int freeSlotCount = chr.getInventory(type).freeSlotCountById(item.getId(), quantity);
                if (freeSlotCount == -1) {
                    if (type.equals(MapleInventoryType.EQUIP) && chr.getInventory(MapleInventoryType.EQUIPPED).countById(item.getId()) > quantity)
                        continue;
                    chr.dropMessage(1, "Please check if you have enough items in your inventory.");
                    return false;
                } else {
                    // more slots available from the given items!
                    int idx = type.getType() - 1;
                    allSlotUsed.set(idx, allSlotUsed.get(idx) - freeSlotCount);
                }
            }
        }
    }
    if (!randomList.isEmpty()) {
        int result;
        MapleClient c = chr.getClient();
        List<Integer> rndUsed = new ArrayList(5);
        for (byte i = 0; i < 5; i++) rndUsed.add(allSlotUsed.get(i));
        for (Pair<Item, MapleInventoryType> it : randomList) {
            int idx = it.getRight().getType() - 1;
            result = MapleInventoryManipulator.checkSpaceProgressively(c, it.getLeft().getItemId(), it.getLeft().getQuantity(), "", rndUsed.get(idx));
            if (result % 2 == 0) {
                chr.dropMessage(1, "Please check if you have enough space in your inventory.");
                return false;
            }
            allSlotUsed.set(idx, Math.max(allSlotUsed.get(idx), result >> 1));
        }
    }
    if (!selectList.isEmpty()) {
        Pair<Item, MapleInventoryType> selected = selectList.get(extSelection);
        gainList.add(selected);
    }
    if (!MapleInventory.checkSpots(chr, gainList, allSlotUsed)) {
        chr.dropMessage(1, "Please check if you have enough space in your inventory.");
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) MapleClient(client.MapleClient) Pair(tools.Pair)

Aggregations

MapleClient (client.MapleClient)21 Item (client.inventory.Item)4 Point (java.awt.Point)4 LinkedList (java.util.LinkedList)4 SpawnPoint (server.life.SpawnPoint)4 MapleInventoryType (client.inventory.MapleInventoryType)3 ArrayList (java.util.ArrayList)3 MapleAESOFB (tools.MapleAESOFB)3 MapleCharacter (client.MapleCharacter)2 SQLException (java.sql.SQLException)2 LinkedHashMap (java.util.LinkedHashMap)2 Pair (tools.Pair)2 MapleJob (client.MapleJob)1 Skill (client.Skill)1 Equip (client.inventory.Equip)1 ScrollResult (client.inventory.Equip.ScrollResult)1 MaplePet (client.inventory.MaplePet)1 ModifyInventory (client.inventory.ModifyInventory)1 Rectangle (java.awt.Rectangle)1 IOException (java.io.IOException)1