Say2.java 5.7 KB

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