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:
LoudPacks
2019-05-30 12:36:40 -04:00
committed by Kyleeld
parent 23fdaf78cd
commit 3465cc3269
2 changed files with 44 additions and 2 deletions

View File

@@ -33,6 +33,8 @@ import com.google.inject.Injector;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Locale;
import javax.annotation.Nullable;
import javax.inject.Provider;
@@ -182,6 +184,10 @@ public class RuneLite
parser.accepts("debug", "Show extra debugging output");
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
.accepts("rs", "Select client type")
.withRequiredArg()
@@ -199,6 +205,36 @@ public class RuneLite
parser.accepts("help", "Show this text").forHelp();
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"))
{
parser.printHelpOn(System.out);