fix: proxy settings not applied to game
This commit is contained in:
@@ -21,6 +21,7 @@ import org.jackhuang.hmcl.util.platform.JavaVersion;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.net.Proxy;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -43,8 +44,7 @@ public class LaunchOptions implements Serializable {
|
||||
private boolean fullscreen;
|
||||
private String serverIp;
|
||||
private String wrapper;
|
||||
private String proxyHost;
|
||||
private int proxyPort;
|
||||
private Proxy proxy;
|
||||
private String proxyUser;
|
||||
private String proxyPass;
|
||||
private boolean noGeneratedJVMArgs;
|
||||
@@ -160,17 +160,10 @@ public class LaunchOptions implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* The host of the proxy address
|
||||
* Proxy settings
|
||||
*/
|
||||
public String getProxyHost() {
|
||||
return proxyHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* the port of the proxy address.
|
||||
*/
|
||||
public int getProxyPort() {
|
||||
return proxyPort;
|
||||
public Proxy getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,13 +277,8 @@ public class LaunchOptions implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setProxyHost(String proxyHost) {
|
||||
options.proxyHost = proxyHost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setProxyPort(int proxyPort) {
|
||||
options.proxyPort = proxyPort;
|
||||
public Builder setProxy(Proxy proxy) {
|
||||
options.proxy = proxy;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -133,6 +135,22 @@ public class DefaultLauncher extends Launcher {
|
||||
res.add("-Dfml.ignorePatchDiscrepancies=true");
|
||||
}
|
||||
|
||||
Proxy proxy = options.getProxy();
|
||||
if (proxy != null && StringUtils.isBlank(options.getProxyUser()) && StringUtils.isBlank(options.getProxyPass())) {
|
||||
InetSocketAddress address = (InetSocketAddress) options.getProxy().address();
|
||||
String host = address.getHostString();
|
||||
int port = address.getPort();
|
||||
if (proxy.type() == Proxy.Type.HTTP) {
|
||||
res.add("-Dhttp.proxyHost=" + host);
|
||||
res.add("-Dhttp.proxyPort=" + port);
|
||||
res.add("-Dhttps.proxyHost=" + host);
|
||||
res.add("-Dhttps.proxyPort=" + port);
|
||||
} else if (proxy.type() == Proxy.Type.SOCKS) {
|
||||
res.add("-DsocksProxyHost=" + host);
|
||||
res.add("-DsocksProxyPort=" + port);
|
||||
}
|
||||
}
|
||||
|
||||
LinkedList<String> classpath = new LinkedList<>();
|
||||
for (Library library : version.getLibraries())
|
||||
if (library.appliesToCurrentEnvironment() && !library.isNative()) {
|
||||
@@ -182,11 +200,12 @@ public class DefaultLauncher extends Launcher {
|
||||
if (options.isFullscreen())
|
||||
res.add("--fullscreen");
|
||||
|
||||
if (StringUtils.isNotBlank(options.getProxyHost())) {
|
||||
if (options.getProxy() != null) {
|
||||
InetSocketAddress address = (InetSocketAddress) options.getProxy().address();
|
||||
res.add("--proxyHost");
|
||||
res.add(options.getProxyHost());
|
||||
res.add(address.getHostString());
|
||||
res.add("--proxyPort");
|
||||
res.add(String.valueOf(options.getProxyPort()));
|
||||
res.add(String.valueOf(address.getPort()));
|
||||
if (StringUtils.isNotBlank(options.getProxyUser()) && StringUtils.isNotBlank(options.getProxyPass())) {
|
||||
res.add("--proxyUser");
|
||||
res.add(options.getProxyUser());
|
||||
|
||||
Reference in New Issue
Block a user