RequestHennaEquip.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. L2Henna template = HennaTable.getInstance().getTemplate(_symbolId);
  53. if (template == null)
  54. return;
  55. L2HennaInstance henna = new L2HennaInstance(template);
  56. long _count = 0;
  57. /**
  58. * Prevents henna drawing exploit:
  59. * 1) talk to L2SymbolMakerInstance
  60. * 2) RequestHennaList
  61. * 3) Don't close the window and go to a GrandMaster and change your subclass
  62. * 4) Get SymbolMaker range again and press draw
  63. * You could draw any kind of henna just having the required subclass...
  64. */
  65. boolean cheater = true;
  66. for (L2HennaInstance h : HennaTreeTable.getInstance().getAvailableHenna(activeChar.getClassId()))
  67. {
  68. if (h.getSymbolId() == henna.getSymbolId())
  69. {
  70. cheater = false;
  71. break;
  72. }
  73. }
  74. try
  75. {
  76. _count = activeChar.getInventory().getItemByItemId(henna.getItemIdDye()).getCount();
  77. }
  78. catch(Exception e){}
  79. if (activeChar.getHennaEmptySlots() == 0)
  80. {
  81. activeChar.sendPacket(new SystemMessage(SystemMessageId.SYMBOLS_FULL));
  82. return;
  83. }
  84. if (!cheater && (_count >= henna.getAmountDyeRequire()) && (activeChar.getAdena() >= henna.getPrice()) && activeChar.addHenna(henna))
  85. {
  86. activeChar.destroyItemByItemId("Henna", henna.getItemIdDye(), henna.getAmountDyeRequire(), activeChar, true);
  87. activeChar.getInventory().reduceAdena("Henna", henna.getPrice(), activeChar, activeChar.getLastFolkNPC());
  88. InventoryUpdate iu = new InventoryUpdate();
  89. iu.addModifiedItem(activeChar.getInventory().getAdenaInstance());
  90. activeChar.sendPacket(iu);
  91. activeChar.sendPacket(new SystemMessage(SystemMessageId.SYMBOL_ADDED));
  92. }
  93. else
  94. {
  95. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_DRAW_SYMBOL));
  96. if ((!activeChar.isGM()) && (cheater))
  97. Util.handleIllegalPlayerAction(activeChar,"Exploit attempt: Character "+activeChar.getName()+" of account "+activeChar.getAccountName()+" tryed to add a forbidden henna.",Config.DEFAULT_PUNISH);
  98. }
  99. }
  100. /* (non-Javadoc)
  101. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  102. */
  103. @Override
  104. public String getType()
  105. {
  106. return _C__BC_RequestHennaEquip;
  107. }
  108. }