Advertisement
Guest User

telnet

a guest
Aug 23rd, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. s### 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,154 @@
  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. + }
  107. + }
  108. + if (connected)
  109. + {
  110. + if (mess.trim().equals("shutdown"))
  111. + {
  112. +
  113. + System.out.println("Shutdown Command");
  114. + System.out.println("Shut down in 60 sec");
  115. +
  116. + Shutdown.getInstance().shutDown(60, false);
  117. + }
  118. + if (mess.trim().equals("restart"))
  119. + {
  120. + System.out.println("Restart Command");
  121. + System.out.println("Restarting in 60 secs");
  122. +
  123. + Shutdown.getInstance().shutDown(60, true);
  124. +
  125. + }
  126. + if (mess.contains("announce"))
  127. + {
  128. + String[] split = mess.split(":");
  129. +
  130. + System.out.println("Announced " + split[1]);
  131. + Announcements.getInstance().announceToAll(split[1]);
  132. +
  133. + }
  134. + else if (mess.contains("jail"))
  135. + {
  136. + String[] split = mess.split(":");
  137. + L2PcInstance pl = L2World.getInstance().getPlayer(split[1]);
  138. + PunishmentManager.getInstance().startPunishment(new PunishmentTask(pl.getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.JAIL, 10000, "jailed", "Admin"));
  139. + }
  140. + if (mess.contains("ban"))
  141. + {
  142. + String[] split = mess.split(":");
  143. + L2PcInstance pl = L2World.getInstance().getPlayer(split[1]);
  144. + pl.setAccessLevel(-1);
  145. + }
  146. + if (mess.trim().equals("online"))
  147. + {
  148. + String online = null;
  149. + for (L2PcInstance onlines : L2World.getInstance().getAllPlayersArray())
  150. + {
  151. + online = onlines.getName() + ",";
  152. + }
  153. + }
  154. + if (mess.trim().equals("closing"))
  155. + {
  156. + connected = false;
  157. + System.out.println("Telnet closed");
  158. + }
  159. + }
  160. + else
  161. + {
  162. + System.out.println("Someone trying to send commands while not connected");
  163. + }
  164. + }
  165. + }
  166. +
  167. + public void sendData(byte[] data, InetAddress ipAddress, int port)
  168. + {
  169. + DatagramPacket packet = new DatagramPacket(data, data.length, ipAddress, port);
  170. + try
  171. + {
  172. + socket.send(packet);
  173. + }
  174. + catch (IOException e)
  175. + {
  176. + // TODO Auto-generated catch block
  177. + e.printStackTrace();
  178. + }
  179. + System.out.println("sent : " + new String(data));
  180. + }
  181. +
  182. + public static Telnet getInstance()
  183. + {
  184. + return SingletonHolder._instance;
  185. + }
  186. +
  187. + private static class SingletonHolder
  188. + {
  189. + @SuppressWarnings("synthetic-access")
  190. + protected static final Telnet _instance = new Telnet();
  191. + }
  192. +
  193. +}
  194. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement