mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
Фикс отправления ответов
This commit is contained in:
parent
7f952af1b9
commit
a1bb6d6e2f
3 changed files with 13 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue