Say2.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.L2ItemInstance;
  23. import com.l2jserver.gameserver.model.L2Object;
  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.SystemMessage;
  28. /**
  29. * This class ...
  30. *
  31. * @version $Revision: 1.16.2.12.2.7 $ $Date: 2005/04/11 10:06:11 $
  32. */
  33. public final class Say2 extends L2GameClientPacket
  34. {
  35. private static final String _C__38_SAY2 = "[C] 38 Say2";
  36. private static Logger _log = Logger.getLogger(Say2.class.getName());
  37. private static Logger _logChat = Logger.getLogger("chat");
  38. public final static int ALL = 0;
  39. public final static int SHOUT = 1; //!
  40. public final static int TELL = 2;
  41. public final static int PARTY = 3; //#
  42. public final static int CLAN = 4; //@
  43. public final static int GM = 5;
  44. public final static int PETITION_PLAYER = 6; // used for petition
  45. public final static int PETITION_GM = 7; //* used for petition
  46. public final static int TRADE = 8; //+
  47. public final static int ALLIANCE = 9; //$
  48. public final static int ANNOUNCEMENT = 10;
  49. public final static int PARTYMATCH_ROOM = 14;
  50. public final static int PARTYROOM_COMMANDER = 15; //(Yellow)
  51. public final static int PARTYROOM_ALL = 16; //(Red)
  52. public final static int HERO_VOICE = 17;
  53. public final static int BATTLEFIELD = 20;
  54. private final static String[] CHAT_NAMES =
  55. {
  56. "ALL",
  57. "SHOUT",
  58. "TELL",
  59. "PARTY",
  60. "CLAN",
  61. "GM",
  62. "PETITION_PLAYER",
  63. "PETITION_GM",
  64. "TRADE",
  65. "ALLIANCE",
  66. "ANNOUNCEMENT", //10
  67. "WILLCRASHCLIENT:)",
  68. "FAKEALL?",
  69. "FAKEALL?",
  70. "PARTYMATCH_ROOM",
  71. "PARTYROOM_ALL",
  72. "PARTYROOM_COMMANDER",
  73. "HERO_VOICE",
  74. "UNKNOWN",
  75. "UNKNOWN",
  76. "BATTLEFIELD"
  77. };
  78. private String _text;
  79. private int _type;
  80. private String _target;
  81. @Override
  82. protected void readImpl()
  83. {
  84. _text = readS();
  85. _type = readD();
  86. _target = (_type == TELL) ? readS() : null;
  87. }
  88. @Override
  89. protected void runImpl()
  90. {
  91. if (Config.DEBUG)
  92. _log.info("Say2: Msg Type = '" + _type + "' Text = '" + _text + "'.");
  93. L2PcInstance activeChar = getClient().getActiveChar();
  94. if (activeChar == null)
  95. return;
  96. if (_type < 0 || _type >= CHAT_NAMES.length)
  97. {
  98. _log.warning("Say2: Invalid type: " +_type + " Player : " + activeChar.getName() + " text: " + String.valueOf(_text));
  99. return;
  100. }
  101. if (_text.isEmpty())
  102. {
  103. _log.warning(activeChar.getName() + ": sending empty text. Possible packet hack!");
  104. return;
  105. }
  106. // 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.
  107. // April 27, 2009 - Verified on Gracia P2 & Final official client as 105
  108. if (_text.length() > 105 && !activeChar.isGM())
  109. {
  110. activeChar.sendPacket(new SystemMessage(SystemMessageId.DONT_SPAM));
  111. return;
  112. }
  113. if (activeChar.isCursedWeaponEquipped() && (_type == TRADE || _type == SHOUT))
  114. {
  115. activeChar.sendPacket(new SystemMessage(SystemMessageId.SHOUT_AND_TRADE_CHAT_CANNOT_BE_USED_WHILE_POSSESSING_CURSED_WEAPON));
  116. return;
  117. }
  118. if (activeChar.isChatBanned())
  119. {
  120. if (_type == ALL || _type == SHOUT || _type == TRADE || _type == HERO_VOICE)
  121. {
  122. activeChar.sendPacket(new SystemMessage(SystemMessageId.CHATTING_IS_CURRENTLY_PROHIBITED));
  123. return;
  124. }
  125. }
  126. if (activeChar.isInJail() && Config.JAIL_DISABLE_CHAT)
  127. {
  128. if (_type == TELL || _type == SHOUT || _type == TRADE || _type == HERO_VOICE)
  129. {
  130. activeChar.sendMessage("You can not chat with players outside of the jail.");
  131. return;
  132. }
  133. }
  134. if (_type == PETITION_PLAYER && activeChar.isGM())
  135. _type = PETITION_GM;
  136. if (Config.LOG_CHAT)
  137. {
  138. LogRecord record = new LogRecord(Level.INFO, _text);
  139. record.setLoggerName("chat");
  140. if (_type == TELL)
  141. record.setParameters(new Object[]{CHAT_NAMES[_type], "[" + activeChar.getName() + " to "+_target+"]"});
  142. else
  143. record.setParameters(new Object[]{CHAT_NAMES[_type], "[" + activeChar.getName() + "]"});
  144. _logChat.log(record);
  145. }
  146. if (_text.indexOf(8) >= 0)
  147. if (!parseAndPublishItem(activeChar))
  148. return;
  149. // Say Filter implementation
  150. if (Config.USE_SAY_FILTER)
  151. checkText();
  152. IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
  153. if (handler != null)
  154. handler.handleChat(_type, activeChar, _target, _text);
  155. }
  156. private void checkText()
  157. {
  158. String filteredText = _text;
  159. for (String pattern : Config.FILTER_LIST)
  160. filteredText = filteredText.replaceAll("(?i)" + pattern, Config.CHAT_FILTER_CHARS);
  161. _text = filteredText;
  162. }
  163. private boolean parseAndPublishItem(L2PcInstance owner)
  164. {
  165. int pos1 = -1;
  166. while ((pos1 = _text.indexOf(8, pos1)) > -1)
  167. {
  168. int pos = _text.indexOf("ID=", pos1);
  169. if (pos == -1)
  170. return false;
  171. StringBuilder result = new StringBuilder(9);
  172. pos += 3;
  173. while (Character.isDigit(_text.charAt(pos)))
  174. result.append(_text.charAt(pos++));
  175. int id = Integer.parseInt(result.toString());
  176. L2Object item = L2World.getInstance().findObject(id);
  177. if (item instanceof L2ItemInstance)
  178. {
  179. if (owner.getInventory().getItemByObjectId(id) == null)
  180. {
  181. _log.info(getClient() + " trying publish item which doesnt own! ID:" + id);
  182. return false;
  183. }
  184. ((L2ItemInstance) item).publish();
  185. }
  186. else
  187. {
  188. _log.info(getClient() + " trying publish object which is not item! ID:" + id);
  189. return false;
  190. }
  191. pos1 = _text.indexOf(8, pos) + 1;
  192. if (pos1 == 0) // missing ending tag
  193. {
  194. _log.info(getClient() + " sent invalid publish item msg! ID:" + id);
  195. return false;
  196. }
  197. }
  198. return true;
  199. }
  200. /* (non-Javadoc)
  201. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  202. */
  203. @Override
  204. public String getType()
  205. {
  206. return _C__38_SAY2;
  207. }
  208. }