mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 08:39:12 +00:00
Added Network command args (-auth for authentication, -mac for mac address, and -proxy to set proxy)
This commit is contained in:
@@ -4,12 +4,16 @@ import org.parabot.core.Configuration;
|
|||||||
import org.parabot.core.Core;
|
import org.parabot.core.Core;
|
||||||
import org.parabot.core.Directories;
|
import org.parabot.core.Directories;
|
||||||
import org.parabot.core.forum.AccountManager;
|
import org.parabot.core.forum.AccountManager;
|
||||||
|
import org.parabot.core.network.NetworkInterface;
|
||||||
|
import org.parabot.core.network.proxy.ProxySocket;
|
||||||
|
import org.parabot.core.network.proxy.ProxyType;
|
||||||
import org.parabot.core.ui.BotUI;
|
import org.parabot.core.ui.BotUI;
|
||||||
import org.parabot.core.ui.ServerSelector;
|
import org.parabot.core.ui.ServerSelector;
|
||||||
import org.parabot.core.ui.utils.UILog;
|
import org.parabot.core.ui.utils.UILog;
|
||||||
import org.parabot.environment.api.utils.WebUtil;
|
import org.parabot.environment.api.utils.WebUtil;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -23,117 +27,143 @@ import java.net.URL;
|
|||||||
* @see <a href="http://www.parabot.org">Homepage</a>
|
* @see <a href="http://www.parabot.org">Homepage</a>
|
||||||
*/
|
*/
|
||||||
public final class Landing {
|
public final class Landing {
|
||||||
private static String username;
|
private static String username;
|
||||||
private static String password;
|
private static String password;
|
||||||
|
|
||||||
public static void main(String... args) throws IOException {
|
public static void main(String... args) throws IOException {
|
||||||
parseArgs(args);
|
parseArgs(args);
|
||||||
|
|
||||||
Core.verbose("Debug mode: " + Core.inDebugMode());
|
Core.verbose("Debug mode: " + Core.inDebugMode());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Core.verbose("Setting look and feel: "
|
Core.verbose("Setting look and feel: "
|
||||||
+ UIManager.getSystemLookAndFeelClassName());
|
+ UIManager.getSystemLookAndFeelClassName());
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Core.inDebugMode() && !Core.isValid()) {
|
if (!Core.inDebugMode() && !Core.isValid()) {
|
||||||
UILog.log(
|
UILog.log(
|
||||||
"Updates",
|
"Updates",
|
||||||
"Please download the newest version of parabot at http://www.parabot.org/",
|
"Please download the newest version of parabot at http://www.parabot.org/",
|
||||||
JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core.verbose("Validating directories...");
|
Core.verbose("Validating directories...");
|
||||||
Directories.validate();
|
Directories.validate();
|
||||||
Core.verbose("Validating account manager...");
|
Core.verbose("Validating account manager...");
|
||||||
AccountManager.validate();
|
AccountManager.validate();
|
||||||
|
|
||||||
if (getCredentials() != null && getCredentials().length == 2){
|
if (getCredentials() != null && getCredentials().length == 2) {
|
||||||
if ((username = getCredentials()[0]) != null && (password = getCredentials()[1]) != null){
|
if ((username = getCredentials()[0]) != null
|
||||||
new BotUI(username, password);
|
&& (password = getCredentials()[1]) != null) {
|
||||||
}
|
new BotUI(username, password);
|
||||||
username = null;
|
}
|
||||||
password = null;
|
username = null;
|
||||||
}else if (username != null && password != null) {
|
password = null;
|
||||||
new BotUI(username, password);
|
} else if (username != null && password != null) {
|
||||||
username = null;
|
new BotUI(username, password);
|
||||||
password = null;
|
username = null;
|
||||||
return;
|
password = null;
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Core.verbose("Starting login gui...");
|
Core.verbose("Starting login gui...");
|
||||||
new BotUI(null, null);
|
new BotUI(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO Returns an array of string containing only the username and password
|
||||||
* Returns an array of string containing only the username and password
|
*
|
||||||
* @return String array with username and password
|
* @return String array with username and password
|
||||||
*/
|
*/
|
||||||
private static String[] getCredentials(){
|
private static String[] getCredentials() {
|
||||||
try {
|
try {
|
||||||
BufferedReader bufferedReader = WebUtil.getReader(new URL(Configuration.GET_PASSWORD));
|
BufferedReader bufferedReader = WebUtil.getReader(new URL(
|
||||||
if (bufferedReader.readLine() != null){
|
Configuration.GET_PASSWORD));
|
||||||
}
|
if (bufferedReader.readLine() != null) {
|
||||||
} catch (IOException e) {
|
}
|
||||||
e.printStackTrace();
|
} catch (IOException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
return null;
|
}
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
private static void parseArgs(String... args) {
|
|
||||||
for (int i = 0; i < args.length; i++) {
|
|
||||||
final String arg = args[i].toLowerCase();
|
|
||||||
switch (arg.toLowerCase()) {
|
|
||||||
case "-createdirs":
|
|
||||||
Directories.validate();
|
|
||||||
System.out.println("Directories created, you can now run parabot.");
|
|
||||||
System.exit(0);
|
|
||||||
break;
|
|
||||||
case "-debug":
|
|
||||||
Core.setDebug(true);
|
|
||||||
break;
|
|
||||||
case "-v":
|
|
||||||
case "-verbose":
|
|
||||||
Core.setVerbose(true);
|
|
||||||
break;
|
|
||||||
case "-server":
|
|
||||||
ServerSelector.initServer = args[++i];
|
|
||||||
break;
|
|
||||||
case "-login":
|
|
||||||
username = args[++i];
|
|
||||||
password = args[++i];
|
|
||||||
break;
|
|
||||||
case "-loadlocal":
|
|
||||||
Core.setLoadLocal(true);
|
|
||||||
break;
|
|
||||||
case "-dump":
|
|
||||||
Core.setDump(true);
|
|
||||||
break;
|
|
||||||
case "-scriptsbin":
|
|
||||||
Directories.setScriptCompiledDirectory(new File(args[++i]));
|
|
||||||
break;
|
|
||||||
case "-serversbin":
|
|
||||||
Directories.setServerCompiledDirectory(new File(args[++i]));
|
|
||||||
break;
|
|
||||||
case "-clearcache":
|
|
||||||
File[] cache = Directories.getCachePath().listFiles();
|
|
||||||
if (cache != null) {
|
|
||||||
for (File f : cache) {
|
|
||||||
if (f.exists() && f.canWrite()) {
|
|
||||||
f.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private static void parseArgs(String... args) {
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
final String arg = args[i].toLowerCase();
|
||||||
|
switch (arg.toLowerCase()) {
|
||||||
|
case "-createdirs":
|
||||||
|
Directories.validate();
|
||||||
|
System.out
|
||||||
|
.println("Directories created, you can now run parabot.");
|
||||||
|
System.exit(0);
|
||||||
|
break;
|
||||||
|
case "-debug":
|
||||||
|
Core.setDebug(true);
|
||||||
|
break;
|
||||||
|
case "-v":
|
||||||
|
case "-verbose":
|
||||||
|
Core.setVerbose(true);
|
||||||
|
break;
|
||||||
|
case "-server":
|
||||||
|
ServerSelector.initServer = args[++i];
|
||||||
|
break;
|
||||||
|
case "-login":
|
||||||
|
username = args[++i];
|
||||||
|
password = args[++i];
|
||||||
|
break;
|
||||||
|
case "-loadlocal":
|
||||||
|
Core.setLoadLocal(true);
|
||||||
|
break;
|
||||||
|
case "-dump":
|
||||||
|
Core.setDump(true);
|
||||||
|
break;
|
||||||
|
case "-scriptsbin":
|
||||||
|
Directories.setScriptCompiledDirectory(new File(args[++i]));
|
||||||
|
break;
|
||||||
|
case "-serversbin":
|
||||||
|
Directories.setServerCompiledDirectory(new File(args[++i]));
|
||||||
|
break;
|
||||||
|
case "-clearcache":
|
||||||
|
File[] cache = Directories.getCachePath().listFiles();
|
||||||
|
if (cache != null) {
|
||||||
|
for (File f : cache) {
|
||||||
|
if (f.exists() && f.canWrite()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "-mac":
|
||||||
|
byte[] mac = new byte[6];
|
||||||
|
String str = args[++i];
|
||||||
|
if (str.toLowerCase().equals("random")) {
|
||||||
|
new java.util.Random().nextBytes(mac);
|
||||||
|
} else {
|
||||||
|
for(int j = 0; j < 6;j++){
|
||||||
|
mac[j] = Byte.parseByte(args[++i], 16); // parses a hex number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NetworkInterface.setMac(mac);
|
||||||
|
break;
|
||||||
|
case "-proxy":
|
||||||
|
ProxyType type = ProxyType.valueOf(args[i++].toUpperCase());
|
||||||
|
if(type == null){
|
||||||
|
System.err.println("Invalid proxy type:" + args[i]);
|
||||||
|
System.exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProxySocket.setProxy(type, args[++i], Integer.parseInt(args[++i]));
|
||||||
|
break;
|
||||||
|
case "-auth":
|
||||||
|
ProxySocket.auth = true;
|
||||||
|
ProxySocket.setLogin(args[++i], args[++i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -59,4 +59,19 @@ public class NetworkInterface {
|
|||||||
cached = new NetworkInterface();
|
cached = new NetworkInterface();
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setMac(byte[] mac2) {
|
||||||
|
System.out.println("Setting mac address to:" + formatMac(mac2));
|
||||||
|
mac = mac2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String formatMac(byte[] mac){
|
||||||
|
StringBuffer b = new StringBuffer();
|
||||||
|
for(int i = 0; i < 6;i++){
|
||||||
|
b.append(String.format("%02X", mac[i]));
|
||||||
|
if(i < 5)
|
||||||
|
b.append(':');
|
||||||
|
}
|
||||||
|
return b.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,11 +90,7 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
|
|||||||
submitButton.addActionListener(this);
|
submitButton.addActionListener(this);
|
||||||
|
|
||||||
byte[] mac = new byte[6];
|
byte[] mac = new byte[6];
|
||||||
try {
|
mac = NetworkInterface.mac;
|
||||||
mac = NetworkInterface.getRealHardwareAddress();
|
|
||||||
} catch (SocketException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
macList = new JList[mac.length];
|
macList = new JList[mac.length];
|
||||||
macScrollList = new JScrollPane[mac.length];
|
macScrollList = new JScrollPane[mac.length];
|
||||||
for (int i = 0; i < mac.length; i++) {
|
for (int i = 0; i < mac.length; i++) {
|
||||||
@@ -259,7 +255,7 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
|
|||||||
for (int i = 0; i < mac.length; i++)
|
for (int i = 0; i < mac.length; i++)
|
||||||
mac[i] = (byte) Short.parseShort(
|
mac[i] = (byte) Short.parseShort(
|
||||||
(String) macList[i].getSelectedValue(), 16);
|
(String) macList[i].getSelectedValue(), 16);
|
||||||
NetworkInterface.mac = mac;
|
NetworkInterface.setMac(mac);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ProxySocket.getConnectionCount() > 0) {
|
if (ProxySocket.getConnectionCount() > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user