From 709efdd04e48684ff85ead5b63aca0d77a903ccd Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 20 Feb 2019 17:23:24 +0700 Subject: [PATCH] [FEATURE] nettyEnabled/nettyAddress --- .../src/main/java/ru/gravit/launcher/request/Request.java | 2 +- .../request/websockets/ClientWebSocketService.java | 8 ++++---- .../launcher/request/websockets/LegacyRequestBridge.java | 8 ++++---- .../src/main/java/ru/gravit/launcher/LauncherConfig.java | 6 ++++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java index 8d1dce9e..5eeba121 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java @@ -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 diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java index 513c1803..e49fb003 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -22,8 +22,8 @@ public class ClientWebSocketService extends ClientJSONPoint { private HashMap> results; private HashSet 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); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java index 72728fcb..bae9f897 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java @@ -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); } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index 6d21dfec..77dfebdc 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -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