[FEATURE] nettyEnabled/nettyAddress

This commit is contained in:
Gravit 2019-02-20 17:23:24 +07:00
parent 2fa638d3c6
commit 709efdd04e
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 15 additions and 9 deletions

View file

@ -58,7 +58,7 @@ public R request() throws Exception {
if (!started.compareAndSet(false, true))
throw new IllegalStateException("Request already started");
R wsResult = null;
if(config.nettyPort != 0)
if(config.isNettyEnabled)
wsResult = requestWebSockets();
if(wsResult != null) return wsResult;
// Make request to LaunchServer

View file

@ -22,8 +22,8 @@ public class ClientWebSocketService extends ClientJSONPoint {
private HashMap<String, Class<? extends ResultInterface>> results;
private HashSet<EventHandler> handlers;
public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int port, int i) {
super(createURL(address, port), Collections.emptyMap(), i);
public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) {
super(createURL(address), Collections.emptyMap(), i);
requests = new HashMap<>();
results = new HashMap<>();
handlers = new HashSet<>();
@ -33,9 +33,9 @@ public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int port,
this.gsonBuilder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter());
this.gson = gsonBuilder.create();
}
private static URI createURL(String address, int port) {
private static URI createURL(String address) {
try {
URI u = new URI("ws://".concat(address).concat(":").concat(String.valueOf(port)).concat("/api"));
URI u = new URI(address);
return u;
} catch (Throwable e) {
LogHelper.error(e);

View file

@ -33,21 +33,21 @@ public static ResultInterface sendRequest(RequestInterface request) throws IOExc
}
return result;
}
public static void initWebSockets(String address, int port)
public static void initWebSockets(String address)
{
service = new ClientWebSocketService(new GsonBuilder(), address, port, 5000);
service = new ClientWebSocketService(new GsonBuilder(), address, 5000);
service.registerResults();
service.registerRequests();
service.registerHandler(waitEventHandler);
try {
if(!service.connectBlocking()) LogHelper.error("Error connecting");
LogHelper.debug("Connect to %s:%d",address,port);
LogHelper.debug("Connect to %s",address);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
static {
if(Launcher.getConfig().nettyPort != 0)
initWebSockets(Launcher.getConfig().address.getHostName(),Launcher.getConfig().nettyPort);
initWebSockets(Launcher.getConfig().nettyAddress);
}
}

View file

@ -28,6 +28,7 @@ public static AutogenConfig getAutogenConfig() {
// Instance
@LauncherAPI
public InetSocketAddress address;
public String nettyAddress;
public int nettyPort;
@LauncherAPI
public final String projectname;
@ -42,6 +43,7 @@ public static AutogenConfig getAutogenConfig() {
public final boolean isUsingWrapper;
public final boolean isDownloadJava;
public final boolean isWarningMissArchJava;
public final boolean isNettyEnabled;
public final String guardLicenseName;
public final String guardLicenseKey;
@ -63,6 +65,8 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
guardLicenseKey = config.guardLicenseKey;
guardLicenseName = config.guardLicenseName;
nettyPort = config.nettyPort;
nettyAddress = config.nettyAddress;
isNettyEnabled = config.isNettyEnabled;
LauncherEnvironment env;
if (config.env == 0) env = LauncherEnvironment.DEV;
else if (config.env == 1) env = LauncherEnvironment.DEBUG;
@ -99,6 +103,7 @@ public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<Stri
isUsingWrapper = true;
isDownloadJava = false;
isWarningMissArchJava = true;
isNettyEnabled = false;
}
@LauncherAPI
@ -114,6 +119,7 @@ public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<Stri
isUsingWrapper = true;
isDownloadJava = false;
isWarningMissArchJava = true;
isNettyEnabled = false;
}
@Override