Search in sources :

Example 6 with MTSItemInfo

use of server.MTSItemInfo in project HeavenMS by ronancpl.

the class MaplePacketCreator method notYetSoldInv.

public static byte[] notYetSoldInv(List<MTSItemInfo> items) {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.MTS_OPERATION.getValue());
    mplew.write(0x23);
    mplew.writeInt(items.size());
    if (!items.isEmpty()) {
        for (MTSItemInfo item : items) {
            addItemInfo(mplew, item.getItem(), true);
            // id
            mplew.writeInt(item.getID());
            // this + below = price
            mplew.writeInt(item.getTaxes());
            // price
            mplew.writeInt(item.getPrice());
            mplew.writeInt(0);
            mplew.writeLong(getTime(item.getEndingDate()));
            // account name (what was nexon thinking?)
            mplew.writeMapleAsciiString(item.getSeller());
            // char name
            mplew.writeMapleAsciiString(item.getSeller());
            for (int i = 0; i < 28; i++) {
                mplew.write(0);
            }
        }
    } else {
        mplew.writeInt(0);
    }
    return mplew.getPacket();
}
Also used : MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) MTSItemInfo(server.MTSItemInfo) Point(java.awt.Point)

Example 7 with MTSItemInfo

use of server.MTSItemInfo in project HeavenMS by ronancpl.

the class MTSHandler method getNotYetSold.

