BuyCSItemHandler.java
Upload User: gwt600
Upload Date: 2021-06-03
Package Size: 704k
Code Size: 5k
Category:

Games

Development Platform:

Java

  1. /*
  2. This file is part of the OdinMS Maple Story Server
  3. Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc> 
  4. Matthias Butz <matze@odinms.de>
  5. Jan Christian Meyer <vimes@odinms.de>
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License version 3
  8. as published by the Free Software Foundation. You may not use, modify
  9. or distribute this program under any other version of the
  10. GNU Affero General Public License.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18. package net.sf.odinms.net.channel.handler;
  19. import java.sql.Connection;
  20. import java.sql.PreparedStatement;
  21. import java.sql.SQLException;
  22. import net.sf.odinms.client.MapleCharacter;
  23. import net.sf.odinms.client.MapleClient;
  24. import net.sf.odinms.client.MaplePet;
  25. import net.sf.odinms.client.MapleRing;
  26. import net.sf.odinms.database.DatabaseConnection;
  27. import net.sf.odinms.net.AbstractMaplePacketHandler;
  28. import net.sf.odinms.server.AutobanManager;
  29. import net.sf.odinms.server.CashItemFactory;
  30. import net.sf.odinms.server.CashItemInfo;
  31. import net.sf.odinms.server.MapleInventoryManipulator;
  32. import net.sf.odinms.tools.MaplePacketCreator;
  33. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  34. /**
  35.  *
  36.  * @author Acrylic (Terry Han)
  37.  */
  38. public class BuyCSItemHandler extends AbstractMaplePacketHandler {
  39.     @Override
  40.     public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  41.         System.out.println(slea.toString());
  42.         int action = slea.readByte();
  43.         if (action == 3) {
  44.             slea.skip(1);
  45.             int useNX = slea.readInt();
  46.             int snCS = slea.readInt();
  47.             CashItemInfo item = CashItemFactory.getItem(snCS);
  48.             if (c.getPlayer().getCSPoints(useNX) >= item.getPrice()) {
  49.                 c.getPlayer().modifyCSPoints(useNX, -item.getPrice());
  50.             } else {
  51.                 c.getSession().write(MaplePacketCreator.enableActions());
  52.                 AutobanManager.getInstance().autoban(c, "Trying to purchase from the CS when they have no NX");
  53.                 return;
  54.             }
  55.             if(item.getId() >= 5390000 && item.getId() <= 5390002){
  56.                 c.getPlayer().dropMessage(1, "You may not purchase this item");
  57.                 return;
  58.             }
  59.             if (item.getId() >= 5000000 && item.getId() <= 5000100) {
  60.                 int petId = MaplePet.createPet(item.getId());
  61.                 if (petId == -1) {
  62.                     return;
  63.                 }
  64.                 MapleInventoryManipulator.addById(c, item.getId(), (short) 1, null, petId);
  65.             } else {
  66.                 MapleInventoryManipulator.addById(c, item.getId(), (short) item.getCount());
  67.             }
  68.             c.getSession().write(MaplePacketCreator.showBoughtCSItem(item.getId()));
  69.             c.getSession().write(MaplePacketCreator.showNXMapleTokens(c.getPlayer()));
  70.             c.getSession().write(MaplePacketCreator.enableCSUse0());
  71.             c.getSession().write(MaplePacketCreator.enableCSUse1());
  72.             c.getSession().write(MaplePacketCreator.enableCSUse2());
  73.             c.getSession().write(MaplePacketCreator.enableActions());
  74.         } else if (action == 5) {
  75.             try {
  76.                 Connection con = DatabaseConnection.getConnection();
  77.                 PreparedStatement ps = con.prepareStatement("DELETE FROM wishlist WHERE charid = ?");
  78.                 ps.setInt(1, c.getPlayer().getId());
  79.                 ps.executeUpdate();
  80.                 ps.close();
  81.                 int i = 10;
  82.                 while (i > 0) {
  83.                     int sn = slea.readInt();
  84.                     if (sn != 0) {
  85.                         ps = con.prepareStatement("INSERT INTO wishlist(charid, sn) VALUES(?, ?) ");
  86.                         ps.setInt(1, c.getPlayer().getId());
  87.                         ps.setInt(2, sn);
  88.                         ps.executeUpdate();
  89.                         ps.close();
  90.                     }
  91.                     i--;
  92.                 }
  93.             } catch (SQLException se) {
  94.             }
  95.             c.getSession().write(MaplePacketCreator.sendWishList(c.getPlayer().getId(), true));
  96.         } else if (action == 30) {
  97.             int snCS = slea.readInt();
  98.             CashItemInfo item = CashItemFactory.getItem(snCS);
  99.             if (c.getPlayer().getMeso() >= item.getPrice()) {
  100.                 c.getPlayer().gainMeso(-item.getPrice(), false);
  101.                 MapleInventoryManipulator.addById(c, item.getId(), (short) item.getCount());
  102.            //     MapleInventory etcInventory = c.getPlayer().getInventory(MapleInventoryType.ETC);
  103.            //     byte slot = etcInventory.findById(item.getId()).getPosition();
  104.            //    c.getSession().write(MaplePacketCreator.showBoughtCSQuestItem(slot, item.getId()));
  105.             } else {
  106.                 AutobanManager.getInstance().autoban(c, "Trying to purchase from the CS with an insufficient amount");
  107.                 return;
  108.             }
  109.         }
  110.     }
  111. }