RequestBlock.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.util.logging.Logger;
  17. import com.l2jserver.gameserver.datatables.CharNameTable;
  18. import com.l2jserver.gameserver.model.BlockList;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. public final class RequestBlock extends L2GameClientPacket
  23. {
  24. private static final String _C__A0_REQUESTBLOCK = "[C] A0 RequestBlock";
  25. private static Logger _log = Logger.getLogger(L2PcInstance.class.getName());
  26. private final static int BLOCK = 0;
  27. private final static int UNBLOCK = 1;
  28. private final static int BLOCKLIST = 2;
  29. private final static int ALLBLOCK = 3;
  30. private final static int ALLUNBLOCK = 4;
  31. private String _name;
  32. private Integer _type;
  33. @Override
  34. protected void readImpl()
  35. {
  36. _type = readD(); //0x00 - block, 0x01 - unblock, 0x03 - allblock, 0x04 - allunblock
  37. if (_type == BLOCK || _type == UNBLOCK)
  38. {
  39. _name = readS();
  40. }
  41. }
  42. @Override
  43. protected void runImpl()
  44. {
  45. final L2PcInstance activeChar = getClient().getActiveChar();
  46. final int targetId = CharNameTable.getInstance().getIdByName(_name);
  47. final int targetAL = CharNameTable.getInstance().getAccessLevelById(targetId);
  48. if (activeChar == null)
  49. return;
  50. switch (_type)
  51. {
  52. case BLOCK:
  53. case UNBLOCK:
  54. // can't use block/unblock for locating invisible characters
  55. if (targetId <= 0)
  56. {
  57. // Incorrect player name.
  58. activeChar.sendPacket(new SystemMessage(SystemMessageId.FAILED_TO_REGISTER_TO_IGNORE_LIST));
  59. return;
  60. }
  61. if (targetAL > 0)
  62. {
  63. // Cannot block a GM character.
  64. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_MAY_NOT_IMPOSE_A_BLOCK_ON_GM));
  65. return;
  66. }
  67. if (activeChar.getObjectId() == targetId)
  68. return;
  69. if (_type == BLOCK)
  70. BlockList.addToBlockList(activeChar, targetId);
  71. else
  72. BlockList.removeFromBlockList(activeChar, targetId);
  73. break;
  74. case BLOCKLIST:
  75. BlockList.sendListToOwner(activeChar);
  76. break;
  77. case ALLBLOCK:
  78. activeChar.sendPacket(new SystemMessage(SystemMessageId.MESSAGE_REFUSAL_MODE));//Update by rocknow
  79. BlockList.setBlockAll(activeChar, true);
  80. break;
  81. case ALLUNBLOCK:
  82. activeChar.sendPacket(new SystemMessage(SystemMessageId.MESSAGE_ACCEPTANCE_MODE));//Update by rocknow
  83. BlockList.setBlockAll(activeChar, false);
  84. break;
  85. default:
  86. _log.info("Unknown 0x0a block type: " + _type);
  87. }
  88. }
  89. @Override
  90. public String getType()
  91. {
  92. return _C__A0_REQUESTBLOCK;
  93. }
  94. }