RequestBlock.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 net.sf.l2j.gameserver.clientpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.gameserver.model.BlockList;
  18. import net.sf.l2j.gameserver.model.L2World;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.network.SystemMessageId;
  21. import net.sf.l2j.gameserver.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. private L2PcInstance _target;
  34. @Override
  35. protected void readImpl()
  36. {
  37. _type = readD(); //0x00 - block, 0x01 - unblock, 0x03 - allblock, 0x04 - allunblock
  38. if( _type == BLOCK || _type == UNBLOCK )
  39. {
  40. _name = readS();
  41. _target = L2World.getInstance().getPlayer(_name);
  42. }
  43. }
  44. @Override
  45. protected void runImpl()
  46. {
  47. L2PcInstance activeChar = getClient().getActiveChar();
  48. if (activeChar == null)
  49. return;
  50. switch (_type)
  51. {
  52. case BLOCK:
  53. case UNBLOCK:
  54. if (_target == null)
  55. {
  56. // Incorrect player name.
  57. activeChar.sendPacket(new SystemMessage(SystemMessageId.FAILED_TO_REGISTER_TO_IGNORE_LIST));
  58. return;
  59. }
  60. if (_target.isGM())
  61. {
  62. // Cannot block a GM character.
  63. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_MAY_NOT_IMPOSE_A_BLOCK_ON_GM));
  64. return;
  65. }
  66. if (_type == BLOCK)
  67. BlockList.addToBlockList(activeChar, _target);
  68. else
  69. BlockList.removeFromBlockList(activeChar, _target);
  70. break;
  71. case BLOCKLIST:
  72. BlockList.sendListToOwner(activeChar);
  73. break;
  74. case ALLBLOCK:
  75. BlockList.setBlockAll(activeChar, true);
  76. break;
  77. case ALLUNBLOCK:
  78. BlockList.setBlockAll(activeChar, false);
  79. break;
  80. default:
  81. _log.info("Unknown 0x0a block type: " + _type);
  82. }
  83. }
  84. @Override
  85. public String getType()
  86. {
  87. return _C__A0_REQUESTBLOCK;
  88. }
  89. }