RequestHennaEquip.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 com.l2jserver.gameserver.network.clientpackets;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.datatables.HennaTable;
  18. import com.l2jserver.gameserver.datatables.HennaTreeTable;
  19. import com.l2jserver.gameserver.model.L2HennaInstance;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. import com.l2jserver.gameserver.templates.item.L2Henna;
  25. import com.l2jserver.gameserver.util.Util;
  26. /**
  27. * This class ...
  28. *
  29. * @version $Revision$ $Date$
  30. */
  31. public final class RequestHennaEquip extends L2GameClientPacket
  32. {
  33. private static final String _C__BC_RequestHennaEquip = "[C] bc RequestHennaEquip";
  34. private int _symbolId;
  35. // format cd
  36. /**
  37. * packet type id 0xbb
  38. * format: cd
  39. * @param decrypt
  40. */
  41. @Override
  42. protected void readImpl()
  43. {
  44. _symbolId = readD();
  45. }
  46. @Override
  47. protected void runImpl()
  48. {
  49. L2PcInstance activeChar = getClient().getActiveChar();
  50. if (activeChar == null)
  51. return;
  52. if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("HennaEquip"))
  53. return;
  54. L2Henna template = HennaTable.getInstance().getTemplate(_symbolId);
  55. if (template == null)
  56. return;
  57. L2HennaInstance henna = new L2HennaInstance(template);
  58. long _count = 0;
  59. /**
  60. * Prevents henna drawing exploit:
  61. * 1) talk to L2SymbolMakerInstance
  62. * 2) RequestHennaList
  63. * 3) Don't close the window and go to a GrandMaster and change your subclass
  64. * 4) Get SymbolMaker range again and press draw
  65. * You could draw any kind of henna just having the required subclass...
  66. */
  67. boolean cheater = true;
  68. for (L2HennaInstance h : HennaTreeTable.getInstance().getAvailableHenna(activeChar.getClassId()))
  69. {
  70. if (h.getSymbolId() == henna.getSymbolId())
  71. {
  72. cheater = false;
  73. break;
  74. }
  75. }
  76. try
  77. {
  78. _count = activeChar.getInventory().getItemByItemId(henna.getItemIdDye()).getCount();
  79. }
  80. catch(Exception e){}
  81. if (activeChar.getHennaEmptySlots() == 0)
  82. {
  83. activeChar.sendPacket(new SystemMessage(SystemMessageId.SYMBOLS_FULL));
  84. return;
  85. }
  86. if (!cheater && (_count >= henna.getAmountDyeRequire()) && (activeChar.getAdena() >= henna.getPrice()) && activeChar.addHenna(henna))
  87. {
  88. activeChar.destroyItemByItemId("Henna", henna.getItemIdDye(), henna.getAmountDyeRequire(), activeChar, true);
  89. activeChar.getInventory().reduceAdena("Henna", henna.getPrice(), activeChar, activeChar.getLastFolkNPC());
  90. InventoryUpdate iu = new InventoryUpdate();
  91. iu.addModifiedItem(activeChar.getInventory().getAdenaInstance());
  92. activeChar.sendPacket(iu);
  93. activeChar.sendPacket(new SystemMessage(SystemMessageId.SYMBOL_ADDED));
  94. }
  95. else
  96. {
  97. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_DRAW_SYMBOL));
  98. if ((!activeChar.isGM()) && (cheater))
  99. Util.handleIllegalPlayerAction(activeChar,"Exploit attempt: Character "+activeChar.getName()+" of account "+activeChar.getAccountName()+" tryed to add a forbidden henna.",Config.DEFAULT_PUNISH);
  100. }
  101. }
  102. /* (non-Javadoc)
  103. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  104. */
  105. @Override
  106. public String getType()
  107. {
  108. return _C__BC_RequestHennaEquip;
  109. }
  110. }