Advertisement
Guest User

telnet

a guest
Aug 23rd, 2013
583
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 1 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2J_Server_BETA
  3. Index: java/com/l2jserver/gameserver/GameServer.java
  4. ===================================================================
  5. --- java/com/l2jserver/gameserver/GameServer.java (revision 6166)
  6. +++ java/com/l2jserver/gameserver/GameServer.java (working copy)
  7. @@ -204,7 +204,8 @@
  8. // load script engines
  9. printSection("Engines");
  10. L2ScriptEngineManager.getInstance();
  11. -
  12. + Telnet telnet = new Telnet();
  13. + telnet.start();
  14. printSection("World");
  15. // start game time control early
  16. GameTimeController.init();
  17. Index: java/com/l2jserver/gameserver/Shutdown.java
  18. ===================================================================
  19. --- java/com/l2jserver/gameserver/Shutdown.java (revision 6166)
  20. +++ java/com/l2jserver/gameserver/Shutdown.java (working copy)
  21. @@ -84,6 +84,13 @@
  22. Broadcast.toAllOnlinePlayers(sysm);
  23. }
  24.  
  25. + public void shutDown(int sec, boolean r)
  26. + {
  27. + _counterInstance = new Shutdown(sec, r);
  28. + _counterInstance.start();
  29. +
  30. + }
  31. +
  32. public void startTelnetShutdown(String IP, int seconds, boolean restart)
  33. {
  34. _log.warning("IP: " + IP + " issued shutdown command. " + MODE_TEXT[_shutdownMode] + " in " + seconds + " seconds!");
  35. Index: java/com/l2jserver/gameserver/Telnet.java
  36. ===================================================================
  37. --- java/com/l2jserver/gameserver/Telnet.java (revision 0)
  38. +++ java/com/l2jserver/gameserver/Telnet.java (revision 0)
  39. @@ -0,0 +1,155 @@
  40. +package com.l2jserver.gameserver;
  41. +
  42. +import java.io.IOException;
  43. +import java.net.DatagramPacket;
  44. +import java.net.DatagramSocket;
  45. +import java.net.InetAddress;
  46. +import java.net.SocketException;
  47. +
  48. +import com.l2jserver.gameserver.instancemanager.PunishmentManager;
  49. +import com.l2jserver.gameserver.model.L2World;
  50. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  51. +import com.l2jserver.gameserver.model.punishment.PunishmentAffect;
  52. +import com.l2jserver.gameserver.model.punishment.PunishmentTask;
  53. +import com.l2jserver.gameserver.model.punishment.PunishmentType;
  54. +
  55. +public class Telnet extends Thread
  56. +{
  57. +
  58. + private DatagramSocket socket;
  59. + String pass = "marwan";
  60. + int port = 1234;
  61. + boolean connected = false;
  62. +
  63. + public Telnet()
  64. + {
  65. + try
  66. + {
  67. + this.socket = new DatagramSocket(port);
  68. + System.out.println("Telnet server started.");
  69. + }
  70. + catch (SocketException e)
  71. + {
  72. + // TODO Auto-generated catch block
  73. + e.printStackTrace();
  74. + }
  75. +
  76. + }
  77. +
  78. + @Override
  79. + public void run()
  80. + {
  81. + while (true)
  82. + {
  83. + byte[] data = new byte[1024];
  84. + DatagramPacket packet = new DatagramPacket(data, data.length);
  85. + try
  86. + {
  87. + socket.receive(packet);
  88. + }
  89. + catch (IOException e)
  90. + {
  91. + // TODO Auto-generated catch block
  92. + e.printStackTrace();
  93. + }
  94. + String mess = new String(packet.getData());
  95. + if (mess.contains("pass"))
  96. + {
  97. + String[] password = mess.split(":");
  98. + if (pass.equals(password[1].trim()))
  99. + {
  100. + sendData("passright".getBytes(), packet.getAddress(), packet.getPort());
  101. + connected = true;
  102. + }
  103. + else
  104. + {
  105. + System.out.println("Pass wrong.");
  106. + sendData("passwrong".getBytes(), packet.getAddress(), packet.getPort());
  107. + }
  108. + }
  109. + if (connected)
  110. + {
  111. + if (mess.trim().equals("shutdown"))
  112. + {
  113. +
  114. + System.out.println("Shutdown Command");
  115. + System.out.println("Shut down in 60 sec");
  116. +
  117. + Shutdown.getInstance().shutDown(60, false);
  118. + }
  119. + if (mess.trim().equals("restart"))
  120. + {
  121. + System.out.println("Restart Command");
  122. + System.out.println("Restarting in 60 secs");
  123. +
  124. + Shutdown.getInstance().shutDown(60, true);
  125. +
  126. + }
  127. + if (mess.contains("announce"))
  128. + {
  129. + String[] split = mess.split(":");
  130. +
  131. + System.out.println("Announced " + split[1]);
  132. + Announcements.getInstance().announceToAll(split[1]);
  133. +
  134. + }
  135. + else if (mess.contains("jail"))
  136. + {
  137. + String[] split = mess.split(":");
  138. + L2PcInstance pl = L2World.getInstance().getPlayer(split[1]);
  139. + PunishmentManager.getInstance().startPunishment(new PunishmentTask(pl.getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.JAIL, 10000, "jailed", "Admin"));
  140. + }
  141. + if (mess.contains("ban"))
  142. + {
  143. + String[] split = mess.split(":");
  144. + L2PcInstance pl = L2World.getInstance().getPlayer(split[1]);
  145. + pl.setAccessLevel(-1);
  146. + }
  147. + if (mess.trim().equals("online"))
  148. + {
  149. + String online = null;
  150. + for (L2PcInstance onlines : L2World.getInstance().getAllPlayersArray())
  151. + {
  152. + online = onlines.getName() + ",";
  153. + }
  154. + }
  155. + if (mess.trim().equals("closing"))
  156. + {
  157. + connected = false;
  158. + System.out.println("Telnet closed");
  159. + }
  160. + }
  161. + else
  162. + {
  163. + System.out.println("Someone trying to send commands while not connected");
  164. + }
  165. + }
  166. + }
  167. +
  168. + public void sendData(byte[] data, InetAddress ipAddress, int port)
  169. + {
  170. + DatagramPacket packet = new DatagramPacket(data, data.length, ipAddress, port);
  171. + try
  172. + {
  173. + socket.send(packet);
  174. + }
  175. + catch (IOException e)
  176. + {
  177. + // TODO Auto-generated catch block
  178. + e.printStackTrace();
  179. + }
  180. + System.out.println("sent : " + new String(data));
  181. + }
  182. +
  183. +
  184. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement