ServerHandler.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 com.l2jserver.gameserver.Shutdown;
  19. import com.l2jserver.gameserver.handler.ITelnetHandler;
  20. /**
  21. * @author UnAfraid
  22. */
  23. public class ServerHandler implements ITelnetHandler
  24. {
  25. private final String[] _commands =
  26. {
  27. "shutdown",
  28. "restart",
  29. "abort"
  30. };
  31. @Override
  32. public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
  33. {
  34. if (command.startsWith("shutdown"))
  35. {
  36. try
  37. {
  38. int val = Integer.parseInt(command.substring(9));
  39. Shutdown.getInstance().startTelnetShutdown(_cSocket.getInetAddress().getHostAddress(), val, false);
  40. _print.println("Server Will Shutdown In " + val + " Seconds!");
  41. _print.println("Type \"abort\" To Abort Shutdown!");
  42. }
  43. catch (StringIndexOutOfBoundsException e)
  44. {
  45. _print.println("Please Enter * amount of seconds to shutdown!");
  46. }
  47. catch (Exception NumberFormatException)
  48. {
  49. _print.println("Numbers Only!");
  50. }
  51. }
  52. else if (command.startsWith("restart"))
  53. {
  54. try
  55. {
  56. int val = Integer.parseInt(command.substring(8));
  57. Shutdown.getInstance().startTelnetShutdown(_cSocket.getInetAddress().getHostAddress(), val, true);
  58. _print.println("Server Will Restart In " + val + " Seconds!");
  59. _print.println("Type \"abort\" To Abort Restart!");
  60. }
  61. catch (StringIndexOutOfBoundsException e)
  62. {
  63. _print.println("Please Enter * amount of seconds to restart!");
  64. }
  65. catch (Exception NumberFormatException)
  66. {
  67. _print.println("Numbers Only!");
  68. }
  69. }
  70. else if (command.startsWith("abort"))
  71. {
  72. Shutdown.getInstance().telnetAbort(_cSocket.getInetAddress().getHostAddress());
  73. _print.println("OK! - Shutdown/Restart Aborted.");
  74. }
  75. return false;
  76. }
  77. @Override
  78. public String[] getCommandList()
  79. {
  80. return _commands;
  81. }
  82. }