2
0

RequestDeleteSentPost.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 static com.l2jserver.gameserver.model.actor.L2Character.ZONE_PEACE;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.instancemanager.MailManager;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.entity.Message;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.ExChangePostState;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. import com.l2jserver.gameserver.util.Util;
  25. /**
  26. * @author Migi, DS
  27. */
  28. public final class RequestDeleteSentPost extends L2GameClientPacket
  29. {
  30. private static final String _C__D0_6C_REQUESTDELETESENTPOST = "[C] D0:6D RequestDeleteSentPost";
  31. private static final int BATCH_LENGTH = 4; // length of the one item
  32. int[] _msgIds = null;
  33. @Override
  34. protected void readImpl()
  35. {
  36. int count = readD();
  37. if (count <= 0
  38. || count > Config.MAX_ITEM_IN_PACKET
  39. || count * BATCH_LENGTH != _buf.remaining())
  40. return;
  41. _msgIds = new int[count];
  42. for (int i = 0; i < count; i++)
  43. _msgIds[i] = readD();
  44. }
  45. @Override
  46. public void runImpl()
  47. {
  48. final L2PcInstance activeChar = getClient().getActiveChar();
  49. if (activeChar == null || _msgIds == null || !Config.ALLOW_MAIL)
  50. return;
  51. if (!activeChar.isInsideZone(ZONE_PEACE))
  52. {
  53. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_USE_MAIL_OUTSIDE_PEACE_ZONE));
  54. return;
  55. }
  56. for (int msgId : _msgIds)
  57. {
  58. Message msg = MailManager.getInstance().getMessage(msgId);
  59. if (msg == null)
  60. continue;
  61. if (msg.getSenderId() != activeChar.getObjectId())
  62. {
  63. Util.handleIllegalPlayerAction(activeChar,
  64. "Player "+activeChar.getName()+" tried to delete not own post!", Config.DEFAULT_PUNISH);
  65. return;
  66. }
  67. if (msg.hasAttachments() || msg.isDeletedBySender())
  68. return;
  69. msg.setDeletedBySender();
  70. }
  71. activeChar.sendPacket(new ExChangePostState(false, _msgIds, Message.DELETED));
  72. }
  73. @Override
  74. public String getType()
  75. {
  76. return _C__D0_6C_REQUESTDELETESENTPOST;
  77. }
  78. }