diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java index 96c75328..0063d3cc 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java @@ -8,6 +8,7 @@ import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.DefaultChannelGroup; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.util.concurrent.GlobalEventExecutor; import ru.gravit.launchserver.LaunchServer; @@ -38,10 +39,13 @@ public void channelActive(ChannelHandlerContext ctx) { @Override protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception { // ping and pong frames already handled - ByteBuf buf = frame.content(); - ByteBufInputStream input = new ByteBufInputStream(buf); - Reader reader = new InputStreamReader(input, "UTF-8"); - JsonResponse response = gson.fromJson(reader,JsonResponse.class); - response.execute(ctx,frame); + if (frame instanceof TextWebSocketFrame) { + String request = ((TextWebSocketFrame) frame).text(); + JsonResponse response = gson.fromJson(request, JsonResponse.class); + response.execute(ctx, frame); + } else { + String message = "unsupported frame type: " + frame.getClass().getName(); + throw new UnsupportedOperationException(message); + } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/EchoResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/EchoResponse.java index 50197c0e..0febaf64 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/EchoResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/EchoResponse.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.socket.websocket.json; import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; import ru.gravit.launchserver.socket.websocket.WebSocketFrameHandler; import ru.gravit.utils.helper.LogHelper; @@ -20,7 +21,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, WebSocketFrame frame) { LogHelper.info("Echo: %s",echo); - ctx.channel().writeAndFlush(WebSocketFrameHandler.gson.toJson(new Result(echo))); + ctx.channel().writeAndFlush(new TextWebSocketFrame(WebSocketFrameHandler.gson.toJson(new Result(echo)))); } public class Result { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index 1a6e538c..3962d527 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; @@ -67,7 +68,7 @@ public void execute(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exce server.config.hwidHandler.check(hwid, result.username); } catch (AuthException | HWIDException e) { - ctx.channel().writeAndFlush(WebSocketFrameHandler.gson.toJson(new ErrorResult(e.getMessage()))); + ctx.channel().writeAndFlush(new TextWebSocketFrame(WebSocketFrameHandler.gson.toJson(new ErrorResult(e.getMessage())))); } } public class ErrorResult