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