Say2.java 8.3 KB

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