RequestRejectPostAttachment.java 3.1 KB

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