RequestFriendDel.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.util.logging.Level;
  23. import com.l2jserver.L2DatabaseFactory;
  24. import com.l2jserver.gameserver.data.sql.impl.CharNameTable;
  25. import com.l2jserver.gameserver.model.L2World;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.FriendPacket;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. /**
  31. * This class ...
  32. * @version $Revision: 1.3.4.2 $ $Date: 2005/03/27 15:29:30 $
  33. */
  34. public final class RequestFriendDel extends L2GameClientPacket
  35. {
  36. private static final String _C__7A_REQUESTFRIENDDEL = "[C] 7A RequestFriendDel";
  37. private String _name;
  38. @Override
  39. protected void readImpl()
  40. {
  41. _name = readS();
  42. }
  43. @Override
  44. protected void runImpl()
  45. {
  46. SystemMessage sm;
  47. L2PcInstance activeChar = getClient().getActiveChar();
  48. if (activeChar == null)
  49. {
  50. return;
  51. }
  52. int id = CharNameTable.getInstance().getIdByName(_name);
  53. if (id == -1)
  54. {
  55. sm = SystemMessage.getSystemMessage(SystemMessageId.C1_NOT_ON_YOUR_FRIENDS_LIST);
  56. sm.addString(_name);
  57. activeChar.sendPacket(sm);
  58. return;
  59. }
  60. if (!activeChar.getFriendList().contains(id))
  61. {
  62. sm = SystemMessage.getSystemMessage(SystemMessageId.C1_NOT_ON_YOUR_FRIENDS_LIST);
  63. sm.addString(_name);
  64. activeChar.sendPacket(sm);
  65. return;
  66. }
  67. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  68. PreparedStatement statement = con.prepareStatement("DELETE FROM character_friends WHERE (charId=? AND friendId=?) OR (charId=? AND friendId=?)"))
  69. {
  70. statement.setInt(1, activeChar.getObjectId());
  71. statement.setInt(2, id);
  72. statement.setInt(3, id);
  73. statement.setInt(4, activeChar.getObjectId());
  74. statement.execute();
  75. // Player deleted from your friend list
  76. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_BEEN_DELETED_FROM_YOUR_FRIENDS_LIST);
  77. sm.addString(_name);
  78. activeChar.sendPacket(sm);
  79. activeChar.getFriendList().remove(Integer.valueOf(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. }
  93. @Override
  94. public String getType()
  95. {
  96. return _C__7A_REQUESTFRIENDDEL;
  97. }
  98. }