RequestDeleteSentPost.java 2.9 KB

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