ChatAll.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 handlers.chathandlers;
  16. import java.util.Collection;
  17. import java.util.StringTokenizer;
  18. import java.util.logging.Logger;
  19. import com.l2jserver.Config;
  20. import com.l2jserver.gameserver.handler.IChatHandler;
  21. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  22. import com.l2jserver.gameserver.handler.VoicedCommandHandler;
  23. import com.l2jserver.gameserver.model.BlockList;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  27. import com.l2jserver.gameserver.util.Util;
  28. /**
  29. * A chat handler
  30. *
  31. * @author durgus
  32. */
  33. public class ChatAll implements IChatHandler
  34. {
  35. private static final int[] COMMAND_IDS =
  36. {
  37. 0
  38. };
  39. private static Logger _log = Logger.getLogger(ChatAll.class.getName());
  40. /**
  41. * Handle chat type 'all'
  42. * @see com.l2jserver.gameserver.handler.IChatHandler#handleChat(int, com.l2jserver.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
  43. */
  44. @Override
  45. public void handleChat(int type, L2PcInstance activeChar, String params, String text)
  46. {
  47. boolean vcd_used = false;
  48. if (text.startsWith("."))
  49. {
  50. StringTokenizer st = new StringTokenizer(text);
  51. IVoicedCommandHandler vch;
  52. String command = "";
  53. if (st.countTokens() > 1)
  54. {
  55. command = st.nextToken().substring(1);
  56. params = text.substring(command.length() + 2);
  57. vch = VoicedCommandHandler.getInstance().getHandler(command);
  58. }
  59. else
  60. {
  61. command = text.substring(1);
  62. if (Config.DEBUG)
  63. _log.info("Command: " + command);
  64. vch = VoicedCommandHandler.getInstance().getHandler(command);
  65. }
  66. if (vch != null)
  67. {
  68. vch.useVoicedCommand(command, activeChar, params);
  69. vcd_used = true;
  70. }
  71. else
  72. {
  73. if (Config.DEBUG)
  74. _log.warning("No handler registered for bypass '" + command + "'");
  75. vcd_used = false;
  76. }
  77. }
  78. if (!vcd_used)
  79. {
  80. if (activeChar.isChatBanned() && Util.contains(Config.BAN_CHAT_CHANNELS, type))
  81. {
  82. activeChar.sendPacket(SystemMessageId.CHATTING_IS_CURRENTLY_PROHIBITED);
  83. return;
  84. }
  85. /**
  86. * Match the character "." literally (Exactly 1 time)
  87. * Match any character that is NOT a . character. Between one and unlimited times as possible, giving back as needed (greedy)
  88. */
  89. if (text.matches("\\.{1}[^\\.]+"))
  90. activeChar.sendPacket(SystemMessageId.INCORRECT_SYNTAX);
  91. else
  92. {
  93. CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getAppearance().getVisibleName(), text);
  94. Collection<L2PcInstance> plrs = activeChar.getKnownList().getKnownPlayers().values();
  95. for (L2PcInstance player : plrs)
  96. {
  97. if (player != null && activeChar.isInsideRadius(player, 1250, false, true) && !BlockList.isBlocked(player, activeChar))
  98. player.sendPacket(cs);
  99. }
  100. activeChar.sendPacket(cs);
  101. }
  102. }
  103. }
  104. /**
  105. * Returns the chat types registered to this handler
  106. * @see com.l2jserver.gameserver.handler.IChatHandler#getChatTypeList()
  107. */
  108. @Override
  109. public int[] getChatTypeList()
  110. {
  111. return COMMAND_IDS;
  112. }
  113. }