RequestSetPledgeCrest.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.idfactory.IdFactory;
  20. import com.l2jserver.gameserver.model.L2Clan;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. /**
  25. * Client packet for setting/deleting clan crest.
  26. *
  27. */
  28. public final class RequestSetPledgeCrest extends L2GameClientPacket
  29. {
  30. private static final String _C__53_REQUESTSETPLEDGECREST = "[C] 53 RequestSetPledgeCrest";
  31. static Logger _log = Logger.getLogger(RequestSetPledgeCrest.class.getName());
  32. private int _length;
  33. private byte[] _data;
  34. @Override
  35. protected void readImpl()
  36. {
  37. _length = readD();
  38. if (_length > 256)
  39. return;
  40. _data = new byte[_length];
  41. readB(_data);
  42. }
  43. @Override
  44. protected void runImpl()
  45. {
  46. L2PcInstance activeChar = getClient().getActiveChar();
  47. if (activeChar == null)
  48. return;
  49. L2Clan clan = activeChar.getClan();
  50. if (clan == null)
  51. return;
  52. if (clan.getDissolvingExpiryTime() > System.currentTimeMillis())
  53. {
  54. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_SET_CREST_WHILE_DISSOLUTION_IN_PROGRESS));
  55. return;
  56. }
  57. if (_length < 0)
  58. {
  59. activeChar.sendMessage("File transfer error.");
  60. return;
  61. }
  62. if (_length > 256)
  63. {
  64. activeChar.sendMessage("The clan crest file size was too big (max 256 bytes).");
  65. return;
  66. }
  67. boolean updated = false;
  68. int crestId = -1;
  69. if ((_length == 0 || _data.length == 0) && clan.getCrestId() != 0)
  70. {
  71. crestId = 0;
  72. activeChar.sendPacket(new SystemMessage(SystemMessageId.CLAN_CREST_HAS_BEEN_DELETED));
  73. updated = true;
  74. }
  75. else if ((activeChar.getClanPrivileges() & L2Clan.CP_CL_REGISTER_CREST) == L2Clan.CP_CL_REGISTER_CREST)
  76. {
  77. if (clan.getLevel() < 3)
  78. {
  79. activeChar.sendPacket(new SystemMessage(SystemMessageId.CLAN_LVL_3_NEEDED_TO_SET_CREST));
  80. return;
  81. }
  82. crestId = IdFactory.getInstance().getNextId();
  83. if (!CrestCache.getInstance().savePledgeCrest(crestId, _data))
  84. {
  85. _log.log(Level.INFO, "Error saving crest for clan " + clan.getName() + " [" + clan.getClanId() + "]");
  86. return;
  87. }
  88. updated = true;
  89. }
  90. if (updated && crestId != -1)
  91. {
  92. clan.changeClanCrest(crestId);
  93. }
  94. }
  95. /* (non-Javadoc)
  96. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  97. */
  98. @Override
  99. public String getType()
  100. {
  101. return _C__53_REQUESTSETPLEDGECREST;
  102. }
  103. }