Add CLI SOCKS5 proxy support (#447)
* Add CLI SOCKS5 proxy support: --proxy ip:port:user:pass | ip:port * Add more argument checks Ensures there wont be an array out of bounds exception. * Update RuneLite.java checkstyle fix * Update RuneLiteProperties.java checkstyle fix
This commit is contained in:
@@ -33,6 +33,8 @@ import com.google.inject.Injector;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.lang.management.RuntimeMXBean;
|
import java.lang.management.RuntimeMXBean;
|
||||||
|
import java.net.Authenticator;
|
||||||
|
import java.net.PasswordAuthentication;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
@@ -182,6 +184,10 @@ public class RuneLite
|
|||||||
parser.accepts("debug", "Show extra debugging output");
|
parser.accepts("debug", "Show extra debugging output");
|
||||||
parser.accepts("no-splash", "Do not show the splash screen");
|
parser.accepts("no-splash", "Do not show the splash screen");
|
||||||
|
|
||||||
|
final ArgumentAcceptingOptionSpec<String> proxyInfo = parser
|
||||||
|
.accepts("proxy")
|
||||||
|
.withRequiredArg().ofType(String.class);
|
||||||
|
|
||||||
final ArgumentAcceptingOptionSpec<ClientUpdateCheckMode> updateMode = parser
|
final ArgumentAcceptingOptionSpec<ClientUpdateCheckMode> updateMode = parser
|
||||||
.accepts("rs", "Select client type")
|
.accepts("rs", "Select client type")
|
||||||
.withRequiredArg()
|
.withRequiredArg()
|
||||||
@@ -199,6 +205,36 @@ public class RuneLite
|
|||||||
parser.accepts("help", "Show this text").forHelp();
|
parser.accepts("help", "Show this text").forHelp();
|
||||||
OptionSet options = parser.parse(args);
|
OptionSet options = parser.parse(args);
|
||||||
|
|
||||||
|
if (options.has("proxy"))
|
||||||
|
{
|
||||||
|
String[] proxy = options.valueOf(proxyInfo).split(":");
|
||||||
|
|
||||||
|
if (proxy.length >= 2)
|
||||||
|
{
|
||||||
|
System.setProperty("socksProxyHost", proxy[0]);
|
||||||
|
System.setProperty("socksProxyPort", proxy[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proxy.length >= 4)
|
||||||
|
{
|
||||||
|
System.setProperty("java.net.socks.username", proxy[2]);
|
||||||
|
System.setProperty("java.net.socks.password", proxy[3]);
|
||||||
|
|
||||||
|
final String user = proxy[2];
|
||||||
|
final char[] pass = proxy[3].toCharArray();
|
||||||
|
|
||||||
|
Authenticator.setDefault(new Authenticator()
|
||||||
|
{
|
||||||
|
private PasswordAuthentication auth = new PasswordAuthentication(user, pass);
|
||||||
|
|
||||||
|
protected PasswordAuthentication getPasswordAuthentication()
|
||||||
|
{
|
||||||
|
return auth;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (options.has("help"))
|
if (options.has("help"))
|
||||||
{
|
{
|
||||||
parser.printHelpOn(System.out);
|
parser.printHelpOn(System.out);
|
||||||
|
|||||||
@@ -65,7 +65,13 @@ public class RuneLiteProperties
|
|||||||
|
|
||||||
public String getTitle()
|
public String getTitle()
|
||||||
{
|
{
|
||||||
return properties.getProperty(RUNELITE_TITLE);
|
final StringBuilder sb = new StringBuilder(properties.getProperty(RUNELITE_TITLE));
|
||||||
|
String proxy;
|
||||||
|
if ((proxy = System.getProperty("socksProxyHost")) != null)
|
||||||
|
{
|
||||||
|
sb.append(String.format(" (%s)", proxy));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion()
|
public String getVersion()
|
||||||
|
|||||||
Reference in New Issue
Block a user