RequestSetAllyCrest.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.ClanTable;
  21. import com.l2jserver.gameserver.data.sql.impl.CrestTable;
  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 ally crest.
  29. */
  30. public final class RequestSetAllyCrest extends L2GameClientPacket
  31. {
  32. private static final String _C__91_REQUESTSETALLYCREST = "[C] 91 RequestSetAllyCrest";
  33. private int _length;
  34. private byte[] _data = null;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _length = readD();
  39. if (_length > 192)
  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.sendMessage("File transfer error.");
  57. return;
  58. }
  59. if (_length > 192)
  60. {
  61. activeChar.sendPacket(SystemMessageId.ADJUST_IMAGE_8_12);
  62. return;
  63. }
  64. if (activeChar.getAllyId() == 0)
  65. {
  66. activeChar.sendPacket(SystemMessageId.FEATURE_ONLY_FOR_ALLIANCE_LEADER);
  67. return;
  68. }
  69. final L2Clan leaderClan = ClanTable.getInstance().getClan(activeChar.getAllyId());
  70. if ((activeChar.getClanId() != leaderClan.getId()) || !activeChar.isClanLeader())
  71. {
  72. activeChar.sendPacket(SystemMessageId.FEATURE_ONLY_FOR_ALLIANCE_LEADER);
  73. return;
  74. }
  75. if (_length == 0)
  76. {
  77. if (leaderClan.getAllyCrestId() != 0)
  78. {
  79. leaderClan.changeAllyCrest(0, false);
  80. }
  81. }
  82. else
  83. {
  84. final L2Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.ALLY);
  85. if (crest != null)
  86. {
  87. leaderClan.changeAllyCrest(crest.getId(), false);
  88. activeChar.sendPacket(SystemMessageId.CLAN_CREST_WAS_SUCCESSFULLY_REGISTRED);
  89. }
  90. }
  91. }
  92. @Override
  93. public String getType()
  94. {
  95. return _C__91_REQUESTSETALLYCREST;
  96. }
  97. }