ChatsHandler.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.telnethandlers;
  20. import java.io.PrintWriter;
  21. import java.net.Socket;
  22. import java.util.StringTokenizer;
  23. import com.l2jserver.gameserver.data.xml.impl.AdminData;
  24. import com.l2jserver.gameserver.handler.ITelnetHandler;
  25. import com.l2jserver.gameserver.model.L2World;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.clientpackets.Say2;
  28. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  29. import com.l2jserver.gameserver.util.Broadcast;
  30. /**
  31. * @author UnAfraid
  32. */
  33. public class ChatsHandler implements ITelnetHandler
  34. {
  35. private final String[] _commands =
  36. {
  37. "announce",
  38. "msg",
  39. "gmchat"
  40. };
  41. @Override
  42. public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
  43. {
  44. if (command.startsWith("announce"))
  45. {
  46. try
  47. {
  48. command = command.substring(9);
  49. Broadcast.toAllOnlinePlayers(command);
  50. _print.println("Announcement Sent!");
  51. }
  52. catch (StringIndexOutOfBoundsException e)
  53. {
  54. _print.println("Please Enter Some Text To Announce!");
  55. }
  56. }
  57. else if (command.startsWith("msg"))
  58. {
  59. try
  60. {
  61. String val = command.substring(4);
  62. StringTokenizer st = new StringTokenizer(val);
  63. String name = st.nextToken();
  64. String message = val.substring(name.length() + 1);
  65. L2PcInstance reciever = L2World.getInstance().getPlayer(name);
  66. CreatureSay cs = new CreatureSay(0, Say2.TELL, "Telnet Priv", message);
  67. if (reciever != null)
  68. {
  69. reciever.sendPacket(cs);
  70. _print.println("Telnet Priv->" + name + ": " + message);
  71. _print.println("Message Sent!");
  72. }
  73. else
  74. {
  75. _print.println("Unable To Find Username: " + name);
  76. }
  77. }
  78. catch (StringIndexOutOfBoundsException e)
  79. {
  80. _print.println("Please Enter Some Text!");
  81. }
  82. }
  83. else if (command.startsWith("gmchat"))
  84. {
  85. try
  86. {
  87. command = command.substring(7);
  88. CreatureSay cs = new CreatureSay(0, Say2.ALLIANCE, "Telnet GM Broadcast from " + _cSocket.getInetAddress().getHostAddress(), command);
  89. AdminData.getInstance().broadcastToGMs(cs);
  90. _print.println("Your Message Has Been Sent To " + getOnlineGMS() + " GM(s).");
  91. }
  92. catch (StringIndexOutOfBoundsException e)
  93. {
  94. _print.println("Please Enter Some Text To Announce!");
  95. }
  96. }
  97. return false;
  98. }
  99. private int getOnlineGMS()
  100. {
  101. return AdminData.getInstance().getAllGms(true).size();
  102. }
  103. @Override
  104. public String[] getCommandList()
  105. {
  106. return _commands;
  107. }
  108. }