RequestSendFriendMsg.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 java.util.logging.Level;
  21. import java.util.logging.LogRecord;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.model.L2World;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.L2FriendSay;
  28. /**
  29. * Recieve Private (Friend) Message - 0xCC Format: c SS S: Message S: Receiving Player
  30. * @author Tempy
  31. */
  32. public final class RequestSendFriendMsg extends L2GameClientPacket
  33. {
  34. private static final String _C__6B_REQUESTSENDMSG = "[C] 6B RequestSendFriendMsg";
  35. private static Logger _logChat = Logger.getLogger("chat");
  36. private String _message;
  37. private String _reciever;
  38. @Override
  39. protected void readImpl()
  40. {
  41. _message = readS();
  42. _reciever = readS();
  43. }
  44. @Override
  45. protected void runImpl()
  46. {
  47. final L2PcInstance activeChar = getClient().getActiveChar();
  48. if (activeChar == null)
  49. {
  50. return;
  51. }
  52. if ((_message == null) || _message.isEmpty() || (_message.length() > 300))
  53. {
  54. return;
  55. }
  56. final L2PcInstance targetPlayer = L2World.getInstance().getPlayer(_reciever);
  57. if ((targetPlayer == null) || !targetPlayer.getFriendList().contains(activeChar.getObjectId()))
  58. {
  59. activeChar.sendPacket(SystemMessageId.TARGET_IS_NOT_FOUND_IN_THE_GAME);
  60. return;
  61. }
  62. if (Config.LOG_CHAT)
  63. {
  64. LogRecord record = new LogRecord(Level.INFO, _message);
  65. record.setLoggerName("chat");
  66. record.setParameters(new Object[]
  67. {
  68. "PRIV_MSG",
  69. "[" + activeChar.getName() + " to " + _reciever + "]"
  70. });
  71. _logChat.log(record);
  72. }
  73. targetPlayer.sendPacket(new L2FriendSay(activeChar.getName(), _reciever, _message));
  74. }
  75. @Override
  76. public String getType()
  77. {
  78. return _C__6B_REQUESTSENDMSG;
  79. }
  80. }