RequestFriendInvite.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 com.l2jserver.gameserver.model.BlockList;
  17. import com.l2jserver.gameserver.model.L2World;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.network.SystemMessageId;
  20. import com.l2jserver.gameserver.network.serverpackets.FriendAddRequest;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. /**
  23. * This class ...
  24. *
  25. * @version $Revision: 1.3.4.2 $ $Date: 2005/03/27 15:29:30 $
  26. */
  27. public final class RequestFriendInvite extends L2GameClientPacket
  28. {
  29. private static final String _C__5E_REQUESTFRIENDINVITE = "[C] 5E RequestFriendInvite";
  30. //private static Logger _log = Logger.getLogger(RequestFriendInvite.class.getName());
  31. private String _name;
  32. @Override
  33. protected void readImpl()
  34. {
  35. _name = readS();
  36. }
  37. @Override
  38. protected void runImpl()
  39. {
  40. final L2PcInstance activeChar = getClient().getActiveChar();
  41. if (activeChar == null)
  42. return;
  43. final L2PcInstance friend = L2World.getInstance().getPlayer(_name);
  44. SystemMessage sm;
  45. // can't use friend invite for locating invisible characters
  46. if (friend == null || !friend.isOnline() || friend.getAppearance().getInvisible())
  47. {
  48. //Target is not found in the game.
  49. activeChar.sendPacket(SystemMessageId.THE_USER_YOU_REQUESTED_IS_NOT_IN_GAME);
  50. return;
  51. }
  52. else if (friend == activeChar)
  53. {
  54. //You cannot add yourself to your own friend list.
  55. activeChar.sendPacket(SystemMessageId.YOU_CANNOT_ADD_YOURSELF_TO_OWN_FRIEND_LIST);
  56. return;
  57. }
  58. else if (BlockList.isBlocked(activeChar, friend))
  59. {
  60. sm = SystemMessage.getSystemMessage(SystemMessageId.BLOCKED_C1);
  61. sm.addCharName(friend);
  62. activeChar.sendPacket(sm);
  63. return;
  64. }
  65. else if (BlockList.isBlocked(friend, activeChar))
  66. {
  67. activeChar.sendMessage("You are in target's block list.");
  68. return;
  69. }
  70. if (activeChar.getFriendList().contains(friend.getObjectId()))
  71. {
  72. // Player already is in your friendlist
  73. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_ALREADY_IN_FRIENDS_LIST);
  74. sm.addString(_name);
  75. activeChar.sendPacket(sm);
  76. return;
  77. }
  78. if (!friend.isProcessingRequest())
  79. {
  80. // requets to become friend
  81. activeChar.onTransactionRequest(friend);
  82. sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_REQUESTED_C1_TO_BE_FRIEND);
  83. sm.addString(_name);
  84. FriendAddRequest ajf = new FriendAddRequest(activeChar.getName());
  85. friend.sendPacket(ajf);
  86. }
  87. else
  88. {
  89. sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_BUSY_TRY_LATER);
  90. sm.addString(_name);
  91. }
  92. activeChar.sendPacket(sm);
  93. }
  94. @Override
  95. public String getType()
  96. {
  97. return _C__5E_REQUESTFRIENDINVITE;
  98. }
  99. }