RequestSetPledgeCrest.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.gameserver.data.sql.impl.CrestTable;
  21. import com.l2jserver.gameserver.model.ClanPrivilege;
  22. import com.l2jserver.gameserver.model.L2Clan;
  23. import com.l2jserver.gameserver.model.L2Crest;
  24. import com.l2jserver.gameserver.model.L2Crest.CrestType;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. /**
  28. * Client packet for setting/deleting clan crest.
  29. */
  30. public final class RequestSetPledgeCrest extends L2GameClientPacket
  31. {
  32. private static final String _C__09_REQUESTSETPLEDGECREST = "[C] 09 RequestSetPledgeCrest";
  33. private int _length;
  34. private byte[] _data = null;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _length = readD();
  39. if (_length > 256)
  40. {
  41. return;
  42. }
  43. _data = new byte[_length];
  44. readB(_data);
  45. }
  46. @Override
  47. protected void runImpl()
  48. {
  49. final L2PcInstance activeChar = getClient().getActiveChar();
  50. if (activeChar == null)
  51. {
  52. return;
  53. }
  54. if ((_length < 0))
  55. {
  56. activeChar.sendPacket(SystemMessageId.WRONG_SIZE_UPLOADED_CREST);
  57. return;
  58. }
  59. if (_length > 256)
  60. {
  61. activeChar.sendPacket(SystemMessageId.THE_SIZE_OF_THE_IMAGE_FILE_IS_INAPPROPRIATE);
  62. return;
  63. }
  64. final L2Clan clan = activeChar.getClan();
  65. if (clan == null)
  66. {
  67. return;
  68. }
  69. if (clan.getDissolvingExpiryTime() > System.currentTimeMillis())
  70. {
  71. activeChar.sendPacket(SystemMessageId.CANNOT_SET_CREST_WHILE_DISSOLUTION_IN_PROGRESS);
  72. return;
  73. }
  74. if (!activeChar.hasClanPrivilege(ClanPrivilege.CL_REGISTER_CREST))
  75. {
  76. activeChar.sendPacket(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
  77. return;
  78. }
  79. if (_length == 0)
  80. {
  81. if (clan.getCrestId() != 0)
  82. {
  83. clan.changeClanCrest(0);
  84. activeChar.sendPacket(SystemMessageId.CLAN_CREST_HAS_BEEN_DELETED);
  85. }
  86. }
  87. else
  88. {
  89. if (clan.getLevel() < 3)
  90. {
  91. activeChar.sendPacket(SystemMessageId.CLAN_LVL_3_NEEDED_TO_SET_CREST);
  92. return;
  93. }
  94. final L2Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.PLEDGE);
  95. if (crest != null)
  96. {
  97. clan.changeClanCrest(crest.getId());
  98. activeChar.sendPacket(SystemMessageId.CLAN_CREST_WAS_SUCCESSFULLY_REGISTRED);
  99. }
  100. }
  101. }
  102. @Override
  103. public String getType()
  104. {
  105. return _C__09_REQUESTSETPLEDGECREST;
  106. }
  107. }