public List<MTSItemInfo> getNotYetSold(int cid) {
    List<MTSItemInfo> items = new ArrayList<>();
    Connection con = null;
    PreparedStatement ps;
    ResultSet rs;
    try {
        con = DatabaseConnection.getConnection();
        ps = con.prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 0 ORDER BY id DESC");
        ps.setInt(1, cid);
        rs = ps.executeQuery();
        while (rs.next()) {
            if (rs.getInt("type") != 1) {
                Item i = new Item(rs.getInt("itemid"), (byte) 0, (short) rs.getInt("quantity"));
                i.setOwner(rs.getString("owner"));
                items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
            } else {
                Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
                equip.setOwner(rs.getString("owner"));
                equip.setQuantity((short) 1);
                equip.setAcc((short) rs.getInt("acc"));
                equip.setAvoid((short) rs.getInt("avoid"));
                equip.setDex((short) rs.getInt("dex"));
                equip.setHands((short) rs.getInt("hands"));
                equip.setHp((short) rs.getInt("hp"));
                equip.setInt((short) rs.getInt("int"));
                equip.setJump((short) rs.getInt("jump"));
                equip.setVicious((short) rs.getInt("vicious"));
                equip.setLuk((short) rs.getInt("luk"));
                equip.setMatk((short) rs.getInt("matk"));
                equip.setMdef((short) rs.getInt("mdef"));
                equip.setMp((short) rs.getInt("mp"));
                equip.setSpeed((short) rs.getInt("speed"));
                equip.setStr((short) rs.getInt("str"));
                equip.setWatk((short) rs.getInt("watk"));
                equip.setWdef((short) rs.getInt("wdef"));
                equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
                equip.setLevel((byte) rs.getInt("level"));
                equip.setFlag((byte) rs.getInt("flag"));
                items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
            }
        }
        rs.close();
        ps.close();
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return items;
}
Also used : Item(client.inventory.Item) Equip(client.inventory.Equip) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MTSItemInfo(server.MTSItemInfo) PreparedStatement(java.sql.PreparedStatement)

Example 8 with MTSItemInfo

use of server.MTSItemInfo in project HeavenMS by ronancpl.

the class MTSHandler method getCart.

public byte[] getCart(int cid) {
    List<MTSItemInfo> items = new ArrayList<>();
    Connection con = null;
    PreparedStatement ps;
    ResultSet rs;
    int pages = 0;
    try {
        con = DatabaseConnection.getConnection();
        ps = con.prepareStatement("SELECT * FROM mts_cart WHERE cid = ? ORDER BY id DESC");
        ps.setInt(1, cid);
        rs = ps.executeQuery();
        while (rs.next()) {
            try (PreparedStatement pse = con.prepareStatement("SELECT * FROM mts_items WHERE id = ?")) {
                pse.setInt(1, rs.getInt("itemid"));
                ResultSet rse = pse.executeQuery();
                if (rse.next()) {
                    if (rse.getInt("type") != 1) {
                        Item i = new Item(rse.getInt("itemid"), (short) 0, (short) rse.getInt("quantity"));
                        i.setOwner(rse.getString("owner"));
                        items.add(new MTSItemInfo((Item) i, rse.getInt("price"), rse.getInt("id"), rse.getInt("seller"), rse.getString("sellername"), rse.getString("sell_ends")));
                    } else {
                        Equip equip = new Equip(rse.getInt("itemid"), (byte) rse.getInt("position"), -1);
                        equip.setOwner(rse.getString("owner"));
                        equip.setQuantity((short) 1);
                        equip.setAcc((short) rse.getInt("acc"));
                        equip.setAvoid((short) rse.getInt("avoid"));
                        equip.setDex((short) rse.getInt("dex"));
                        equip.setHands((short) rse.getInt("hands"));
                        equip.setHp((short) rse.getInt("hp"));
                        equip.setInt((short) rse.getInt("int"));
                        equip.setJump((short) rse.getInt("jump"));
                        equip.setVicious((short) rse.getInt("vicious"));
                        equip.setLuk((short) rse.getInt("luk"));
                        equip.setMatk((short) rse.getInt("matk"));
                        equip.setMdef((short) rse.getInt("mdef"));
                        equip.setMp((short) rse.getInt("mp"));
                        equip.setSpeed((short) rse.getInt("speed"));
                        equip.setStr((short) rse.getInt("str"));
                        equip.setWatk((short) rse.getInt("watk"));
                        equip.setWdef((short) rse.getInt("wdef"));
                        equip.setUpgradeSlots((byte) rse.getInt("upgradeslots"));
                        equip.setLevel((byte) rse.getInt("level"));
                        equip.setFlag((byte) rs.getInt("flag"));
                        items.add(new MTSItemInfo((Item) equip, rse.getInt("price"), rse.getInt("id"), rse.getInt("seller"), rse.getString("sellername"), rse.getString("sell_ends")));
                    }
                }
            }
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT COUNT(*) FROM mts_cart WHERE cid = ?");
        ps.setInt(1, cid);
        rs = ps.executeQuery();
        if (rs.next()) {
            pages = rs.getInt(1) / 16;
            if (rs.getInt(1) % 16 > 0) {
                pages += 1;
            }
        }
        rs.close();
        ps.close();
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return MaplePacketCreator.sendMTS(items, 4, 0, 0, pages);
}
Also used : Item(client.inventory.Item) Equip(client.inventory.Equip) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MTSItemInfo(server.MTSItemInfo) PreparedStatement(java.sql.PreparedStatement)

Example 9 with MTSItemInfo

use of server.MTSItemInfo in project HeavenMS by ronancpl.

the class MTSHandler method getTransfer.

public List<MTSItemInfo> getTransfer(int cid) {
    List<MTSItemInfo> items = new ArrayList<>();
    Connection con = null;
    PreparedStatement ps;
    ResultSet rs;
    try {
        con = DatabaseConnection.getConnection();
        ps = con.prepareStatement("SELECT * FROM mts_items WHERE transfer = 1 AND seller = ? ORDER BY id DESC");
        ps.setInt(1, cid);
        rs = ps.executeQuery();
        while (rs.next()) {
            if (rs.getInt("type") != 1) {
                Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
                i.setOwner(rs.getString("owner"));
                items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
            } else {
                Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
                equip.setOwner(rs.getString("owner"));
                equip.setQuantity((short) 1);
                equip.setAcc((short) rs.getInt("acc"));
                equip.setAvoid((short) rs.getInt("avoid"));
                equip.setDex((short) rs.getInt("dex"));
                equip.setHands((short) rs.getInt("hands"));
                equip.setHp((short) rs.getInt("hp"));
                equip.setInt((short) rs.getInt("int"));
                equip.setJump((short) rs.getInt("jump"));
                equip.setVicious((short) rs.getInt("vicious"));
                equip.setLuk((short) rs.getInt("luk"));
                equip.setMatk((short) rs.getInt("matk"));
                equip.setMdef((short) rs.getInt("mdef"));
                equip.setMp((short) rs.getInt("mp"));
                equip.setSpeed((short) rs.getInt("speed"));
                equip.setStr((short) rs.getInt("str"));
                equip.setWatk((short) rs.getInt("watk"));
                equip.setWdef((short) rs.getInt("wdef"));
                equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
                equip.setLevel((byte) rs.getInt("level"));
                equip.setFlag((byte) rs.getInt("flag"));
                items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
            }
        }
        rs.close();
        ps.close();
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return items;
}
Also used : Item(client.inventory.Item) Equip(client.inventory.Equip) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MTSItemInfo(server.MTSItemInfo) PreparedStatement(java.sql.PreparedStatement)

Example 10 with MTSItemInfo

use of server.MTSItemInfo in project HeavenMS by ronancpl.

the class EnterMTSHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!ServerConstants.USE_MTS) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (MapleMiniDungeonInfo.isDungeonMap(c.getPlayer().getMapId())) {
        c.announce(MaplePacketCreator.serverNotice(5, "Changing channels or entering Cash Shop or MTS are disabled when inside a Mini-Dungeon."));
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    MapleCharacter chr = c.getPlayer();
    if (!chr.isAlive()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (chr.getLevel() < 10) {
        c.announce(MaplePacketCreator.blockedMessage2(5));
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    chr.unregisterChairBuff();
    Server.getInstance().getPlayerBuffStorage().addBuffsToStorage(chr.getId(), chr.getAllBuffs());
    chr.setAwayFromWorld(true);
    chr.cancelAllBuffs(true);
    chr.cancelBuffExpireTask();
    chr.cancelDiseaseExpireTask();
    chr.cancelSkillCooldownTask();
    chr.cancelExpirationTask();
    chr.forfeitExpirableQuests();
    chr.cancelQuestExpirationTask();
    chr.saveToDB();
    chr.getMap().removePlayer(c.getPlayer());
    try {
        c.announce(MaplePacketCreator.openCashShop(c, true));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    // xD
    chr.getCashShop().open(true);
    c.announce(MaplePacketCreator.enableCSUse());
    c.announce(MaplePacketCreator.MTSWantedListingOver(0, 0));
    c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
    List<MTSItemInfo> items = new ArrayList<>();
    int pages = 0;
    try {
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = 1 AND transfer = 0 ORDER BY id DESC LIMIT 16, 16");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            if (rs.getInt("type") != 1) {
                Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
                i.setOwner(rs.getString("owner"));
                items.add(new MTSItemInfo(i, rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
            } else {
                Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
                equip.setOwner(rs.getString("owner"));
                equip.setQuantity((short) 1);
                equip.setAcc((short) rs.getInt("acc"));
                equip.setAvoid((short) rs.getInt("avoid"));
                equip.setDex((short) rs.getInt("dex"));
                equip.setHands((short) rs.getInt("hands"));
                equip.setHp((short) rs.getInt("hp"));
                equip.setInt((short) rs.getInt("int"));
                equip.setJump((short) rs.getInt("jump"));
                equip.setVicious((short) rs.getInt("vicious"));
                equip.setFlag((byte) rs.getInt("flag"));
                equip.setLuk((short) rs.getInt("luk"));
                equip.setMatk((short) rs.getInt("matk"));
                equip.setMdef((short) rs.getInt("mdef"));
                equip.setMp((short) rs.getInt("mp"));
                equip.setSpeed((short) rs.getInt("speed"));
                equip.setStr((short) rs.getInt("str"));
                equip.setWatk((short) rs.getInt("watk"));
                equip.setWdef((short) rs.getInt("wdef"));
                equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
                equip.setLevel((byte) rs.getInt("level"));
                items.add(new MTSItemInfo((Item) equip, rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
            }
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items");
        rs = ps.executeQuery();
        if (rs.next()) {
            pages = (int) Math.ceil(rs.getInt(1) / 16);
        }
        rs.close();
        ps.close();
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    c.announce(MaplePacketCreator.sendMTS(items, 1, 0, 0, pages));
    c.announce(MaplePacketCreator.transferInventory(getTransfer(chr.getId())));
    c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(chr.getId())));
}
Also used : Item(client.inventory.Item) Equip(client.inventory.Equip) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MTSItemInfo(server.MTSItemInfo) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Aggregations

MTSItemInfo (server.MTSItemInfo)11 Equip (client.inventory.Equip)8 Item (client.inventory.Item)8 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 SQLException (java.sql.SQLException)8 ArrayList (java.util.ArrayList)8 DatabaseConnection (tools.DatabaseConnection)8 Point (java.awt.Point)3 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)3 MapleItemInformationProvider (server.MapleItemInformationProvider)1