RequestPrivateStoreSell.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.clientpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.model.ItemRequest;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2World;
  21. import net.sf.l2j.gameserver.model.TradeList;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  23. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  24. import net.sf.l2j.gameserver.util.Util;
  25. /**
  26. * This class ...
  27. *
  28. * @version $Revision: 1.2.2.1.2.4 $ $Date: 2005/03/27 15:29:30 $
  29. */
  30. public final class RequestPrivateStoreSell extends L2GameClientPacket
  31. {
  32. // private static final String _C__96_SENDPRIVATESTOREBUYBUYLIST = "[C] 96 SendPrivateStoreBuyBuyList";
  33. private static final String _C__96_REQUESTPRIVATESTORESELL = "[C] 96 RequestPrivateStoreSell";
  34. private static Logger _log = Logger.getLogger(RequestPrivateStoreSell.class.getName());
  35. private int _storePlayerId;
  36. private int _count;
  37. private int _price;
  38. private ItemRequest[] _items;
  39. @Override
  40. protected void readImpl()
  41. {
  42. _storePlayerId = readD();
  43. _count = readD();
  44. // count*20 is the size of a for iteration of each item
  45. if (_count < 0 || _count * 20 > _buf.remaining() || _count > Config.MAX_ITEM_IN_PACKET)
  46. _count = 0;
  47. _items = new ItemRequest[_count];
  48. long priceTotal = 0;
  49. for (int i = 0; i < _count; i++)
  50. {
  51. int objectId = readD();
  52. int itemId = readD();
  53. readH(); //TODO analyse this
  54. readH(); //TODO analyse this
  55. long count = readD();
  56. int price = readD();
  57. if (count > Integer.MAX_VALUE || count < 0)
  58. {
  59. String msgErr = "[RequestPrivateStoreSell] player "+getClient().getActiveChar().getName()+" tried an overflow exploit, ban this player!";
  60. Util.handleIllegalPlayerAction(getClient().getActiveChar(),msgErr,Config.DEFAULT_PUNISH);
  61. _count = 0;
  62. _items = null;
  63. return;
  64. }
  65. _items[i] = new ItemRequest(objectId, itemId, (int)count, price);
  66. priceTotal += price * count;
  67. }
  68. if(priceTotal < 0 || priceTotal > Integer.MAX_VALUE)
  69. {
  70. String msgErr = "[RequestPrivateStoreSell] player "+getClient().getActiveChar().getName()+" tried an overflow exploit, ban this player!";
  71. Util.handleIllegalPlayerAction(getClient().getActiveChar(),msgErr,Config.DEFAULT_PUNISH);
  72. _count = 0;
  73. _items = null;
  74. return;
  75. }
  76. _price = (int)priceTotal;
  77. }
  78. @Override
  79. protected void runImpl()
  80. {
  81. L2PcInstance player = getClient().getActiveChar();
  82. if (player == null) return;
  83. L2Object object = L2World.getInstance().findObject(_storePlayerId);
  84. if (!(object instanceof L2PcInstance)) return;
  85. L2PcInstance storePlayer = (L2PcInstance)object;
  86. if (storePlayer.getPrivateStoreType() != L2PcInstance.STORE_PRIVATE_BUY) return;
  87. if(player.isCursedWeaponEquipped())
  88. return;
  89. TradeList storeList = storePlayer.getBuyList();
  90. if (storeList == null) return;
  91. if (!player.getAccessLevel().allowTransaction())
  92. {
  93. player.sendMessage("Transactions are disable for your Access Level");
  94. sendPacket(ActionFailed.STATIC_PACKET);
  95. return;
  96. }
  97. if (storePlayer.getAdena() < _price)
  98. {
  99. sendPacket(ActionFailed.STATIC_PACKET);
  100. storePlayer.sendMessage("You have not enough adena, canceling PrivateBuy.");
  101. storePlayer.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
  102. storePlayer.broadcastUserInfo();
  103. return;
  104. }
  105. if (!storeList.privateStoreSell(player, _items, _price))
  106. {
  107. sendPacket(ActionFailed.STATIC_PACKET);
  108. _log.warning("PrivateStore sell has failed due to invalid list or request. Player: " + player.getName() + ", Private store of: " + storePlayer.getName());
  109. return;
  110. }
  111. if (storeList.getItemCount() == 0)
  112. {
  113. storePlayer.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
  114. storePlayer.broadcastUserInfo();
  115. }
  116. }
  117. @Override
  118. public String getType()
  119. {
  120. return _C__96_REQUESTPRIVATESTORESELL;
  121. }
  122. }