RequestBlock.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.data.sql.impl.CharNameTable;
  21. import com.l2jserver.gameserver.model.BlockList;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. public final class RequestBlock extends L2GameClientPacket
  25. {
  26. private static final String _C__A9_REQUESTBLOCK = "[C] A9 RequestBlock";
  27. private static final int BLOCK = 0;
  28. private static final int UNBLOCK = 1;
  29. private static final int BLOCKLIST = 2;
  30. private static final int ALLBLOCK = 3;
  31. private static final int ALLUNBLOCK = 4;
  32. private String _name;
  33. private Integer _type;
  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. }
  42. }
  43. @Override
  44. protected void runImpl()
  45. {
  46. final L2PcInstance activeChar = getClient().getActiveChar();
  47. final int targetId = CharNameTable.getInstance().getIdByName(_name);
  48. final int targetAL = CharNameTable.getInstance().getAccessLevelById(targetId);
  49. if (activeChar == null)
  50. {
  51. return;
  52. }
  53. switch (_type)
  54. {
  55. case BLOCK:
  56. case UNBLOCK:
  57. // can't use block/unblock for locating invisible characters
  58. if (targetId <= 0)
  59. {
  60. // Incorrect player name.
  61. activeChar.sendPacket(SystemMessageId.FAILED_TO_REGISTER_TO_IGNORE_LIST);
  62. return;
  63. }
  64. if (targetAL > 0)
  65. {
  66. // Cannot block a GM character.
  67. activeChar.sendPacket(SystemMessageId.YOU_MAY_NOT_IMPOSE_A_BLOCK_ON_GM);
  68. return;
  69. }
  70. if (activeChar.getObjectId() == targetId)
  71. {
  72. return;
  73. }
  74. if (_type == BLOCK)
  75. {
  76. BlockList.addToBlockList(activeChar, targetId);
  77. }
  78. else
  79. {
  80. BlockList.removeFromBlockList(activeChar, targetId);
  81. }
  82. break;
  83. case BLOCKLIST:
  84. BlockList.sendListToOwner(activeChar);
  85. break;
  86. case ALLBLOCK:
  87. activeChar.sendPacket(SystemMessageId.MESSAGE_REFUSAL_MODE);
  88. BlockList.setBlockAll(activeChar, true);
  89. break;
  90. case ALLUNBLOCK:
  91. activeChar.sendPacket(SystemMessageId.MESSAGE_ACCEPTANCE_MODE);
  92. BlockList.setBlockAll(activeChar, false);
  93. break;
  94. default:
  95. _log.info("Unknown 0xA9 block type: " + _type);
  96. }
  97. }
  98. @Override
  99. public String getType()
  100. {
  101. return _C__A9_REQUESTBLOCK;
  102. }
  103. }