2
0

Say2.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 net.sf.l2j.gameserver.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 net.sf.l2j.Config;
  21. import net.sf.l2j.gameserver.handler.ChatHandler;
  22. import net.sf.l2j.gameserver.handler.IChatHandler;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  24. import net.sf.l2j.gameserver.network.SystemMessageId;
  25. import net.sf.l2j.gameserver.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 PARTYROOM_ALL = 16; //(Red)
  48. public final static int PARTYROOM_COMMANDER = 15; //(Yellow)
  49. public final static int HERO_VOICE = 17;
  50. private final static String[] CHAT_NAMES = {
  51. "ALL ",
  52. "SHOUT",
  53. "TELL ",
  54. "PARTY",
  55. "CLAN ",
  56. "GM ",
  57. "PETITION_PLAYER",
  58. "PETITION_GM",
  59. "TRADE",
  60. "ALLIANCE",
  61. "ANNOUNCEMENT", //10
  62. "WILLCRASHCLIENT:)",
  63. "FAKEALL?",
  64. "FAKEALL?",
  65. "FAKEALL?",
  66. "PARTYROOM_ALL",
  67. "PARTYROOM_COMMANDER",
  68. "HERO_VOICE"
  69. };
  70. private String _text;
  71. private int _type;
  72. private String _target;
  73. @Override
  74. protected void readImpl()
  75. {
  76. _text = readS();
  77. try
  78. {
  79. _type = readD();
  80. }
  81. catch (BufferUnderflowException e)
  82. {
  83. _type = CHAT_NAMES.length;
  84. }
  85. _target = (_type == TELL) ? readS() : null;
  86. }
  87. @Override
  88. protected void runImpl()
  89. {
  90. if (Config.DEBUG)
  91. _log.info("Say2: Msg Type = '" + _type + "' Text = '" + _text + "'.");
  92. if(_type < 0 || _type >= CHAT_NAMES.length)
  93. {
  94. _log.warning("Say2: Invalid type: "+_type);
  95. return;
  96. }
  97. L2PcInstance activeChar = getClient().getActiveChar();
  98. if (activeChar == null)
  99. {
  100. _log.warning("[Say2.java] Active Character is null.");
  101. return;
  102. }
  103. if (activeChar.isCursedWeaponEquipped() && (_type == TRADE || _type == SHOUT))
  104. {
  105. SystemMessage sm = new SystemMessage(SystemMessageId.SHOUT_AND_TRADE_CHAT_CANNOT_BE_USED_WHILE_POSSESSING_CURSED_WEAPON);
  106. activeChar.sendPacket(sm);
  107. return;
  108. }
  109. if (activeChar.isChatBanned())
  110. {
  111. if (_type == ALL || _type == SHOUT || _type == TRADE || _type == HERO_VOICE)
  112. {
  113. activeChar.sendMessage("You may not chat while a chat ban is in effect.");
  114. return;
  115. }
  116. }
  117. if (activeChar.isInJail() && Config.JAIL_DISABLE_CHAT)
  118. {
  119. if (_type == TELL || _type == SHOUT || _type == TRADE || _type == HERO_VOICE)
  120. {
  121. activeChar.sendMessage("You can not chat with players outside of the jail.");
  122. return;
  123. }
  124. }
  125. if (_type == PETITION_PLAYER && activeChar.isGM())
  126. _type = PETITION_GM;
  127. if (Config.LOG_CHAT)
  128. {
  129. LogRecord record = new LogRecord(Level.INFO, _text);
  130. record.setLoggerName("chat");
  131. if (_type == TELL)
  132. record.setParameters(new Object[]{CHAT_NAMES[_type], "[" + activeChar.getName() + " to "+_target+"]"});
  133. else
  134. record.setParameters(new Object[]{CHAT_NAMES[_type], "[" + activeChar.getName() + "]"});
  135. _logChat.log(record);
  136. }
  137. IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
  138. if (handler != null)
  139. {
  140. handler.handleChat(_type, activeChar, _target, _text);
  141. }
  142. }
  143. /* (non-Javadoc)
  144. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  145. */
  146. @Override
  147. public String getType()
  148. {
  149. return _C__38_SAY2;
  150. }
  151. }