RequestRejectPostAttachment.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.L2World;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.entity.Message;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.ExChangePostState;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. import com.l2jserver.gameserver.util.Util;
  26. /**
  27. * @author Migi, DS
  28. */
  29. public final class RequestRejectPostAttachment extends L2GameClientPacket
  30. {
  31. private static final String _C__D0_6B_REQUESTREJECTPOSTATTACHMENT = "[C] D0:6B RequestRejectPostAttachment";
  32. private int _msgId;
  33. @Override
  34. protected void readImpl()
  35. {
  36. _msgId = readD();
  37. }
  38. @Override
  39. public void runImpl()
  40. {
  41. if (!Config.ALLOW_MAIL || !Config.ALLOW_ATTACHMENTS)
  42. return;
  43. final L2PcInstance activeChar = getClient().getActiveChar();
  44. if (activeChar == null)
  45. return;
  46. if (!activeChar.getFloodProtectors().getTransaction().tryPerformAction("rejectattach"))
  47. return;
  48. if (!activeChar.isInsideZone(ZONE_PEACE))
  49. {
  50. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_USE_MAIL_OUTSIDE_PEACE_ZONE));
  51. return;
  52. }
  53. Message msg = MailManager.getInstance().getMessage(_msgId);
  54. if (msg == null)
  55. return;
  56. if (msg.getReceiverId() != activeChar.getObjectId())
  57. {
  58. Util.handleIllegalPlayerAction(activeChar,
  59. "Player "+activeChar.getName()+" tried to reject not own attachment!", Config.DEFAULT_PUNISH);
  60. return;
  61. }
  62. if (!msg.hasAttachments() || msg.isFourStars())
  63. return;
  64. MailManager.getInstance().sendMessage(new Message(msg));
  65. activeChar.sendPacket(new SystemMessage(SystemMessageId.MAIL_SUCCESSFULLY_RETURNED));
  66. activeChar.sendPacket(new ExChangePostState(true, _msgId, Message.REJECTED));
  67. final L2PcInstance sender = L2World.getInstance().getPlayer(msg.getSenderId());
  68. if (sender != null)
  69. {
  70. SystemMessage sm = new SystemMessage(SystemMessageId.S1_RETURNED_MAIL);
  71. sm.addCharName(activeChar);
  72. sender.sendPacket(sm);
  73. }
  74. }
  75. @Override
  76. public String getType()
  77. {
  78. return _C__D0_6B_REQUESTREJECTPOSTATTACHMENT;
  79. }
  80. }