Index: C:/Documents and Settings/Administrator/Desktop/eclipse/workspace/L2_GameServer/java/config/telnet.properties =================================================================== --- C:/Documents and Settings/Administrator/Desktop/eclipse/workspace/L2_GameServer/java/config/telnet.properties (revision 0) +++ C:/Documents and Settings/Administrator/Desktop/eclipse/workspace/L2_GameServer/java/config/telnet.properties (revision 0) @@ -0,0 +1,15 @@ +#Telnet is disabled by default. +EnableTelnet = false + +#This is the port telnet server will bind to +StatusPort = 12345 + +#If the following is not set, a random password is generated on server startup. +#StatusPW = somePass + +#This list can contain IPs or Hosts of clients you wish to allow. +#Hosts must be resolvable to an IP. +#The format is as follows: +#ListOfHosts = 0.0.0.0,host,0.0.0.1,host2,host3,host4,0.0.0.3 +#Make sure there are no spaces between hosts/ips +ListOfHosts = 127.0.0.1,localhost Index: C:/Documents and Settings/Administrator/Desktop/eclipse/workspace/L2_GameServer/java/net/sf/l2j/status/Status.java =================================================================== --- C:/Documents and Settings/Administrator/Desktop/eclipse/workspace/L2_GameServer/java/net/sf/l2j/status/Status.java (revision 0) +++ C:/Documents and Settings/Administrator/Desktop/eclipse/workspace/L2_GameServer/java/net/sf/l2j/status/Status.java (revision 0) @@ -0,0 +1,107 @@ +package net.sf.l2j.status; + +import java.io.IOException; +import java.io.InputStream; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.Properties; +import java.util.Random; + +import net.sf.l2j.Config; + + +public class Status extends Thread +{ + + private ServerSocket statusServerSocket; + + private int _uptime; + private int _StatusPort; + private String _StatusPW; + + public void run() + { + while (true) + { + try + { + Socket connection = statusServerSocket.accept(); + + new StatusThread(connection, _uptime, _StatusPW); + if (this.isInterrupted()) + { + try + { + statusServerSocket.close(); + } + catch (IOException io) { io.printStackTrace(); } + break; + } + } + catch (IOException e) + { + if (this.isInterrupted()) + { + try + { + statusServerSocket.close(); + } + catch (IOException io) { io.printStackTrace(); } + break; + } + } + } + } + + public Status() throws IOException + { + super("Status"); + Properties telnetSettings = new Properties(); + InputStream is = getClass().getResourceAsStream(Config.TELNET_FILE); + telnetSettings.load(is); + is.close(); + + _StatusPort = Integer.parseInt(telnetSettings.getProperty("StatusPort", "25650")); + _StatusPW = telnetSettings.getProperty("StatusPW"); + + if (_StatusPW == null) + { + System.out.println("Server's Telnet Function Has No Password Defined!"); + System.out.println("A Password Has Been Automaticly Created!"); + _StatusPW = RndPW(10); + System.out.println("Password Has Been Set To: " + _StatusPW); + } + statusServerSocket = new ServerSocket(_StatusPort); + _uptime = (int) System.currentTimeMillis(); + System.out.println("StatusServer Started! - Listening on Port: " + _StatusPort); + System.out.println("Password Has Been Set To: " + _StatusPW); + } + + + + private String RndPW(int length) + { + StringBuffer password = new StringBuffer(); + String lowerChar= "qwertyuiopasdfghjklzxcvbnm"; + String upperChar = "QWERTYUIOPASDFGHJKLZXCVBNM"; + String digits = "1234567890"; + Random randInt = new Random(); + for (int i = 0; i < length; i++) + { + int charSet = randInt.nextInt(3); + switch (charSet) + { + case 0: + password.append(lowerChar.charAt(randInt.nextInt(lowerChar.length()-1))); + break; + case 1: + password.append(upperChar.charAt(randInt.nextInt(upperChar.length()-1))); + break; + case 2: + password.append(digits.charAt(randInt.nextInt(digits.length()-1))); + break; + } + } + return password.toString(); + } +} Index: C:/Documents and Settings/Administrator/Desktop/eclipse/workspace/L2_GameServer/java/net/sf/l2j/status/StatusThread.java =================================================================== --- C:/Documents and Settings/Administrator/Desktop/eclipse/workspace/L2_GameServer/java/net/sf/l2j/status/StatusThread.java (revision 0) +++ C:/Documents and Settings/Administrator/Desktop/eclipse/workspace/L2_GameServer/java/net/sf/l2j/status/StatusThread.java (revision 0) @@ -0,0 +1,345 @@ +package net.sf.l2j.status; + + +import java.io.IOException; + +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.BufferedReader; +import java.io.InputStreamReader; + + +import java.net.InetAddress; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Hashtable; +import java.util.Properties; +import java.util.StringTokenizer; + + +import net.sf.l2j.Config; +import net.sf.l2j.gameserver.Announcements; + +import net.sf.l2j.gameserver.GmListTable; +import net.sf.l2j.gameserver.GameTimeController; +import net.sf.l2j.gameserver.Shutdown; +import net.sf.l2j.gameserver.serverpackets.CreatureSay; +import net.sf.l2j.gameserver.clientpackets.Say2; +import net.sf.l2j.gameserver.model.L2PcInstance; +import net.sf.l2j.gameserver.model.L2World; +import net.sf.l2j.loginserver.LoginController; + + +public class StatusThread extends Thread +{ + + private Socket _csocket; + + private PrintWriter _print; + private BufferedReader _read; + + private int _uptime; + + private void telnetOutput(int type, String text) { + if ( type == 1 ) System.out.println("TELNET | "+text); + else if ( type == 2 ) System.out.print("TELNET | "+text); + else if ( type == 3 ) System.out.print(text); + else if ( type == 4 ) System.out.println(text); + else System.out.println("TELNET | "+text); + } + + private boolean isValidIP(Socket client) { + boolean result = false; + InetAddress ClientIP = client.getInetAddress(); + + // convert IP to String, and compare with list + String clientStringIP = ClientIP.getHostAddress(); + + telnetOutput(1, "Connection from: "+clientStringIP); + + // read and loop thru list of IPs, compare with newIP + if ( Config.DEVELOPER ) telnetOutput(2, ""); + + try { + Properties telnetSettings = new Properties(); + InputStream telnetIS = getClass().getResourceAsStream(Config.TELNET_FILE); + telnetSettings.load(telnetIS); + telnetIS.close(); + + String HostList = telnetSettings.getProperty("ListOfHosts", "127.0.0.1,localhost"); + + if ( Config.DEVELOPER ) telnetOutput(3, "Comparing ip to list..."); + + // compare + String ipToCompare = null; + for (String ip:HostList.split(",")) { + if ( !result ) { + ipToCompare = InetAddress.getByName(ip).getHostAddress(); + if ( clientStringIP.equals(ipToCompare) ) result = true; + if ( Config.DEVELOPER ) telnetOutput(3, clientStringIP + " = " + ipToCompare + "("+ip+") = " + result); + } + } + } + catch ( IOException e) { + if ( Config.DEVELOPER ) telnetOutput(4, ""); + telnetOutput(1, "Error: "+e); + } + + if ( Config.DEVELOPER ) telnetOutput(4, "Allow IP: "+result); + return result; + } + + public StatusThread(Socket client, int uptime, String StatusPW) throws IOException + { + _csocket = client; + this._uptime = uptime; + + _print = new PrintWriter(_csocket.getOutputStream()); + _read = new BufferedReader(new InputStreamReader(_csocket.getInputStream())); + + if ( isValidIP(client) ) { + telnetOutput(1, client.getInetAddress().getHostAddress()+" accepted."); + _print.println("Welcome To The L2J Telnet Session."); + _print.println("Please Insert Your Password!"); + _print.print("Password: "); + _print.flush(); + String tmpLine = _read.readLine(); + if ( tmpLine == null ) { + _print.println("Error."); + _print.println("Disconnected..."); + _print.flush(); + _csocket.close(); + } + else { + if (tmpLine.compareTo(StatusPW) != 0) + { + _print.println("Incorrect Password!"); + _print.println("Disconnected..."); + _print.flush(); + _csocket.close(); + } + else + { + _print.println("Password Correct!"); + _print.println("[L2J]"); + _print.print(""); + _print.flush(); + start(); + } + } + } + else { + telnetOutput(1, "Connection attempt from "+ client.getInetAddress().getHostAddress() +" rejected."); + _csocket.close(); + } + } + + public void run() + { + String _usrCommand = ""; + try + { + while (_usrCommand.compareTo("quit") != 0) + { + _usrCommand = _read.readLine(); + if (_usrCommand.equals("help")) { + _print.println("The following is a list of all available commands: "); + _print.println("help - shows this help."); + _print.println("status - displays basic server statistics."); + _print.println("announce - announces in game."); + _print.println("msg - Sends a whisper to char with ."); + _print.println("gmchat - Sends a message to all GMs with ."); + _print.println("gmlist - lists all gms online."); + _print.println("shutdown