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(); };