mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +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;
|
||||||
@@ -53,7 +57,8 @@ public final class Landing {
|
|||||||
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
|
||||||
|
&& (password = getCredentials()[1]) != null) {
|
||||||
new BotUI(username, password);
|
new BotUI(username, password);
|
||||||
}
|
}
|
||||||
username = null;
|
username = null;
|
||||||
@@ -70,13 +75,14 @@ public final class Landing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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(
|
||||||
|
Configuration.GET_PASSWORD));
|
||||||
if (bufferedReader.readLine() != null) {
|
if (bufferedReader.readLine() != null) {
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -91,7 +97,8 @@ public final class Landing {
|
|||||||
switch (arg.toLowerCase()) {
|
switch (arg.toLowerCase()) {
|
||||||
case "-createdirs":
|
case "-createdirs":
|
||||||
Directories.validate();
|
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);
|
System.exit(0);
|
||||||
break;
|
break;
|
||||||
case "-debug":
|
case "-debug":
|
||||||
@@ -130,10 +137,33 @@ public final class Landing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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