RequestFriendInvite.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 com.l2jserver.gameserver.model.BlockList;
  21. import com.l2jserver.gameserver.model.L2World;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.FriendAddRequest;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. public final class RequestFriendInvite extends L2GameClientPacket
  27. {
  28. private static final String _C__77_REQUESTFRIENDINVITE = "[C] 77 RequestFriendInvite";
  29. private String _name;
  30. @Override
  31. protected void readImpl()
  32. {
  33. _name = readS();
  34. }
  35. @Override
  36. protected void runImpl()
  37. {
  38. final L2PcInstance activeChar = getActiveChar();
  39. if (activeChar == null)
  40. {
  41. return;
  42. }
  43. final L2PcInstance friend = L2World.getInstance().getPlayer(_name);
  44. // Target is not found in the game.
  45. if ((friend == null) || !friend.isOnline() || friend.isInvisible())
  46. {
  47. activeChar.sendPacket(SystemMessageId.THE_USER_YOU_REQUESTED_IS_NOT_IN_GAME);
  48. return;
  49. }
  50. // You cannot add yourself to your own friend list.
  51. if (friend == activeChar)
  52. {
  53. activeChar.sendPacket(SystemMessageId.YOU_CANNOT_ADD_YOURSELF_TO_OWN_FRIEND_LIST);
  54. return;
  55. }
  56. // Target is in olympiad.
  57. if (activeChar.isInOlympiadMode() || friend.isInOlympiadMode())
  58. {
  59. activeChar.sendPacket(SystemMessageId.A_USER_CURRENTLY_PARTICIPATING_IN_THE_OLYMPIAD_CANNOT_SEND_PARTY_AND_FRIEND_INVITATIONS);
  60. return;
  61. }
  62. // Target blocked active player.
  63. if (BlockList.isBlocked(friend, activeChar))
  64. {
  65. activeChar.sendMessage("You are in target's block list.");
  66. return;
  67. }
  68. SystemMessage sm;
  69. // Target is blocked.
  70. if (BlockList.isBlocked(activeChar, friend))
  71. {
  72. sm = SystemMessage.getSystemMessage(SystemMessageId.BLOCKED_C1);
  73. sm.addCharName(friend);
  74. activeChar.sendPacket(sm);
  75. return;
  76. }
  77. // Target already in friend list.
  78. if (activeChar.getFriendList().contains(friend.getObjectId()))
  79. {
  80. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_ALREADY_IN_FRIENDS_LIST);
  81. sm.addString(_name);
  82. activeChar.sendPacket(sm);
  83. return;
  84. }
  85. // Target is busy.
  86. if (friend.isProcessingRequest())
  87. {
  88. sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_BUSY_TRY_LATER);
  89. sm.addString(_name);
  90. activeChar.sendPacket(sm);
  91. return;
  92. }
  93. // Friend request sent.
  94. activeChar.onTransactionRequest(friend);
  95. friend.sendPacket(new FriendAddRequest(activeChar.getName()));
  96. sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_REQUESTED_C1_TO_BE_FRIEND);
  97. sm.addString(_name);
  98. activeChar.sendPacket(sm);
  99. }
  100. @Override
  101. public String getType()
  102. {
  103. return _C__77_REQUESTFRIENDINVITE;
  104. }
  105. }