diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index 102de532..3bbf0bdc 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -3,7 +3,7 @@ dependencies { compile project(':libLauncher') - compile 'javax.websocket:javax.websocket-client-api:1.1' + compileOnly 'javax.websocket:javax.websocket-client-api:1.1' compileOnly 'com.google.guava:guava:26.0-jre' compile files('../compat/authlib/authlib-clean.jar') } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java index 27521e73..1f1dc7fa 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java @@ -5,6 +5,8 @@ import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.RequestType; import ru.gravit.launcher.request.auth.AuthRequest.Result; +import ru.gravit.launcher.request.websockets.LegacyRequestBridge; +import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -67,9 +69,26 @@ public AuthRequest(String login, byte[] encryptedPassword, HWID hwid, int auth_i public Integer getType() { return RequestType.AUTH.getNumber(); } + /*public class EchoRequest implements RequestInterface + { + String echo; + public EchoRequest(String echo) { + this.echo = echo; + } + + @Override + public String getType() { + return "echo"; + } + }*/ @Override protected Result requestDo(HInput input, HOutput output) throws IOException { + /*try { + LegacyRequestBridge.sendRequest(new EchoRequest("Hello World!")); + } catch (InterruptedException e) { + e.printStackTrace(); + }*/ output.writeString(login, SerializeLimits.MAX_LOGIN); output.writeBoolean(Launcher.profile != null); if (Launcher.profile != null) 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 d6c9aa06..760fe522 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 @@ -1,8 +1,13 @@ package ru.gravit.launcher.request.websockets; +import com.google.gson.GsonBuilder; +import ru.gravit.launcher.Launcher; import ru.gravit.launcher.request.ResultInterface; +import javax.websocket.ContainerProvider; +import javax.websocket.WebSocketContainer; import java.io.IOException; +import java.net.URI; public class LegacyRequestBridge { public static WaitEventHandler waitEventHandler = new WaitEventHandler(); @@ -23,4 +28,18 @@ public static ResultInterface sendRequest(RequestInterface request) throws IOExc waitEventHandler.requests.remove(e); return result; } + public static void initWebSockets(String address, int port) + { + service = new ClientWebSocketService(new GsonBuilder()); + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + container.connectToServer(service, new URI("ws://".concat(address).concat(":".concat(String.valueOf(port)).concat("/api")))); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + static { + if(Launcher.getConfig().nettyPort != 0) + initWebSockets(Launcher.getConfig().address.getHostName(),Launcher.getConfig().nettyPort); + } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index ea50ef9d..15595196 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 int nettyPort; @LauncherAPI public final String projectname; public final int clientPort; @@ -54,6 +55,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException isDownloadJava = config.isDownloadJava; isUsingWrapper = config.isUsingWrapper; isWarningMissArchJava = config.isWarningMissArchJava; + nettyPort = config.nettyPort; LauncherEnvironment env; if (config.env == 0) env = LauncherEnvironment.DEV; else if (config.env == 1) env = LauncherEnvironment.DEBUG;