Say2.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 java.util.logging.Level;
  17. import java.util.logging.LogRecord;
  18. import java.util.logging.Logger;
  19. import com.l2jserver.Config;
  20. import com.l2jserver.gameserver.handler.ChatHandler;
  21. import com.l2jserver.gameserver.handler.IChatHandler;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. /**
  26. * This class ...
  27. *
  28. * @version $Revision: 1.16.2.12.2.7 $ $Date: 2005/04/11 10:06:11 $
  29. */
  30. public final class Say2 extends L2GameClientPacket
  31. {
  32. private static final String _C__38_SAY2 = "[C] 38 Say2";
  33. private static Logger _log = Logger.getLogger(Say2.class.getName());
  34. private static Logger _logChat = Logger.getLogger("chat");
  35. public final static int ALL = 0;
  36. public final static int SHOUT = 1; //!
  37. public final static int TELL = 2;
  38. public final static int PARTY = 3; //#
  39. public final static int CLAN = 4; //@
  40. public final static int GM = 5;
  41. public final static int PETITION_PLAYER = 6; // used for petition
  42. public final static int PETITION_GM = 7; //* used for petition
  43. public final static int TRADE = 8; //+
  44. public final static int ALLIANCE = 9; //$
  45. public final static int ANNOUNCEMENT = 10;
  46. public final static int PARTYMATCH_ROOM = 14;
  47. public final static int PARTYROOM_COMMANDER = 15; //(Yellow)
  48. public final static int PARTYROOM_ALL = 16; //(Red)
  49. public final static int HERO_VOICE = 17;
  50. public final static int BATTLEFIELD = 20;
  51. private final static String[] CHAT_NAMES =
  52. {
  53. "ALL",
  54. "SHOUT",
  55. "TELL",
  56. "PARTY",
  57. "CLAN",
  58. "GM",
  59. "PETITION_PLAYER",
  60. "PETITION_GM",
  61. "TRADE",
  62. "ALLIANCE",
  63. "ANNOUNCEMENT", //10
  64. "WILLCRASHCLIENT:)",
  65. "FAKEALL?",
  66. "FAKEALL?",
  67. "PARTYMATCH_ROOM",
  68. "PARTYROOM_ALL",
  69. "PARTYROOM_COMMANDER",
  70. "HERO_VOICE",
  71. "UNKNOWN",
  72. "UNKNOWN",
  73. "BATTLEFIELD"
  74. };
  75. private String _text;
  76. private int _type;
  77. private String _target;
  78. @Override
  79. protected void readImpl()
  80. {
  81. _text = readS();
  82. _type = readD();
  83. _target = (_type == TELL) ? readS() : null;
  84. }
  85. @Override
  86. protected void runImpl()
  87. {
  88. if (Config.DEBUG)
  89. _log.info("Say2: Msg Type = '" + _type + "' Text = '" + _text + "'.");
  90. L2PcInstance activeChar = getClient().getActiveChar();
  91. if (activeChar == null)
  92. return;
  93. if (_type < 0 || _type >= CHAT_NAMES.length)
  94. {
  95. _log.warning("Say2: Invalid type: " +_type + " Player : " + activeChar.getName() + " text: " + String.valueOf(_text));
  96. return;
  97. }
  98. if (_text.isEmpty())
  99. {
  100. _log.warning(activeChar.getName() + ": sending empty text. Possible packet hack!");
  101. return;
  102. }
  103. // Even though the client can handle more characters than it's current limit allows, an overflow (critical error) happens if you pass a huge (1000+) message.
  104. // April 27, 2009 - Verified on Gracia P2 & Final official client as 105
  105. if (_text.length() > 105 && !activeChar.isGM())
  106. {
  107. activeChar.sendPacket(new SystemMessage(SystemMessageId.DONT_SPAM));
  108. return;
  109. }
  110. if (activeChar.isCursedWeaponEquipped() && (_type == TRADE || _type == SHOUT))
  111. {
  112. activeChar.sendPacket(new SystemMessage(SystemMessageId.SHOUT_AND_TRADE_CHAT_CANNOT_BE_USED_WHILE_POSSESSING_CURSED_WEAPON));
  113. return;
  114. }
  115. if (activeChar.isChatBanned())
  116. {
  117. if (_type == ALL || _type == SHOUT || _type == TRADE || _type == HERO_VOICE)
  118. {
  119. activeChar.sendPacket(new SystemMessage(SystemMessageId.CHATTING_IS_CURRENTLY_PROHIBITED));
  120. return;
  121. }
  122. }
  123. if (activeChar.isInJail() && Config.JAIL_DISABLE_CHAT)
  124. {
  125. if (_type == TELL || _type == SHOUT || _type == TRADE || _type == HERO_VOICE)
  126. {
  127. activeChar.sendMessage("You can not chat with players outside of the jail.");
  128. return;
  129. }
  130. }
  131. if (_type == PETITION_PLAYER && activeChar.isGM())
  132. _type = PETITION_GM;
  133. if (Config.LOG_CHAT)
  134. {
  135. LogRecord record = new LogRecord(Level.INFO, _text);
  136. record.setLoggerName("chat");
  137. if (_type == TELL)
  138. record.setParameters(new Object[]{CHAT_NAMES[_type], "[" + activeChar.getName() + " to "+_target+"]"});
  139. else
  140. record.setParameters(new Object[]{CHAT_NAMES[_type], "[" + activeChar.getName() + "]"});
  141. _logChat.log(record);
  142. }
  143. // Say Filter implementation
  144. if (Config.USE_SAY_FILTER)
  145. checkText();
  146. IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
  147. if (handler != null)
  148. handler.handleChat(_type, activeChar, _target, _text);
  149. }
  150. private void checkText()
  151. {
  152. String filteredText = _text;
  153. for (String pattern : Config.FILTER_LIST)
  154. filteredText = filteredText.replaceAll("(?i)" + pattern, Config.CHAT_FILTER_CHARS);
  155. _text = filteredText;
  156. }
  157. /* (non-Javadoc)
  158. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  159. */
  160. @Override
  161. public String getType()
  162. {
  163. return _C__38_SAY2;
  164. }
  165. }