ChatsHandler.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.telnethandlers;
  16. import java.io.PrintWriter;
  17. import java.net.Socket;
  18. import java.util.StringTokenizer;
  19. import com.l2jserver.gameserver.Announcements;
  20. import com.l2jserver.gameserver.GmListTable;
  21. import com.l2jserver.gameserver.handler.ITelnetHandler;
  22. import com.l2jserver.gameserver.model.L2World;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.clientpackets.Say2;
  25. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  26. /**
  27. * @author UnAfraid
  28. */
  29. public class ChatsHandler implements ITelnetHandler
  30. {
  31. private final String[] _commands =
  32. {
  33. "announce",
  34. "msg",
  35. "gmchat"
  36. };
  37. @Override
  38. public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
  39. {
  40. if (command.startsWith("announce"))
  41. {
  42. try
  43. {
  44. command = command.substring(9);
  45. Announcements.getInstance().announceToAll(command);
  46. _print.println("Announcement Sent!");
  47. }
  48. catch (StringIndexOutOfBoundsException e)
  49. {
  50. _print.println("Please Enter Some Text To Announce!");
  51. }
  52. }
  53. else if (command.startsWith("msg"))
  54. {
  55. try
  56. {
  57. String val = command.substring(4);
  58. StringTokenizer st = new StringTokenizer(val);
  59. String name = st.nextToken();
  60. String message = val.substring(name.length() + 1);
  61. L2PcInstance reciever = L2World.getInstance().getPlayer(name);
  62. CreatureSay cs = new CreatureSay(0, Say2.TELL, "Telnet Priv", message);
  63. if (reciever != null)
  64. {
  65. reciever.sendPacket(cs);
  66. _print.println("Telnet Priv->" + name + ": " + message);
  67. _print.println("Message Sent!");
  68. }
  69. else
  70. {
  71. _print.println("Unable To Find Username: " + name);
  72. }
  73. }
  74. catch (StringIndexOutOfBoundsException e)
  75. {
  76. _print.println("Please Enter Some Text!");
  77. }
  78. }
  79. else if (command.startsWith("gmchat"))
  80. {
  81. try
  82. {
  83. command = command.substring(7);
  84. CreatureSay cs = new CreatureSay(0, Say2.ALLIANCE, "Telnet GM Broadcast from " + _cSocket.getInetAddress().getHostAddress(), command);
  85. GmListTable.broadcastToGMs(cs);
  86. _print.println("Your Message Has Been Sent To " + getOnlineGMS() + " GM(s).");
  87. }
  88. catch (StringIndexOutOfBoundsException e)
  89. {
  90. _print.println("Please Enter Some Text To Announce!");
  91. }
  92. }
  93. return false;
  94. }
  95. private int getOnlineGMS()
  96. {
  97. return GmListTable.getInstance().getAllGms(true).size();
  98. }
  99. @Override
  100. public String[] getCommandList()
  101. {
  102. return _commands;
  103. }
  104. }