This commit is contained in:
241
trunk/java/com/l2jserver/status/GameStatusThread.java
Normal file
241
trunk/java/com/l2jserver/status/GameStatusThread.java
Normal file
@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.status;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.gameserver.handler.ITelnetHandler;
|
||||
import com.l2jserver.gameserver.handler.TelnetHandler;
|
||||
|
||||
public class GameStatusThread extends Thread
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(GameStatusThread.class.getName());
|
||||
|
||||
private final Socket _cSocket;
|
||||
|
||||
private final PrintWriter _print;
|
||||
private final BufferedReader _read;
|
||||
|
||||
private final int _uptime;
|
||||
|
||||
private void telnetOutput(int type, String text)
|
||||
{
|
||||
if (Config.DEVELOPER)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// only print output if the message is rejected
|
||||
if (type == 5)
|
||||
{
|
||||
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, "");
|
||||
}
|
||||
|
||||
final File file = new File(Config.TELNET_FILE);
|
||||
try (InputStream telnetIS = new FileInputStream(file))
|
||||
{
|
||||
Properties telnetSettings = new Properties();
|
||||
telnetSettings.load(telnetIS);
|
||||
|
||||
String HostList = telnetSettings.getProperty("ListOfHosts", "127.0.0.1,localhost,::1");
|
||||
|
||||
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 GameStatusThread(Socket client, int uptime, String StatusPW) throws IOException
|
||||
{
|
||||
setPriority(Thread.MAX_PRIORITY);
|
||||
_cSocket = client;
|
||||
_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.equals(StatusPW))
|
||||
{
|
||||
_print.println("Incorrect Password!");
|
||||
_print.println("Disconnected...");
|
||||
_print.flush();
|
||||
_cSocket.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.println("Password Correct!");
|
||||
_print.println("[L2J Game Server]");
|
||||
_print.print("");
|
||||
_print.flush();
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
telnetOutput(5, "Connection attempt from " + client.getInetAddress().getHostAddress() + " rejected.");
|
||||
_cSocket.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
String _usrCommand = "";
|
||||
try
|
||||
{
|
||||
while ((_usrCommand.compareTo("quit") != 0) && (_usrCommand.compareTo("exit") != 0))
|
||||
{
|
||||
_usrCommand = _read.readLine();
|
||||
if (_usrCommand == null)
|
||||
{
|
||||
_cSocket.close();
|
||||
break;
|
||||
}
|
||||
|
||||
final ITelnetHandler handler = TelnetHandler.getInstance().getHandler(_usrCommand);
|
||||
if (handler != null)
|
||||
{
|
||||
handler.useCommand(_usrCommand, _print, _cSocket, _uptime);
|
||||
}
|
||||
else if (_usrCommand.equalsIgnoreCase("quit") || _usrCommand.equalsIgnoreCase("exit") || _usrCommand.isEmpty())
|
||||
{
|
||||
/* Do Nothing :p - Just here to save us from the "Command Not Understood" Text */
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.print("Command: " + _usrCommand + " was not found!");
|
||||
}
|
||||
|
||||
_print.print("");
|
||||
_print.flush();
|
||||
}
|
||||
if (!_cSocket.isClosed())
|
||||
{
|
||||
_print.println("Bye Bye!");
|
||||
_print.flush();
|
||||
_cSocket.close();
|
||||
}
|
||||
telnetOutput(1, "Connection from " + _cSocket.getInetAddress().getHostAddress() + " was closed by client.");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
296
trunk/java/com/l2jserver/status/LoginStatusThread.java
Normal file
296
trunk/java/com/l2jserver/status/LoginStatusThread.java
Normal file
@ -0,0 +1,296 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.status;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.loginserver.GameServerTable;
|
||||
import com.l2jserver.loginserver.L2LoginServer;
|
||||
import com.l2jserver.loginserver.LoginController;
|
||||
|
||||
public class LoginStatusThread extends Thread
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(LoginStatusThread.class.getName());
|
||||
|
||||
private final Socket _cSocket;
|
||||
|
||||
private final PrintWriter _print;
|
||||
private final BufferedReader _read;
|
||||
|
||||
private boolean _redirectLogger;
|
||||
|
||||
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, "");
|
||||
}
|
||||
|
||||
final File file = new File(Config.TELNET_FILE);
|
||||
try (InputStream telnetIS = new FileInputStream(file))
|
||||
{
|
||||
Properties telnetSettings = new Properties();
|
||||
telnetSettings.load(telnetIS);
|
||||
|
||||
String HostList = telnetSettings.getProperty("ListOfHosts", "127.0.0.1,localhost,::1");
|
||||
|
||||
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 LoginStatusThread(Socket client, int uptime, String StatusPW) throws IOException
|
||||
{
|
||||
_cSocket = client;
|
||||
|
||||
_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.equals(StatusPW))
|
||||
{
|
||||
_print.println("Incorrect Password!");
|
||||
_print.println("Disconnected...");
|
||||
_print.flush();
|
||||
_cSocket.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.println("Password Correct!");
|
||||
_print.println("[L2J Login Server]");
|
||||
_print.print("");
|
||||
_print.flush();
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
telnetOutput(5, "Connection attempt from " + client.getInetAddress().getHostAddress() + " rejected.");
|
||||
_cSocket.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
String _usrCommand = "";
|
||||
try
|
||||
{
|
||||
while ((_usrCommand.compareTo("quit") != 0) && (_usrCommand.compareTo("exit") != 0))
|
||||
{
|
||||
_usrCommand = _read.readLine();
|
||||
if (_usrCommand == null)
|
||||
{
|
||||
_cSocket.close();
|
||||
break;
|
||||
}
|
||||
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("unblock <ip> - removes <ip> from banlist.");
|
||||
_print.println("shutdown - shuts down server.");
|
||||
_print.println("restart - restarts the server.");
|
||||
_print.println("RedirectLogger - Telnet will give you some info about server in real time.");
|
||||
_print.println("quit - closes telnet session.");
|
||||
_print.println("");
|
||||
}
|
||||
else if (_usrCommand.equals("status"))
|
||||
{
|
||||
// TODO enhance the output
|
||||
_print.println("Registered Server Count: " + GameServerTable.getInstance().getRegisteredGameServers().size());
|
||||
}
|
||||
else if (_usrCommand.startsWith("unblock"))
|
||||
{
|
||||
try
|
||||
{
|
||||
_usrCommand = _usrCommand.substring(8);
|
||||
if (LoginController.getInstance().removeBanForAddress(_usrCommand))
|
||||
{
|
||||
_log.warning("IP removed via TELNET by host: " + _cSocket.getInetAddress().getHostAddress());
|
||||
_print.println("The IP " + _usrCommand + " has been removed from the hack protection list!");
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.println("IP not found in hack protection list...");
|
||||
}
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{
|
||||
_print.println("Please Enter the IP to Unblock!");
|
||||
}
|
||||
}
|
||||
else if (_usrCommand.startsWith("shutdown"))
|
||||
{
|
||||
L2LoginServer.getInstance().shutdown(false);
|
||||
_print.println("Bye Bye!");
|
||||
_print.flush();
|
||||
_cSocket.close();
|
||||
}
|
||||
else if (_usrCommand.startsWith("restart"))
|
||||
{
|
||||
L2LoginServer.getInstance().shutdown(true);
|
||||
_print.println("Bye Bye!");
|
||||
_print.flush();
|
||||
_cSocket.close();
|
||||
}
|
||||
else if (_usrCommand.equals("RedirectLogger"))
|
||||
{
|
||||
_redirectLogger = true;
|
||||
}
|
||||
else if (_usrCommand.equals("quit"))
|
||||
{ /* Do Nothing :p - Just here to save us from the "Command Not Understood" Text */
|
||||
}
|
||||
else if (_usrCommand.isEmpty())
|
||||
{ /* Do Nothing Again - Same reason as the quit part */
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.println("Invalid Command");
|
||||
}
|
||||
_print.print("");
|
||||
_print.flush();
|
||||
}
|
||||
if (!_cSocket.isClosed())
|
||||
{
|
||||
_print.println("Bye Bye!");
|
||||
_print.flush();
|
||||
_cSocket.close();
|
||||
}
|
||||
telnetOutput(1, "Connection from " + _cSocket.getInetAddress().getHostAddress() + " was closed by client.");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void printToTelnet(String msg)
|
||||
{
|
||||
synchronized (_print)
|
||||
{
|
||||
_print.println(msg);
|
||||
_print.flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the redirectLogger.
|
||||
*/
|
||||
public boolean isRedirectLogger()
|
||||
{
|
||||
return _redirectLogger;
|
||||
}
|
||||
}
|
170
trunk/java/com/l2jserver/status/Status.java
Normal file
170
trunk/java/com/l2jserver/status/Status.java
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.status;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javolution.util.FastList;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.Server;
|
||||
import com.l2jserver.util.Rnd;
|
||||
|
||||
public class Status extends Thread
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(Status.class.getName());
|
||||
|
||||
private final ServerSocket statusServerSocket;
|
||||
|
||||
private final int _uptime;
|
||||
private String _statusPw;
|
||||
private final int _mode;
|
||||
private final List<LoginStatusThread> _loginStatus;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
setPriority(Thread.MAX_PRIORITY);
|
||||
|
||||
while (!isInterrupted())
|
||||
{
|
||||
try
|
||||
{
|
||||
Socket connection = statusServerSocket.accept();
|
||||
if (_mode == Server.MODE_GAMESERVER)
|
||||
{
|
||||
new GameStatusThread(connection, _uptime, _statusPw);
|
||||
}
|
||||
else if (_mode == Server.MODE_LOGINSERVER)
|
||||
{
|
||||
LoginStatusThread lst = new LoginStatusThread(connection, _uptime, _statusPw);
|
||||
if (lst.isAlive())
|
||||
{
|
||||
_loginStatus.add(lst);
|
||||
}
|
||||
}
|
||||
if (isInterrupted())
|
||||
{
|
||||
try
|
||||
{
|
||||
statusServerSocket.close();
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": " + io.getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
if (isInterrupted())
|
||||
{
|
||||
try
|
||||
{
|
||||
statusServerSocket.close();
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": " + io.getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Status(int mode) throws IOException
|
||||
{
|
||||
super("Status");
|
||||
_mode = mode;
|
||||
Properties telnetSettings = new Properties();
|
||||
try (InputStream is = new FileInputStream(new File(Config.TELNET_FILE)))
|
||||
{
|
||||
telnetSettings.load(is);
|
||||
}
|
||||
int statusPort = Integer.parseInt(telnetSettings.getProperty("StatusPort", "12345"));
|
||||
_statusPw = telnetSettings.getProperty("StatusPW");
|
||||
|
||||
if ((_mode == Server.MODE_GAMESERVER) || (_mode == Server.MODE_LOGINSERVER))
|
||||
{
|
||||
if (_statusPw == null)
|
||||
{
|
||||
_log.info("Server's Telnet Function Has No Password Defined!");
|
||||
_log.info("A Password Has Been Automaticly Created!");
|
||||
_statusPw = rndPW(10);
|
||||
_log.info("Password Has Been Set To: " + _statusPw);
|
||||
}
|
||||
_log.info("Telnet StatusServer started successfully, listening on Port: " + statusPort);
|
||||
}
|
||||
statusServerSocket = new ServerSocket(statusPort);
|
||||
_uptime = (int) System.currentTimeMillis();
|
||||
_loginStatus = new FastList<>();
|
||||
}
|
||||
|
||||
private String rndPW(int length)
|
||||
{
|
||||
final String lowerChar = "qwertyuiopasdfghjklzxcvbnm";
|
||||
final String upperChar = "QWERTYUIOPASDFGHJKLZXCVBNM";
|
||||
final String digits = "1234567890";
|
||||
final StringBuilder password = new StringBuilder(length);
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int charSet = Rnd.nextInt(3);
|
||||
switch (charSet)
|
||||
{
|
||||
case 0:
|
||||
password.append(lowerChar.charAt(Rnd.nextInt(lowerChar.length() - 1)));
|
||||
break;
|
||||
case 1:
|
||||
password.append(upperChar.charAt(Rnd.nextInt(upperChar.length() - 1)));
|
||||
break;
|
||||
case 2:
|
||||
password.append(digits.charAt(Rnd.nextInt(digits.length() - 1)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return password.toString();
|
||||
}
|
||||
|
||||
public void sendMessageToTelnets(String msg)
|
||||
{
|
||||
List<LoginStatusThread> lsToRemove = new FastList<>();
|
||||
for (LoginStatusThread ls : _loginStatus)
|
||||
{
|
||||
if (ls.isInterrupted())
|
||||
{
|
||||
lsToRemove.add(ls);
|
||||
}
|
||||
else
|
||||
{
|
||||
ls.printToTelnet(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user