RequestExSetPledgeCrestLarge.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 net.sf.l2j.gameserver.clientpackets;
  16. import java.sql.PreparedStatement;
  17. import java.sql.SQLException;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import net.sf.l2j.L2DatabaseFactory;
  21. import net.sf.l2j.gameserver.cache.CrestCache;
  22. import net.sf.l2j.gameserver.idfactory.IdFactory;
  23. import net.sf.l2j.gameserver.model.L2Clan;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.network.SystemMessageId;
  26. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  27. /**
  28. * Format : chdb
  29. * c (id) 0xD0
  30. * h (subid) 0x11
  31. * d data size
  32. * b raw data (picture i think ;) )
  33. * @author -Wooden-
  34. *
  35. */
  36. public final class RequestExSetPledgeCrestLarge extends L2GameClientPacket
  37. {
  38. private static final String _C__D0_11_REQUESTEXSETPLEDGECRESTLARGE = "[C] D0:11 RequestExSetPledgeCrestLarge";
  39. static Logger _log = Logger.getLogger(RequestExSetPledgeCrestLarge.class.getName());
  40. private int _size;
  41. private byte[] _data;
  42. @Override
  43. protected void readImpl()
  44. {
  45. _size = readD();
  46. if(_size > 2176)
  47. return;
  48. if(_size > 0) // client CAN send a RequestExSetPledgeCrestLarge with the size set to 0 then format is just chd
  49. {
  50. _data = new byte[_size];
  51. readB(_data);
  52. }
  53. }
  54. /* (non-Javadoc)
  55. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#runImpl()
  56. */
  57. @Override
  58. protected
  59. void runImpl()
  60. {
  61. L2PcInstance activeChar = getClient().getActiveChar();
  62. if (activeChar == null) return;
  63. L2Clan clan = activeChar.getClan();
  64. if (clan == null) return;
  65. if (_data == null)
  66. {
  67. CrestCache.getInstance().removePledgeCrestLarge(clan.getCrestId());
  68. clan.setHasCrestLarge(false);
  69. activeChar.sendMessage("The insignia has been removed.");
  70. for (L2PcInstance member : clan.getOnlineMembers(0))
  71. member.broadcastUserInfo();
  72. return;
  73. }
  74. if (_size > 2176)
  75. {
  76. activeChar.sendMessage("The insignia file size is greater than 2176 bytes.");
  77. return;
  78. }
  79. if ((activeChar.getClanPrivileges() & L2Clan.CP_CL_REGISTER_CREST) == L2Clan.CP_CL_REGISTER_CREST)
  80. {
  81. if(clan.getHasCastle() == 0 && clan.getHasHideout() == 0)
  82. {
  83. 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
  84. return;
  85. }
  86. CrestCache crestCache = CrestCache.getInstance();
  87. int newId = IdFactory.getInstance().getNextId();
  88. if (!crestCache.savePledgeCrestLarge(newId,_data))
  89. {
  90. _log.log(Level.INFO, "Error loading large crest of clan:" + clan.getName());
  91. return;
  92. }
  93. if (clan.hasCrestLarge())
  94. {
  95. crestCache.removePledgeCrestLarge(clan.getCrestLargeId());
  96. }
  97. java.sql.Connection con = null;
  98. try
  99. {
  100. con = L2DatabaseFactory.getInstance().getConnection();
  101. PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_large_id = ? WHERE clan_id = ?");
  102. statement.setInt(1, newId);
  103. statement.setInt(2, clan.getClanId());
  104. statement.executeUpdate();
  105. statement.close();
  106. }
  107. catch (SQLException e)
  108. {
  109. _log.warning("could not update the large crest id:"+e.getMessage());
  110. }
  111. finally
  112. {
  113. try { con.close(); } catch (Exception e) {}
  114. }
  115. clan.setCrestLargeId(newId);
  116. clan.setHasCrestLarge(true);
  117. activeChar.sendPacket(new SystemMessage(SystemMessageId.CLAN_EMBLEM_WAS_SUCCESSFULLY_REGISTERED));
  118. for (L2PcInstance member : clan.getOnlineMembers(0))
  119. member.broadcastUserInfo();
  120. }
  121. }
  122. /* (non-Javadoc)
  123. * @see net.sf.l2j.gameserver.BasePacket#getType()
  124. */
  125. @Override
  126. public String getType()
  127. {
  128. return _C__D0_11_REQUESTEXSETPLEDGECRESTLARGE;
  129. }
  130. }