RequestSetAllyCrest.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 java.util.logging.Level;
  17. import java.util.logging.Logger;
  18. import com.l2jserver.gameserver.cache.CrestCache;
  19. import com.l2jserver.gameserver.datatables.ClanTable;
  20. import com.l2jserver.gameserver.idfactory.IdFactory;
  21. import com.l2jserver.gameserver.model.L2Clan;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. /**
  24. * Client packet for setting ally crest.
  25. *
  26. */
  27. public final class RequestSetAllyCrest extends L2GameClientPacket
  28. {
  29. private static final String _C__87_REQUESTSETALLYCREST = "[C] 87 RequestSetAllyCrest";
  30. static Logger _log = Logger.getLogger(RequestSetAllyCrest.class.getName());
  31. private int _length;
  32. private byte[] _data;
  33. @Override
  34. protected void readImpl()
  35. {
  36. _length = readD();
  37. if (_length > 192)
  38. return;
  39. _data = new byte[_length];
  40. readB(_data);
  41. }
  42. @Override
  43. protected void runImpl()
  44. {
  45. L2PcInstance activeChar = getClient().getActiveChar();
  46. if (activeChar == null)
  47. return;
  48. if (_length < 0)
  49. {
  50. activeChar.sendMessage("File transfer error.");
  51. return;
  52. }
  53. if (_length > 192)
  54. {
  55. activeChar.sendMessage("The ally crest file size was too big (max 192 bytes).");
  56. return;
  57. }
  58. if (activeChar.getAllyId() != 0)
  59. {
  60. L2Clan leaderclan = ClanTable.getInstance().getClan(activeChar.getAllyId());
  61. if (activeChar.getClanId() != leaderclan.getClanId() || !activeChar.isClanLeader())
  62. {
  63. return;
  64. }
  65. boolean remove = false;
  66. if (_length == 0 || _data.length == 0)
  67. remove = true;
  68. int newId = 0;
  69. if (!remove)
  70. newId = IdFactory.getInstance().getNextId();
  71. if (!remove && !CrestCache.getInstance().saveAllyCrest(newId, _data))
  72. {
  73. _log.log(Level.INFO, "Error saving crest for ally " + leaderclan.getAllyName() + " [" + leaderclan.getAllyId() + "]");
  74. return;
  75. }
  76. leaderclan.changeAllyCrest(newId, false);
  77. }
  78. }
  79. /* (non-Javadoc)
  80. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  81. */
  82. @Override
  83. public String getType()
  84. {
  85. return _C__87_REQUESTSETALLYCREST;
  86. }
  87. }