From 92df57e49197794671512b88a9d94cda3cfef95a Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 26 Sep 2020 02:57:42 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=BB=D1=83=D1=87=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B8=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20web?= =?UTF-8?q?socket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handlers/WebSocketFrameHandler.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java index 5e374f42..a86cdeb9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java @@ -56,9 +56,29 @@ public void channelActive(ChannelHandlerContext ctx) { @Override protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) { // ping and pong frames already handled - if (hooks.hook(ctx, frame)) return; + try { + if (hooks.hook(ctx, frame)) return; + } catch (Throwable ex) + { + LogHelper.error(ex); + } if (frame instanceof TextWebSocketFrame) { - service.process(ctx, (TextWebSocketFrame) frame, client, context.ip); + try { + service.process(ctx, (TextWebSocketFrame) frame, client, context.ip); + } catch (Throwable ex) { + if(LogHelper.isDebugEnabled()) { + LogHelper.warning("Client %s send invalid request. Connection force closed.", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip); + if(LogHelper.isDevEnabled()) + { + LogHelper.dev("Client message: %s", ((TextWebSocketFrame) frame).text()); + } + if(LogHelper.isStacktraceEnabled()) + { + LogHelper.error(ex); + } + } + ctx.channel().close(); + } } else if ((frame instanceof PingWebSocketFrame)) { frame.content().retain(); ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content()));