From 91d26907614d999b03ae934369d50cd8b0ec81ba Mon Sep 17 00:00:00 2001 From: Zaxar163 <35835496+Zaxar163@users.noreply.github.com> Date: Mon, 29 Apr 2019 03:30:56 +0200 Subject: [PATCH 01/10] =?UTF-8?q?[FIX]=20=D0=AD=D0=BA=D1=81=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D1=84=D0=B8=D0=BA=D1=81=20=D0=B1=D0=B0=D0=B3?= =?UTF-8?q?=D0=B0=20=D1=81=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D0=B5=D0=BC=20=D1=80=D0=B5=D0=BA=D0=BE=D0=BD=D0=BD?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B0.=20(#238)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launcher/LauncherEngine.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 6990a706..f0b096ce 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -9,6 +9,7 @@ import ru.gravit.launcher.managers.ClientGsonManager; import ru.gravit.launcher.managers.ConsoleManager; import ru.gravit.launcher.request.Request; +import ru.gravit.launcher.request.auth.RestoreSessionRequest; import ru.gravit.launcher.request.websockets.StandartClientWebSocketService; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.EnvHelper; @@ -71,11 +72,27 @@ public void start(String... args) throws Throwable { if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider(); runtimeProvider.init(false); runtimeProvider.preLoad(); - if(Request.service != null) + if(Request.service == null) { String address = Launcher.getConfig().address; LogHelper.debug("Start async connection to %s", address); Request.service = StandartClientWebSocketService.initWebSockets(address, true); + Request.service.reconnectCallback = () -> + { + LogHelper.debug("WebSocket connect closed. Try reconnect"); + try { + if (!Request.service.reconnectBlocking()) LogHelper.error("Error connecting"); + LogHelper.debug("Connect to %s", Launcher.getConfig().address); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + RestoreSessionRequest request1 = new RestoreSessionRequest(Request.getSession()); + request1.request(); + } catch (Exception e) { + LogHelper.error(e); + } + }; } LauncherGuardManager.initGuard(false); Objects.requireNonNull(args, "args"); From 9480e94778d2dbaf1e51f16ad76fa70d008226a5 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 29 Apr 2019 10:19:47 +0700 Subject: [PATCH 02/10] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20Netty=20=D0=B2?= =?UTF-8?q?=20=D0=BA=D0=B0=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B5=20=D0=B1?= =?UTF-8?q?=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8=20=D0=B2?= =?UTF-8?q?=D0=B5=D0=B1=D1=81=D0=BE=D0=BA=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/build.gradle | 3 +- .../ru/gravit/launcher/LauncherEngine.java | 4 +- .../launcher/client/ClientLauncher.java | 4 +- LauncherAPI/build.gradle | 2 +- .../request/websockets/ClientJSONPoint.java | 98 +++++++++++++++---- .../websockets/ClientWebSocketService.java | 49 +++------- .../StandartClientWebSocketService.java | 15 ++- .../websockets/WebSocketClientHandler.java | 97 ++++++++++++++++++ .../gravit/launcher/server/ServerWrapper.java | 4 +- 9 files changed, 212 insertions(+), 64 deletions(-) create mode 100644 LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java diff --git a/Launcher/build.gradle b/Launcher/build.gradle index f01e92e7..cb817a76 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -30,6 +30,7 @@ shadowJar { classifier = null relocate 'org.objectweb.asm', 'ru.gravit.repackage.org.objectweb.asm' + relocate 'io.netty', 'ru.gravit.repackage.io.netty' configurations = [project.configurations.pack] exclude 'module-info.class' } @@ -39,7 +40,7 @@ pack project(':LauncherAPI') // Not error on obf. bundle 'com.github.oshi:oshi-core:3.13.0' bundle 'com.jfoenix:jfoenix:8.0.8' bundle 'de.jensd:fontawesomefx:8.9' - bundle 'org.fusesource.jansi:jansi:1.17.1' + pack 'io.netty:netty-all:4.1.32.Final' pack 'org.ow2.asm:asm-tree:7.1' } diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index f0b096ce..d976e31a 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -81,9 +81,9 @@ public void start(String... args) throws Throwable { { LogHelper.debug("WebSocket connect closed. Try reconnect"); try { - if (!Request.service.reconnectBlocking()) LogHelper.error("Error connecting"); + Request.service.open(); LogHelper.debug("Connect to %s", Launcher.getConfig().address); - } catch (InterruptedException e) { + } catch (Exception e) { e.printStackTrace(); } try { diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index 3d8d118a..a762b11c 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -459,9 +459,9 @@ public static void main(String... args) throws Throwable { { LogHelper.debug("WebSocket connect closed. Try reconnect"); try { - if (!Request.service.reconnectBlocking()) LogHelper.error("Error connecting"); + Request.service.open(); LogHelper.debug("Connect to %s", Launcher.getConfig().address); - } catch (InterruptedException e) { + } catch (Exception e) { e.printStackTrace(); } try { diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index 0f04a4d3..ad4e07c0 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -3,7 +3,7 @@ dependencies { compile project(':libLauncher') - compile 'org.java-websocket:Java-WebSocket:1.3.9' + compileOnly 'io.netty:netty-all:4.1.32.Final' compile 'org.apache.httpcomponents:httpclient:4.5.7' 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/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java index a09f1241..40735fab 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -1,36 +1,100 @@ package ru.gravit.launcher.request.websockets; -import org.java_websocket.client.WebSocketClient; -import org.java_websocket.drafts.Draft_6455; -import org.java_websocket.handshake.ServerHandshake; +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.*; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.codec.http.HttpClientCodec; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory; +import io.netty.handler.codec.http.websocketx.WebSocketVersion; +import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; import java.net.URI; import java.util.Map; -public class ClientJSONPoint extends WebSocketClient { +public class ClientJSONPoint { - public ClientJSONPoint(URI serverUri, Map httpHeaders, int connectTimeout) { - super(serverUri, new Draft_6455(), httpHeaders, connectTimeout); + private final URI uri; + private Channel ch; + private static final EventLoopGroup group = new NioEventLoopGroup(); + protected WebSocketClientHandler webSocketClientHandler; + + public ClientJSONPoint(final String uri) { + this.uri = URI.create(uri); } - @Override - public void onOpen(ServerHandshake handshakedata) { - + public ClientJSONPoint(URI uri) { + this.uri = uri; } - @Override - public void onMessage(String message) { + public void open() throws Exception { + Bootstrap b = new Bootstrap(); + String protocol = uri.getScheme(); + if (!"ws".equals(protocol) && !"wss".equals(protocol)) { + throw new IllegalArgumentException("Unsupported protocol: " + protocol); + } + boolean ssl = false; + if("wss".equals(protocol)) + { + ssl = true; + } + final SslContext sslCtx; + if (ssl) { + sslCtx = SslContextBuilder.forClient().build(); + } else { + sslCtx = null; + } + + // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00. + // If you change it to V00, ping is not supported and remember to change + // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline. + webSocketClientHandler = + new WebSocketClientHandler( + WebSocketClientHandshakerFactory.newHandshaker( + uri, WebSocketVersion.V13, null, false, HttpHeaders.EMPTY_HEADERS, 1280000)); + + b.group(group) + .channel(NioSocketChannel.class) + .handler(new ChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline pipeline = ch.pipeline(); + if (sslCtx != null) { + pipeline.addLast(sslCtx.newHandler(ch.alloc())); + } + pipeline.addLast("http-codec", new HttpClientCodec()); + pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); + pipeline.addLast("ws-handler", webSocketClientHandler); + } + }); + + //System.out.println("WebSocket Client connecting"); + ch = b.connect(uri.getHost(), uri.getPort()).sync().channel(); + webSocketClientHandler.handshakeFuture().sync(); + } + public ChannelFuture send(String text) + { + LogHelper.dev("Send: %s", text); + return ch.writeAndFlush(new TextWebSocketFrame(text)); } - @Override - public void onClose(int code, String reason, boolean remote) { - LogHelper.debug("Disconnected: " + code + " " + remote + " " + reason != null ? reason : "no reason"); + public void close() throws InterruptedException { + //System.out.println("WebSocket Client sending close"); + ch.writeAndFlush(new CloseWebSocketFrame()); + ch.closeFuture().sync(); + //group.shutdownGracefully(); } - @Override - public void onError(Exception ex) { - LogHelper.error(ex); + public void eval(final String text) throws IOException { + ch.writeAndFlush(new TextWebSocketFrame(text)); } } \ No newline at end of file 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 395aaf4a..5e995190 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 @@ -2,7 +2,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import org.java_websocket.handshake.ServerHandshake; import ru.gravit.launcher.events.ExceptionEvent; import ru.gravit.launcher.events.request.*; import ru.gravit.launcher.hasher.HashedEntry; @@ -13,7 +12,6 @@ import java.io.IOException; import java.lang.reflect.Type; import java.net.URI; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -28,7 +26,7 @@ public class ClientWebSocketService extends ClientJSONPoint { private HashSet handlers; public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) { - super(createURL(address), Collections.emptyMap(), i); + super(createURL(address)); requests = new HashMap<>(); results = new HashMap<>(); handlers = new HashSet<>(); @@ -51,33 +49,16 @@ private static URI createURL(String address) { } @Override - public void onMessage(String message) { - ResultInterface result = gson.fromJson(message, ResultInterface.class); - for (EventHandler handler : handlers) { - handler.process(result); - } + public void open() throws Exception { + super.open(); + webSocketClientHandler.onMessageCallback = (message) -> { + ResultInterface result = gson.fromJson(message, ResultInterface.class); + for (EventHandler handler : handlers) { + handler.process(result); + } + }; } - @Override - public void onError(Exception e) { - LogHelper.error(e); - } - @Override - public void onOpen(ServerHandshake handshakedata) { - //Notify open - synchronized (onConnect) - { - onConnect.notifyAll(); - } - } - - @Override - public void onClose(int code, String reason, boolean remote) - { - LogHelper.debug("Disconnected: " + code + " " + remote + " " + (reason != null ? reason : "no reason")); - if(onCloseCallback != null) - onCloseCallback.onClose(code, reason, remote); - } @FunctionalInterface public interface OnCloseCallback { @@ -136,7 +117,7 @@ public void registerHandler(EventHandler eventHandler) { } public void waitIfNotConnected() { - if(!isOpen() && !isClosed() && !isClosing()) + /*if(!isOpen() && !isClosed() && !isClosing()) { LogHelper.warning("WebSocket not connected. Try wait onConnect object"); synchronized (onConnect) @@ -147,20 +128,20 @@ public void waitIfNotConnected() LogHelper.error(e); } } - } + }*/ } public void sendObject(Object obj) throws IOException { waitIfNotConnected(); - if(isClosed() && reconnectCallback != null) - reconnectCallback.onReconnect(); + //if(isClosed() && reconnectCallback != null) + // reconnectCallback.onReconnect(); send(gson.toJson(obj, RequestInterface.class)); } public void sendObject(Object obj, Type type) throws IOException { waitIfNotConnected(); - if(isClosed() && reconnectCallback != null) - reconnectCallback.onReconnect(); + //if(isClosed() && reconnectCallback != null) + // reconnectCallback.onReconnect(); send(gson.toJson(obj, type)); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java index 68b2ff3c..234bd257 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java @@ -108,20 +108,25 @@ public static StandartClientWebSocketService initWebSockets(String address, bool if(!async) { try { - if (!service.connectBlocking()) LogHelper.error("Error connecting"); + service.open(); LogHelper.debug("Connect to %s", address); - } catch (InterruptedException e) { + } catch (Exception e) { e.printStackTrace(); } } else { - service.connect(); + try { + service.open(); + } catch (Exception e) { + e.printStackTrace(); + } } JVMHelper.RUNTIME.addShutdownHook(new Thread(() -> { try { - if(service.isOpen()) - service.closeBlocking(); + //if(service.isOpen()) + // service.closeBlocking(); + service.close(); } catch (InterruptedException e) { LogHelper.error(e); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java new file mode 100644 index 00000000..2fc12055 --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java @@ -0,0 +1,97 @@ +package ru.gravit.launcher.request.websockets; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPromise; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; +import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; +import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker; +import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import io.netty.util.CharsetUtil; +import ru.gravit.utils.helper.LogHelper; + +/** + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public class WebSocketClientHandler extends SimpleChannelInboundHandler { + + private final WebSocketClientHandshaker handshaker; + private ChannelPromise handshakeFuture; + interface OnMessageCallback + { + void onMessage(String text); + } + public OnMessageCallback onMessageCallback; + + public WebSocketClientHandler(final WebSocketClientHandshaker handshaker) { + this.handshaker = handshaker; + } + + public ChannelFuture handshakeFuture() { + return handshakeFuture; + } + + @Override + public void handlerAdded(final ChannelHandlerContext ctx) throws Exception { + handshakeFuture = ctx.newPromise(); + } + + @Override + public void channelActive(final ChannelHandlerContext ctx) throws Exception { + handshaker.handshake(ctx.channel()); + } + + @Override + public void channelInactive(final ChannelHandlerContext ctx) throws Exception { + //System.out.println("WebSocket Client disconnected!"); + } + + @Override + protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { + final Channel ch = ctx.channel(); + if (!handshaker.isHandshakeComplete()) { + // web socket client connected + handshaker.finishHandshake(ch, (FullHttpResponse) msg); + handshakeFuture.setSuccess(); + return; + } + + if (msg instanceof FullHttpResponse) { + final FullHttpResponse response = (FullHttpResponse) msg; + throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + + response.content().toString(CharsetUtil.UTF_8) + ')'); + } + + final WebSocketFrame frame = (WebSocketFrame) msg; + if (frame instanceof TextWebSocketFrame) { + final TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; + if(onMessageCallback != null) onMessageCallback.onMessage(textFrame.text()); + LogHelper.dev("Message: %s", textFrame.text()); + // uncomment to print request + // logger.info(textFrame.text()); + } else if (frame instanceof PongWebSocketFrame) { + } else if (frame instanceof CloseWebSocketFrame) + ch.close(); + else if (frame instanceof BinaryWebSocketFrame) { + // uncomment to print request + // logger.info(frame.content().toString()); + } + + } + + @Override + public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { + cause.printStackTrace(); + + if (!handshakeFuture.isDone()) { + handshakeFuture.setFailure(cause); + } + + ctx.close(); + } +} \ No newline at end of file diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 56b946ce..98d554f1 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -162,9 +162,9 @@ public void run(String... args) throws Throwable { { LogHelper.debug("WebSocket connect closed. Try reconnect"); try { - if (!Request.service.reconnectBlocking()) LogHelper.error("Error connecting"); + Request.service.open(); LogHelper.debug("Connect to %s", config.websocket.address); - } catch (InterruptedException e) { + } catch (Exception e) { e.printStackTrace(); } auth(); From 1cc08204e5cbc7d14867ab078ce132a4c0616e71 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 29 Apr 2019 11:00:37 +0700 Subject: [PATCH 03/10] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20=D0=98=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=20Netty=20=D0=BD=D0=B0=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B8=D0=B5=D0=BD=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/websockets/ClientJSONPoint.java | 50 +++++++++---------- .../websockets/ClientWebSocketService.java | 24 +++++---- .../StandartClientWebSocketService.java | 11 +++- .../websockets/WebSocketClientHandler.java | 7 ++- 4 files changed, 54 insertions(+), 38 deletions(-) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java index 40735fab..91f1b554 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -5,8 +5,8 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.codec.http.EmptyHttpHeaders; import io.netty.handler.codec.http.HttpClientCodec; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; @@ -16,27 +16,33 @@ import io.netty.handler.ssl.SslContextBuilder; import ru.gravit.utils.helper.LogHelper; +import javax.net.ssl.SSLException; import java.io.IOException; import java.net.URI; -import java.util.Map; -public class ClientJSONPoint { +public abstract class ClientJSONPoint { private final URI uri; - private Channel ch; + protected Channel ch; private static final EventLoopGroup group = new NioEventLoopGroup(); protected WebSocketClientHandler webSocketClientHandler; + protected Bootstrap bootstrap = new Bootstrap(); + public boolean isClosed; - public ClientJSONPoint(final String uri) { - this.uri = URI.create(uri); + public ClientJSONPoint(final String uri) throws SSLException { + this(URI.create(uri)); } - public ClientJSONPoint(URI uri) { + public ClientJSONPoint(URI uri) throws SSLException { this.uri = uri; - } + // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00. + // If you change it to V00, ping is not supported and remember to change + // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline. + webSocketClientHandler = + new WebSocketClientHandler( + WebSocketClientHandshakerFactory.newHandshaker( + uri, WebSocketVersion.V13, null, false, EmptyHttpHeaders.INSTANCE, 1280000), this); - public void open() throws Exception { - Bootstrap b = new Bootstrap(); String protocol = uri.getScheme(); if (!"ws".equals(protocol) && !"wss".equals(protocol)) { throw new IllegalArgumentException("Unsupported protocol: " + protocol); @@ -49,19 +55,8 @@ public void open() throws Exception { final SslContext sslCtx; if (ssl) { sslCtx = SslContextBuilder.forClient().build(); - } else { - sslCtx = null; - } - - // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00. - // If you change it to V00, ping is not supported and remember to change - // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline. - webSocketClientHandler = - new WebSocketClientHandler( - WebSocketClientHandshakerFactory.newHandshaker( - uri, WebSocketVersion.V13, null, false, HttpHeaders.EMPTY_HEADERS, 1280000)); - - b.group(group) + } else sslCtx = null; + bootstrap.group(group) .channel(NioSocketChannel.class) .handler(new ChannelInitializer() { @Override @@ -74,10 +69,12 @@ public void initChannel(SocketChannel ch) throws Exception { pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); pipeline.addLast("ws-handler", webSocketClientHandler); } - }); + }); + } + public void open() throws Exception { //System.out.println("WebSocket Client connecting"); - ch = b.connect(uri.getHost(), uri.getPort()).sync().channel(); + ch = bootstrap.connect(uri.getHost(), uri.getPort()).sync().channel(); webSocketClientHandler.handshakeFuture().sync(); } public ChannelFuture send(String text) @@ -85,9 +82,12 @@ public ChannelFuture send(String text) LogHelper.dev("Send: %s", text); return ch.writeAndFlush(new TextWebSocketFrame(text)); } + abstract void onMessage(String message) throws Exception; + abstract void onDisconnect() throws Exception; public void close() throws InterruptedException { //System.out.println("WebSocket Client sending close"); + isClosed = true; ch.writeAndFlush(new CloseWebSocketFrame()); ch.closeFuture().sync(); //group.shutdownGracefully(); 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 5e995190..2a39a54f 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 @@ -9,6 +9,7 @@ import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.helper.LogHelper; +import javax.net.ssl.SSLException; import java.io.IOException; import java.lang.reflect.Type; import java.net.URI; @@ -25,7 +26,7 @@ public class ClientWebSocketService extends ClientJSONPoint { private HashMap> results; private HashSet handlers; - public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) { + public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) throws SSLException { super(createURL(address)); requests = new HashMap<>(); results = new HashMap<>(); @@ -49,14 +50,17 @@ private static URI createURL(String address) { } @Override - public void open() throws Exception { - super.open(); - webSocketClientHandler.onMessageCallback = (message) -> { - ResultInterface result = gson.fromJson(message, ResultInterface.class); - for (EventHandler handler : handlers) { - handler.process(result); - } - }; + void onMessage(String message) { + ResultInterface result = gson.fromJson(message, ResultInterface.class); + for (EventHandler handler : handlers) { + handler.process(result); + } + } + + @Override + void onDisconnect() { + LogHelper.info("WebSocket client disconnect"); + if(onCloseCallback != null) onCloseCallback.onClose(0,"unsupported param", !isClosed); } @FunctionalInterface @@ -133,6 +137,7 @@ public void waitIfNotConnected() public void sendObject(Object obj) throws IOException { waitIfNotConnected(); + if(ch == null || !ch.isActive()) reconnectCallback.onReconnect(); //if(isClosed() && reconnectCallback != null) // reconnectCallback.onReconnect(); send(gson.toJson(obj, RequestInterface.class)); @@ -140,6 +145,7 @@ public void sendObject(Object obj) throws IOException { public void sendObject(Object obj, Type type) throws IOException { waitIfNotConnected(); + if(ch == null || !ch.isActive()) reconnectCallback.onReconnect(); //if(isClosed() && reconnectCallback != null) // reconnectCallback.onReconnect(); send(gson.toJson(obj, type)); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java index 234bd257..54ac6940 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java @@ -8,6 +8,7 @@ import ru.gravit.utils.helper.JVMHelper; import ru.gravit.utils.helper.LogHelper; +import javax.net.ssl.SSLException; import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -15,7 +16,7 @@ public class StandartClientWebSocketService extends ClientWebSocketService { public WaitEventHandler waitEventHandler = new WaitEventHandler(); - public StandartClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) { + public StandartClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) throws SSLException { super(gsonBuilder, address, i); } public class RequestFuture implements Future @@ -101,7 +102,13 @@ public RequestFuture asyncSendRequest(RequestInterface request) throws IOExcepti } public static StandartClientWebSocketService initWebSockets(String address, boolean async) { - StandartClientWebSocketService service = new StandartClientWebSocketService(new GsonBuilder(), address, 5000); + StandartClientWebSocketService service; + try { + service = new StandartClientWebSocketService(new GsonBuilder(), address, 5000); + } catch (SSLException e) { + LogHelper.error(e); + return null; + } service.registerResults(); service.registerRequests(); service.registerHandler(service.waitEventHandler); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java index 2fc12055..41d98c39 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java @@ -21,6 +21,7 @@ public class WebSocketClientHandler extends SimpleChannelInboundHandler { private final WebSocketClientHandshaker handshaker; + private final ClientJSONPoint clientJSONPoint; private ChannelPromise handshakeFuture; interface OnMessageCallback { @@ -28,8 +29,9 @@ interface OnMessageCallback } public OnMessageCallback onMessageCallback; - public WebSocketClientHandler(final WebSocketClientHandshaker handshaker) { + public WebSocketClientHandler(final WebSocketClientHandshaker handshaker, ClientJSONPoint clientJSONPoint) { this.handshaker = handshaker; + this.clientJSONPoint = clientJSONPoint; } public ChannelFuture handshakeFuture() { @@ -49,6 +51,7 @@ public void channelActive(final ChannelHandlerContext ctx) throws Exception { @Override public void channelInactive(final ChannelHandlerContext ctx) throws Exception { //System.out.println("WebSocket Client disconnected!"); + clientJSONPoint.onDisconnect(); } @Override @@ -70,7 +73,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except final WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { final TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; - if(onMessageCallback != null) onMessageCallback.onMessage(textFrame.text()); + clientJSONPoint.onMessage(textFrame.text()); LogHelper.dev("Message: %s", textFrame.text()); // uncomment to print request // logger.info(textFrame.text()); From 323cfe763adc7725ca62755811a472ae1eb233c4 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 29 Apr 2019 13:38:35 +0700 Subject: [PATCH 04/10] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20onOpen=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/request/websockets/ClientJSONPoint.java | 1 + .../request/websockets/ClientWebSocketService.java | 8 ++++++++ .../request/websockets/WebSocketClientHandler.java | 10 +++------- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java index 91f1b554..be03e5f4 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -84,6 +84,7 @@ public ChannelFuture send(String text) } abstract void onMessage(String message) throws Exception; abstract void onDisconnect() throws Exception; + abstract void onOpen() throws Exception; public void close() throws InterruptedException { //System.out.println("WebSocket Client sending close"); 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 2a39a54f..b47ccf66 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 @@ -63,6 +63,14 @@ void onDisconnect() { if(onCloseCallback != null) onCloseCallback.onClose(0,"unsupported param", !isClosed); } + @Override + void onOpen() throws Exception { + synchronized (onConnect) + { + onConnect.notifyAll(); + } + } + @FunctionalInterface public interface OnCloseCallback { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java index 41d98c39..da494a72 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java @@ -23,11 +23,6 @@ public class WebSocketClientHandler extends SimpleChannelInboundHandler private final WebSocketClientHandshaker handshaker; private final ClientJSONPoint clientJSONPoint; private ChannelPromise handshakeFuture; - interface OnMessageCallback - { - void onMessage(String text); - } - public OnMessageCallback onMessageCallback; public WebSocketClientHandler(final WebSocketClientHandshaker handshaker, ClientJSONPoint clientJSONPoint) { this.handshaker = handshaker; @@ -46,6 +41,7 @@ public void handlerAdded(final ChannelHandlerContext ctx) throws Exception { @Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { handshaker.handshake(ctx.channel()); + clientJSONPoint.onOpen(); } @Override @@ -66,7 +62,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except if (msg instanceof FullHttpResponse) { final FullHttpResponse response = (FullHttpResponse) msg; - throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } @@ -89,7 +85,7 @@ else if (frame instanceof BinaryWebSocketFrame) { @Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { - cause.printStackTrace(); + LogHelper.error(cause); if (!handshakeFuture.isDone()) { handshakeFuture.setFailure(cause); From a921fde598c0f9af50c4ebf8dd73404207e5e6c5 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Mon, 29 Apr 2019 09:56:39 +0300 Subject: [PATCH 05/10] =?UTF-8?q?[FIX]=20=D0=97=D0=B0=D0=BF=D0=B0=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20netty=20=D0=B2=20ServerWrapper.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/defaults/proguard.cfg | 4 ++-- Launcher/build.gradle | 3 ++- LauncherAPI/build.gradle | 2 +- ServerWrapper/build.gradle | 22 ++++++++++++++++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg index 4c93356a..b2e34d42 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg @@ -20,9 +20,9 @@ -keepattributes Signature -adaptresourcefilecontents META-INF/MANIFEST.MF --keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,oshi.**,com.sun.jna.**,com.google.gson.**,org.slf4j.**,oshi.jna.**,com.sun.jna.**,org.apache.commons.logging.**, org.fusesource.**, com.jfoenix.** +-keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,ru.gravit.repackage.**,org.fusesource.** --keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,oshi.**,com.sun.jna.**,com.google.gson.**,org.slf4j.**,oshi.jna.**,com.sun.jna.**,org.apache.commons.logging.**, org.fusesource.**, com.jfoenix.** { +-keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,ru.gravit.repackage.**,org.fusesource.** { *; } diff --git a/Launcher/build.gradle b/Launcher/build.gradle index cb817a76..904fba57 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -36,10 +36,11 @@ } dependencies { - pack project(':LauncherAPI') // Not error on obf. + pack project(':LauncherAPI') bundle 'com.github.oshi:oshi-core:3.13.0' bundle 'com.jfoenix:jfoenix:8.0.8' bundle 'de.jensd:fontawesomefx:8.9' + bundle 'org.apache.httpcomponents:httpclient:4.5.7' pack 'io.netty:netty-all:4.1.32.Final' pack 'org.ow2.asm:asm-tree:7.1' } diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index ad4e07c0..6c28c79d 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -4,7 +4,7 @@ dependencies { compile project(':libLauncher') compileOnly 'io.netty:netty-all:4.1.32.Final' - compile 'org.apache.httpcomponents:httpclient:4.5.7' + compileOnly 'org.apache.httpcomponents:httpclient:4.5.7' compileOnly 'com.google.guava:guava:26.0-jre' compile files('../compat/authlib/authlib-clean.jar') } diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index 4ec8ef0a..241d2b17 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -1,6 +1,12 @@ +apply plugin: 'com.github.johnrengelman.shadow' + String mainClassName = "ru.gravit.launcher.server.ServerWrapper" String mainAgentName = "ru.gravit.launcher.server.ServerAgent" +configurations { + pack + compile.extendsFrom pack +} repositories { maven { @@ -12,6 +18,7 @@ targetCompatibility = '1.8' jar { + classifier = 'clean' from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } manifest.attributes("Main-Class": mainClassName, "Premain-Class": mainAgentName, @@ -21,5 +28,18 @@ } dependencies { - compile project(':LauncherAPI') + pack project(':LauncherAPI') + pack 'org.apache.httpcomponents:httpclient:4.5.7' + pack 'io.netty:netty-all:4.1.32.Final' } + +shadowJar { + classifier = null + relocate 'io.netty', 'ru.gravit.repackage.io.netty' + configurations = [project.configurations.pack] + exclude 'module-info.class' + } + + + build.dependsOn tasks.shadowJar + \ No newline at end of file From edc5f1f7b2da52575b7581413f1645891fa08353 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 29 Apr 2019 15:35:51 +0700 Subject: [PATCH 06/10] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B3=D0=BE=D0=BD=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=82=D0=BE=D0=BA=D0=BE=D0=B2,=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20reconnect=20loop,?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=84=D0=B8=D0=BA=D1=88=D0=B5=D0=BD=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launcher/LauncherEngine.java | 4 +++- .../launcher/client/ClientLauncher.java | 4 +++- .../request/websockets/ClientJSONPoint.java | 20 +++++++++---------- .../websockets/WebSocketClientHandler.java | 4 ---- .../gravit/launcher/server/ServerWrapper.java | 4 +++- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index d976e31a..0d0a657a 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -9,6 +9,7 @@ import ru.gravit.launcher.managers.ClientGsonManager; import ru.gravit.launcher.managers.ConsoleManager; import ru.gravit.launcher.request.Request; +import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.request.auth.RestoreSessionRequest; import ru.gravit.launcher.request.websockets.StandartClientWebSocketService; import ru.gravit.utils.helper.CommonHelper; @@ -84,7 +85,8 @@ public void start(String... args) throws Throwable { Request.service.open(); LogHelper.debug("Connect to %s", Launcher.getConfig().address); } catch (Exception e) { - e.printStackTrace(); + LogHelper.error(e); + throw new RequestException(String.format("Connect error: %s", e.getMessage() != null ? e.getMessage() : "null")); } try { RestoreSessionRequest request1 = new RestoreSessionRequest(Request.getSession()); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index a762b11c..e3dc7e66 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -9,6 +9,7 @@ import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.request.Request; +import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.request.auth.RestoreSessionRequest; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -462,7 +463,8 @@ public static void main(String... args) throws Throwable { Request.service.open(); LogHelper.debug("Connect to %s", Launcher.getConfig().address); } catch (Exception e) { - e.printStackTrace(); + LogHelper.error(e); + throw new RequestException(String.format("Connect error: %s", e.getMessage() != null ? e.getMessage() : "null")); } try { RestoreSessionRequest request1 = new RestoreSessionRequest(Request.getSession()); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java index be03e5f4..22e0c07d 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -35,14 +35,6 @@ public ClientJSONPoint(final String uri) throws SSLException { public ClientJSONPoint(URI uri) throws SSLException { this.uri = uri; - // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00. - // If you change it to V00, ping is not supported and remember to change - // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline. - webSocketClientHandler = - new WebSocketClientHandler( - WebSocketClientHandshakerFactory.newHandshaker( - uri, WebSocketVersion.V13, null, false, EmptyHttpHeaders.INSTANCE, 1280000), this); - String protocol = uri.getScheme(); if (!"ws".equals(protocol) && !"wss".equals(protocol)) { throw new IllegalArgumentException("Unsupported protocol: " + protocol); @@ -74,6 +66,10 @@ public void initChannel(SocketChannel ch) throws Exception { public void open() throws Exception { //System.out.println("WebSocket Client connecting"); + webSocketClientHandler = + new WebSocketClientHandler( + WebSocketClientHandshakerFactory.newHandshaker( + uri, WebSocketVersion.V13, null, false, EmptyHttpHeaders.INSTANCE, 1280000), this); ch = bootstrap.connect(uri.getHost(), uri.getPort()).sync().channel(); webSocketClientHandler.handshakeFuture().sync(); } @@ -89,8 +85,12 @@ public ChannelFuture send(String text) public void close() throws InterruptedException { //System.out.println("WebSocket Client sending close"); isClosed = true; - ch.writeAndFlush(new CloseWebSocketFrame()); - ch.closeFuture().sync(); + if(ch != null && ch.isActive()) + { + ch.writeAndFlush(new CloseWebSocketFrame()); + ch.closeFuture().sync(); + } + //group.shutdownGracefully(); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java index da494a72..7d185225 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WebSocketClientHandler.java @@ -14,10 +14,6 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.util.CharsetUtil; import ru.gravit.utils.helper.LogHelper; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ public class WebSocketClientHandler extends SimpleChannelInboundHandler { private final WebSocketClientHandshaker handshaker; diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 98d554f1..15710be1 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -6,6 +6,7 @@ import ru.gravit.launcher.events.request.ProfilesRequestEvent; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.request.Request; +import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.request.auth.AuthRequest; import ru.gravit.launcher.request.update.ProfilesRequest; import ru.gravit.launcher.server.setup.ServerWrapperSetup; @@ -165,7 +166,8 @@ public void run(String... args) throws Throwable { Request.service.open(); LogHelper.debug("Connect to %s", config.websocket.address); } catch (Exception e) { - e.printStackTrace(); + LogHelper.error(e); + throw new RequestException(String.format("Connect error: %s", e.getMessage() != null ? e.getMessage() : "null")); } auth(); }; From 72ce4234a3f5009ab4ed16802483961263d85425 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 29 Apr 2019 15:56:19 +0700 Subject: [PATCH 07/10] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20NPE=20=D0=B2=20AuthResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/websocket/json/auth/AuthResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/json/auth/AuthResponse.java index 1ff9a85f..8059d02e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/json/auth/AuthResponse.java @@ -60,7 +60,7 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti try { AuthRequestEvent result = new AuthRequestEvent(); String ip = IOHelper.getIP(ctx.channel().remoteAddress()); - if ((authType == null || authType == ConnectTypes.CLIENT) && !clientData.checkSign) { + if ((authType == null || authType == ConnectTypes.CLIENT) && ( clientData == null || !clientData.checkSign )) { AuthProvider.authError("Don't skip Launcher Update"); return; } From 02c8ee49995aa98a9b1b2b22ffe8c952e16cd484 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 29 Apr 2019 15:59:30 +0700 Subject: [PATCH 08/10] =?UTF-8?q?[FIX]=20=D0=92=D0=BE=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B1=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=20=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20Netty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ru/gravit/launchserver/LaunchServer.java | 2 ++ .../ru/gravit/launchserver/websocket/LauncherNettyServer.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index f0309cc5..08bb893f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -1,5 +1,6 @@ package ru.gravit.launchserver; +import io.netty.handler.logging.LogLevel; import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.NeedGarbageCollection; @@ -280,6 +281,7 @@ public class NettyConfig { public Map bindings = new HashMap<>(); public NettyPerformanceConfig performance; public NettyBindAddress[] binds; + public LogLevel logLevel = LogLevel.DEBUG; } public class NettyPerformanceConfig { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/LauncherNettyServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/LauncherNettyServer.java index 0df2a864..0259bdc9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/LauncherNettyServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/LauncherNettyServer.java @@ -32,7 +32,7 @@ public LauncherNettyServer() { serverBootstrap = new ServerBootstrap(); serverBootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) - .handler(new LoggingHandler(LogLevel.DEBUG)) + .handler(new LoggingHandler(config.logLevel)) .childHandler(new ChannelInitializer() { @Override public void initChannel(NioSocketChannel ch) { From f820271418573ff1ba7e26aab8447ce94517de4d Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 29 Apr 2019 16:08:43 +0700 Subject: [PATCH 09/10] =?UTF-8?q?[FIX]=20Radon=20=D0=B2=D1=8B=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=D0=B5=D0=BD=20=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE?= =?UTF-8?q?=D0=BB=D1=87=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ru/gravit/launchserver/LaunchServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 08bb893f..94f4db54 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -721,7 +721,7 @@ private void generateConfigIfNotExists(boolean testEnv) throws IOException { newConfig.threadCoreCount = 0; // on your own newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors(); - newConfig.enabledRadon = true; + newConfig.enabledRadon = false; newConfig.enabledProGuard = true; newConfig.stripLineNumbers = true; newConfig.deleteTempFiles = true; From adb8091ff3fa248e666529972e7f6bc85759b6ab Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 29 Apr 2019 16:16:33 +0700 Subject: [PATCH 10/10] [ANY] 5.0.0b3 beta --- libLauncher/src/main/java/ru/gravit/launcher/Launcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index 81ad3e3d..d11cfafa 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -60,7 +60,7 @@ public final class Launcher { public static final int MAJOR = 5; public static final int MINOR = 0; public static final int PATCH = 0; - public static final int BUILD = 2; + public static final int BUILD = 3; public static final Version.Type RELEASE = Version.Type.BETA; public static GsonManager gsonManager;