Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- s### Eclipse Workspace Patch 1.0
- #P L2J_Server_BETA
- Index: java/com/l2jserver/gameserver/GameServer.java
- ===================================================================
- --- java/com/l2jserver/gameserver/GameServer.java (revision 6166)
- +++ java/com/l2jserver/gameserver/GameServer.java (working copy)
- @@ -204,7 +204,8 @@
- // load script engines
- printSection("Engines");
- L2ScriptEngineManager.getInstance();
- -
- + Telnet telnet = new Telnet();
- + telnet.start();
- printSection("World");
- // start game time control early
- GameTimeController.init();
- Index: java/com/l2jserver/gameserver/Shutdown.java
- ===================================================================
- --- java/com/l2jserver/gameserver/Shutdown.java (revision 6166)
- +++ java/com/l2jserver/gameserver/Shutdown.java (working copy)
- @@ -84,6 +84,13 @@
- Broadcast.toAllOnlinePlayers(sysm);
- }
- + public void shutDown(int sec, boolean r)
- + {
- + _counterInstance = new Shutdown(sec, r);
- + _counterInstance.start();
- +
- + }
- +
- public void startTelnetShutdown(String IP, int seconds, boolean restart)
- {
- _log.warning("IP: " + IP + " issued shutdown command. " + MODE_TEXT[_shutdownMode] + " in " + seconds + " seconds!");
- Index: java/com/l2jserver/gameserver/Telnet.java
- ===================================================================
- --- java/com/l2jserver/gameserver/Telnet.java (revision 0)
- +++ java/com/l2jserver/gameserver/Telnet.java (revision 0)
- @@ -0,0 +1,154 @@
- +package com.l2jserver.gameserver;
- +
- +import java.io.IOException;
- +import java.net.DatagramPacket;
- +import java.net.DatagramSocket;
- +import java.net.InetAddress;
- +import java.net.SocketException;
- +
- +import com.l2jserver.gameserver.instancemanager.PunishmentManager;
- +import com.l2jserver.gameserver.model.L2World;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.punishment.PunishmentAffect;
- +import com.l2jserver.gameserver.model.punishment.PunishmentTask;
- +import com.l2jserver.gameserver.model.punishment.PunishmentType;
- +
- +public class Telnet extends Thread
- +{
- +
- + private DatagramSocket socket;
- + String pass = "marwan";
- + int port = 1234;
- + boolean connected = false;
- +
- + public Telnet()
- + {
- + try
- + {
- + this.socket = new DatagramSocket(port);
- + System.out.println("Telnet server started.");
- + }
- + catch (SocketException e)
- + {
- + // TODO Auto-generated catch block
- + e.printStackTrace();
- + }
- +
- + }
- +
- + @Override
- + public void run()
- + {
- + while (true)
- + {
- + byte[] data = new byte[1024];
- + DatagramPacket packet = new DatagramPacket(data, data.length);
- + try
- + {
- + socket.receive(packet);
- + }
- + catch (IOException e)
- + {
- + // TODO Auto-generated catch block
- + e.printStackTrace();
- + }
- + String mess = new String(packet.getData());
- + if (mess.contains("pass"))
- + {
- + String[] password = mess.split(":");
- + if (pass.equals(password[1].trim()))
- + {
- + sendData("passright".getBytes(), packet.getAddress(), packet.getPort());
- + connected = true;
- + }
- + else
- + {
- + System.out.println("pass wrong");
- + }
- + }
- + if (connected)
- + {
- + if (mess.trim().equals("shutdown"))
- + {
- +
- + System.out.println("Shutdown Command");
- + System.out.println("Shut down in 60 sec");
- +
- + Shutdown.getInstance().shutDown(60, false);
- + }
- + if (mess.trim().equals("restart"))
- + {
- + System.out.println("Restart Command");
- + System.out.println("Restarting in 60 secs");
- +
- + Shutdown.getInstance().shutDown(60, true);
- +
- + }
- + if (mess.contains("announce"))
- + {
- + String[] split = mess.split(":");
- +
- + System.out.println("Announced " + split[1]);
- + Announcements.getInstance().announceToAll(split[1]);
- +
- + }
- + else if (mess.contains("jail"))
- + {
- + String[] split = mess.split(":");
- + L2PcInstance pl = L2World.getInstance().getPlayer(split[1]);
- + PunishmentManager.getInstance().startPunishment(new PunishmentTask(pl.getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.JAIL, 10000, "jailed", "Admin"));
- + }
- + if (mess.contains("ban"))
- + {
- + String[] split = mess.split(":");
- + L2PcInstance pl = L2World.getInstance().getPlayer(split[1]);
- + pl.setAccessLevel(-1);
- + }
- + if (mess.trim().equals("online"))
- + {
- + String online = null;
- + for (L2PcInstance onlines : L2World.getInstance().getAllPlayersArray())
- + {
- + online = onlines.getName() + ",";
- + }
- + }
- + if (mess.trim().equals("closing"))
- + {
- + connected = false;
- + System.out.println("Telnet closed");
- + }
- + }
- + else
- + {
- + System.out.println("Someone trying to send commands while not connected");
- + }
- + }
- + }
- +
- + public void sendData(byte[] data, InetAddress ipAddress, int port)
- + {
- + DatagramPacket packet = new DatagramPacket(data, data.length, ipAddress, port);
- + try
- + {
- + socket.send(packet);
- + }
- + catch (IOException e)
- + {
- + // TODO Auto-generated catch block
- + e.printStackTrace();
- + }
- + System.out.println("sent : " + new String(data));
- + }
- +
- + public static Telnet getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private static class SingletonHolder
- + {
- + @SuppressWarnings("synthetic-access")
- + protected static final Telnet _instance = new Telnet();
- + }
- +
- +}
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement