ClanWarsList.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 handlers.usercommandhandlers;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import com.l2jserver.L2DatabaseFactory;
  21. import com.l2jserver.gameserver.handler.IUserCommandHandler;
  22. import com.l2jserver.gameserver.model.L2Clan;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. /**
  27. * Support for /clanwarlist command
  28. * @author Tempy
  29. */
  30. public class ClanWarsList implements IUserCommandHandler
  31. {
  32. private static final Logger _log = Logger.getLogger(ClanWarsList.class.getName());
  33. private static final int[] COMMAND_IDS =
  34. {
  35. 88, 89, 90
  36. };
  37. /**
  38. *
  39. * @see com.l2jserver.gameserver.handler.IUserCommandHandler#useUserCommand(int, com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  40. */
  41. public boolean useUserCommand(int id, L2PcInstance activeChar)
  42. {
  43. if (id != COMMAND_IDS[0] && id != COMMAND_IDS[1] && id != COMMAND_IDS[2])
  44. return false;
  45. L2Clan clan = activeChar.getClan();
  46. if (clan == null)
  47. {
  48. activeChar.sendMessage("You are not in a clan.");
  49. return false;
  50. }
  51. SystemMessage sm;
  52. java.sql.Connection con = null;
  53. try
  54. {
  55. con = L2DatabaseFactory.getInstance().getConnection();
  56. PreparedStatement statement;
  57. if (id == 88)
  58. {
  59. // Attack List
  60. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CLANS_YOU_DECLARED_WAR_ON));
  61. statement = con.prepareStatement("select clan_name,clan_id,ally_id,ally_name from clan_data,clan_wars where clan1=? and clan_id=clan2 and clan2 not in (select clan1 from clan_wars where clan2=?)");
  62. statement.setInt(1, clan.getClanId());
  63. statement.setInt(2, clan.getClanId());
  64. }
  65. else if (id == 89)
  66. {
  67. // Under Attack List
  68. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CLANS_THAT_HAVE_DECLARED_WAR_ON_YOU));
  69. statement = con.prepareStatement("select clan_name,clan_id,ally_id,ally_name from clan_data,clan_wars where clan2=? and clan_id=clan1 and clan1 not in (select clan2 from clan_wars where clan1=?)");
  70. statement.setInt(1, clan.getClanId());
  71. statement.setInt(2, clan.getClanId());
  72. }
  73. else
  74. // ID = 90
  75. {
  76. // War List
  77. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.WAR_LIST));
  78. statement = con.prepareStatement("select clan_name,clan_id,ally_id,ally_name from clan_data,clan_wars where clan1=? and clan_id=clan2 and clan2 in (select clan1 from clan_wars where clan2=?)");
  79. statement.setInt(1, clan.getClanId());
  80. statement.setInt(2, clan.getClanId());
  81. }
  82. ResultSet rset = statement.executeQuery();
  83. while (rset.next())
  84. {
  85. String clanName = rset.getString("clan_name");
  86. int ally_id = rset.getInt("ally_id");
  87. if (ally_id > 0)
  88. {
  89. // Target With Ally
  90. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_S2_ALLIANCE);
  91. sm.addString(clanName);
  92. sm.addString(rset.getString("ally_name"));
  93. }
  94. else
  95. {
  96. // Target Without Ally
  97. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_NO_ALLI_EXISTS);
  98. sm.addString(clanName);
  99. }
  100. activeChar.sendPacket(sm);
  101. }
  102. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FRIEND_LIST_FOOTER));
  103. rset.close();
  104. statement.close();
  105. }
  106. catch (Exception e)
  107. {
  108. _log.log(Level.WARNING, "", e);
  109. }
  110. finally
  111. {
  112. L2DatabaseFactory.close(con);
  113. }
  114. return true;
  115. }
  116. /**
  117. *
  118. * @see com.l2jserver.gameserver.handler.IUserCommandHandler#getUserCommandList()
  119. */
  120. public int[] getUserCommandList()
  121. {
  122. return COMMAND_IDS;
  123. }
  124. }