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