2
0

RequestExSetPledgeCrestLarge.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * Format : chdb
  26. * c (id) 0xD0
  27. * h (subid) 0x11
  28. * d data size
  29. * b raw data (picture i think ;) )
  30. * @author -Wooden-
  31. *
  32. */
  33. public final class RequestExSetPledgeCrestLarge extends L2GameClientPacket
  34. {
  35. private static final String _C__D0_11_REQUESTEXSETPLEDGECRESTLARGE = "[C] D0:11 RequestExSetPledgeCrestLarge";
  36. static Logger _log = Logger.getLogger(RequestExSetPledgeCrestLarge.class.getName());
  37. private int _length;
  38. private byte[] _data;
  39. @Override
  40. protected void readImpl()
  41. {
  42. _length = readD();
  43. if (_length > 2176)
  44. return;
  45. _data = new byte[_length];
  46. readB(_data);
  47. }
  48. /* (non-Javadoc)
  49. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#runImpl()
  50. */
  51. @Override
  52. protected void runImpl()
  53. {
  54. L2PcInstance activeChar = getClient().getActiveChar();
  55. if (activeChar == null)
  56. return;
  57. L2Clan clan = activeChar.getClan();
  58. if (clan == null)
  59. return;
  60. if (_length < 0)
  61. {
  62. activeChar.sendMessage("File transfer error.");
  63. return;
  64. }
  65. if (_length > 2176)
  66. {
  67. activeChar.sendMessage("The insignia file size is greater than 2176 bytes.");
  68. return;
  69. }
  70. boolean updated = false;
  71. int crestLargeId = -1;
  72. if ((_length == 0 || _data == null) && clan.getCrestLargeId() != 0)
  73. {
  74. crestLargeId = 0;
  75. activeChar.sendMessage("The insignia has been removed.");
  76. updated = true;
  77. }
  78. else if ((activeChar.getClanPrivileges() & L2Clan.CP_CL_REGISTER_CREST) == L2Clan.CP_CL_REGISTER_CREST)
  79. {
  80. if (clan.getHasCastle() == 0 && clan.getHasHideout() == 0)
  81. {
  82. activeChar.sendMessage("Only a clan that owns a clan hall or a castle can get their emblem displayed on clan related items"); //there is a system message for that but didnt found the id
  83. return;
  84. }
  85. crestLargeId = IdFactory.getInstance().getNextId();
  86. if (!CrestCache.getInstance().savePledgeCrestLarge(crestLargeId, _data))
  87. {
  88. _log.log(Level.INFO, "Error saving large crest for clan " + clan.getName() + " [" + clan.getClanId() + "]");
  89. return;
  90. }
  91. activeChar.sendPacket(new SystemMessage(SystemMessageId.CLAN_EMBLEM_WAS_SUCCESSFULLY_REGISTERED));
  92. updated = true;
  93. }
  94. if (updated && crestLargeId != -1)
  95. {
  96. clan.changeLargeCrest(crestLargeId);
  97. }
  98. }
  99. /* (non-Javadoc)
  100. * @see com.l2jserver.gameserver.BasePacket#getType()
  101. */
  102. @Override
  103. public String getType()
  104. {
  105. return _C__D0_11_REQUESTEXSETPLEDGECRESTLARGE;
  106. }
  107. }