RequestReceivedPost.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.ExReplyReceivedPost;
  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 RequestReceivedPost extends L2GameClientPacket
  30. {
  31. private static final String _C__D0_69_REQUESTRECEIVEDPOST = "[C] D0:69 RequestReceivedPost";
  32. private int _msgId;
  33. @Override
  34. protected void readImpl()
  35. {
  36. _msgId = readD();
  37. }
  38. @Override
  39. public void runImpl()
  40. {
  41. final L2PcInstance activeChar = getClient().getActiveChar();
  42. if (activeChar == null || !Config.ALLOW_MAIL)
  43. return;
  44. final Message msg = MailManager.getInstance().getMessage(_msgId);
  45. if (msg == null)
  46. return;
  47. if (!activeChar.isInsideZone(ZONE_PEACE) && msg.hasAttachments())
  48. {
  49. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANT_USE_MAIL_OUTSIDE_PEACE_ZONE));
  50. return;
  51. }
  52. if (msg.getReceiverId() != activeChar.getObjectId())
  53. {
  54. Util.handleIllegalPlayerAction(activeChar,
  55. "Player "+activeChar.getName()+" tried to receive not own post!", Config.DEFAULT_PUNISH);
  56. return;
  57. }
  58. if (msg.isDeletedByReceiver())
  59. return;
  60. activeChar.sendPacket(new ExReplyReceivedPost(msg));
  61. activeChar.sendPacket(new ExChangePostState(true, _msgId, Message.READED));
  62. msg.markAsRead();
  63. }
  64. @Override
  65. public String getType()
  66. {
  67. return _C__D0_69_REQUESTRECEIVEDPOST;
  68. }
  69. @Override
  70. protected boolean triggersOnActionRequest()
  71. {
  72. return false;
  73. }
  74. }