RequestFriendDel.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import com.l2jserver.L2DatabaseFactory;
  21. import com.l2jserver.gameserver.datatables.CharNameTable;
  22. import com.l2jserver.gameserver.model.L2World;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.FriendPacket;
  26. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  27. /**
  28. * This class ...
  29. *
  30. * @version $Revision: 1.3.4.2 $ $Date: 2005/03/27 15:29:30 $
  31. */
  32. public final class RequestFriendDel extends L2GameClientPacket{
  33. private static final String _C__61_REQUESTFRIENDDEL = "[C] 61 RequestFriendDel";
  34. private static Logger _log = Logger.getLogger(RequestFriendDel.class.getName());
  35. private String _name;
  36. @Override
  37. protected void readImpl()
  38. {
  39. _name = readS();
  40. }
  41. @Override
  42. protected void runImpl()
  43. {
  44. SystemMessage sm;
  45. L2PcInstance activeChar = getClient().getActiveChar();
  46. if (activeChar == null)
  47. return;
  48. int id = CharNameTable.getInstance().getIdByName(_name);
  49. if (id == -1)
  50. {
  51. sm = new SystemMessage(SystemMessageId.C1_NOT_ON_YOUR_FRIENDS_LIST);
  52. sm.addString(_name);
  53. activeChar.sendPacket(sm);
  54. return;
  55. }
  56. if (!activeChar.getFriendList().contains(id))
  57. {
  58. sm = new SystemMessage(SystemMessageId.C1_NOT_ON_YOUR_FRIENDS_LIST);
  59. sm.addString(_name);
  60. activeChar.sendPacket(sm);
  61. return;
  62. }
  63. Connection con = null;
  64. try
  65. {
  66. con = L2DatabaseFactory.getInstance().getConnection();
  67. PreparedStatement statement;
  68. statement = con.prepareStatement("DELETE FROM character_friends WHERE (charId=? AND friendId=?) OR (charId=? AND friendId=?)");
  69. statement.setInt(1, activeChar.getObjectId());
  70. statement.setInt(2, id);
  71. statement.setInt(3, id);
  72. statement.setInt(4, activeChar.getObjectId());
  73. statement.execute();
  74. statement.close();
  75. // Player deleted from your friendlist
  76. sm = new SystemMessage(SystemMessageId.S1_HAS_BEEN_DELETED_FROM_YOUR_FRIENDS_LIST);
  77. sm.addString(_name);
  78. activeChar.sendPacket(sm);
  79. activeChar.getFriendList().remove(new Integer(id));
  80. activeChar.sendPacket(new FriendPacket(false, id));
  81. L2PcInstance player = L2World.getInstance().getPlayer(_name);
  82. if (player != null)
  83. {
  84. player.getFriendList().remove(Integer.valueOf(activeChar.getObjectId()));
  85. player.sendPacket(new FriendPacket(false, activeChar.getObjectId()));
  86. }
  87. }
  88. catch (Exception e)
  89. {
  90. _log.log(Level.WARNING, "could not del friend objectid: ", e);
  91. }
  92. finally
  93. {
  94. try { con.close(); } catch (Exception e) {}
  95. }
  96. }
  97. @Override
  98. public String getType()
  99. {
  100. return _C__61_REQUESTFRIENDDEL;
  101. }
  102. }