ServerHandler.java 2.6 KB

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