mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-10-01 02:17:22 +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.Directories;
|
||||
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.ServerSelector;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -53,7 +57,8 @@ public final class Landing {
|
||||
AccountManager.validate();
|
||||
|
||||
if (getCredentials() != null && getCredentials().length == 2) {
|
||||
if ((username = getCredentials()[0]) != null && (password = getCredentials()[1]) != null){
|
||||
if ((username = getCredentials()[0]) != null
|
||||
&& (password = getCredentials()[1]) != null) {
|
||||
new BotUI(username, password);
|
||||
}
|
||||
username = null;
|
||||
@@ -70,13 +75,14 @@ public final class Landing {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Returns an array of string containing only the username and password
|
||||
* TODO Returns an array of string containing only the username and password
|
||||
*
|
||||
* @return String array with username and password
|
||||
*/
|
||||
private static String[] getCredentials() {
|
||||
try {
|
||||
BufferedReader bufferedReader = WebUtil.getReader(new URL(Configuration.GET_PASSWORD));
|
||||
BufferedReader bufferedReader = WebUtil.getReader(new URL(
|
||||
Configuration.GET_PASSWORD));
|
||||
if (bufferedReader.readLine() != null) {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -91,7 +97,8 @@ public final class Landing {
|
||||
switch (arg.toLowerCase()) {
|
||||
case "-createdirs":
|
||||
Directories.validate();
|
||||
System.out.println("Directories created, you can now run parabot.");
|
||||
System.out
|
||||
.println("Directories created, you can now run parabot.");
|
||||
System.exit(0);
|
||||
break;
|
||||
case "-debug":
|
||||
@@ -130,10 +137,33 @@ public final class Landing {
|
||||
}
|
||||
}
|
||||
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();
|
||||
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);
|
||||
|
||||
byte[] mac = new byte[6];
|
||||
try {
|
||||
mac = NetworkInterface.getRealHardwareAddress();
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mac = NetworkInterface.mac;
|
||||
macList = new JList[mac.length];
|
||||
macScrollList = new JScrollPane[mac.length];
|
||||
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++)
|
||||
mac[i] = (byte) Short.parseShort(
|
||||
(String) macList[i].getSelectedValue(), 16);
|
||||
NetworkInterface.mac = mac;
|
||||
NetworkInterface.setMac(mac);
|
||||
|
||||
try {
|
||||
if (ProxySocket.getConnectionCount() > 0) {
|
||||
|
||||
Reference in New Issue
Block a user