public static List<DueyPackages> loadItems(MapleCharacter chr) { List<DueyPackages> packages = new LinkedList<DueyPackages>(); try { PreparedStatement ps = DatabaseConnection.getConnection() .prepareStatement( "SELECT * FROM dueypackages LEFT JOIN dueyitems USING (PackageId) WHERE RecieverId = ?"); // PLEASE WORK D: ps.setInt(1, chr.getId()); ResultSet rs = ps.executeQuery(); while (rs.next()) { DueyPackages dueypack = getItemByPID(rs); dueypack.setSender(rs.getString("SenderName")); dueypack.setMesos(rs.getInt("Mesos")); dueypack.setSentTime(rs.getString("TimeStamp")); packages.add(dueypack); } rs.close(); ps.close(); return packages; } catch (SQLException e) { return null; } }
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) { c.getPlayer().resetAfkTime(); 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 (amount < 0 || amount > 2000 || itemPos < 0 || inventId > 5 || inventId < 0) { return; } if (mesos < 0 || (long) mesos > Integer.MAX_VALUE || ((long) mesos + fee + getFee(mesos)) > Integer.MAX_VALUE) { 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()) { c.getPlayer().gainMeso(-finalcost, false); c.getSession() .write( MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SUCCESSFULLY_SENT.getCode())); send = true; } else { c.getSession() .write(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SAMEACC_ERROR.getCode())); } } else { c.getSession() .write( MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_NAME_DOES_NOT_EXIST.getCode())); } } else { c.getSession() .write(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_NOT_ENOUGH_MESOS.getCode())); } boolean recipientOn = false; MapleClient rClient = null; try { int channel = c.getChannelServer().getWorldInterface().find(recipient); if (channel > -1) { recipientOn = true; ChannelServer rcserv = ChannelServer.getInstance(channel); rClient = rcserv.getPlayerStorage().getCharacterByName(recipient).getClient(); } } catch (RemoteException re) { c.getChannelServer().reconnectWorld(); } if (send) { if (inventId > 0) { MapleInventoryType inv = MapleInventoryType.getByType(inventId); IItem item = c.getPlayer().getInventory(inv).getItem((byte) itemPos); if (item != null && c.getPlayer().getItemQuantity(item.getItemId(), false) > amount) { if (InventoryConstants.isRechargable(item.getItemId())) { MapleInventoryManipulator.removeFromSlot( c, inv, (byte) itemPos, item.getQuantity(), true); } else { MapleInventoryManipulator.removeFromSlot(c, inv, (byte) itemPos, amount, true, false); } addItemToDB( item, amount, mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false)); } else { return; } } else { addMesoToDB(mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false)); } if (recipientOn && rClient != null) { rClient .getSession() .write(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_PACKAGE_MSG.getCode())); } c.getPlayer().gainMeso(-fee, false); } } else if (operation == Actions.TOSERVER_REMOVE_PACKAGE.getCode()) { int packageid = slea.readInt(); removeItemFromDB(packageid); c.getSession().write(MaplePacketCreator.removeItemFromDuey(true, packageid)); } else if (operation == Actions.TOSERVER_CLAIM_PACKAGE.getCode()) { int packageid = slea.readInt(); List<DueyPackages> packages = new LinkedList<DueyPackages>(); DueyPackages dp = null; Connection con = DatabaseConnection.getConnection(); try { PreparedStatement ps = con.prepareStatement( "SELECT * FROM dueypackages LEFT JOIN dueyitems USING (PackageId) WHERE PackageId = ?"); // PLEASE WORK D: ps.setInt(1, packageid); ResultSet rs = ps.executeQuery(); DueyPackages 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); } rs.close(); ps.close(); dp = dueypack; } catch (SQLException e) { } if (dp.getItem() != null) { if (!MapleInventoryManipulator.checkSpace( c, dp.getItem().getItemId(), dp.getItem().getQuantity(), dp.getItem().getOwner())) { c.getPlayer().dropMessage(1, "Your inventory is full"); c.getSession().write(MaplePacketCreator.enableActions()); return; } else { MapleInventoryManipulator.addFromDrop(c, dp.getItem(), false); } } int gainmesos = 0; long totalmesos = (long) dp.getMesos() + (long) c.getPlayer().getMeso(); if (totalmesos >= Integer.MAX_VALUE) { gainmesos = 2147383647 - c.getPlayer().getMeso(); } else if (totalmesos < 0 || dp.getMesos() < 0) { // do nothing } else { c.getPlayer().gainMeso(gainmesos, false); } removeItemFromDB(packageid); c.getSession().write(MaplePacketCreator.removeItemFromDuey(false, packageid)); } }