Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 419b52b

Browse files
fixed disconnection packet
1 parent 33d629b commit 419b52b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/main/java/com/andcool/OAuthServer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ public static void main(String[] args) throws Exception {
5858
public void initChannel(SocketChannel ch) {
5959
ch.pipeline()
6060
.addLast(new SessionHandler())
61-
.addLast("encryption", NoopHandler.INSTANCE)
62-
.addLast(new LengthFieldBasedFrameDecoder(8192, 0, 4, 0, 4))
63-
.addLast(new LengthFieldPrepender(4));
61+
.addLast("encryption", NoopHandler.INSTANCE);
6462
}
6563
});
6664

src/main/java/com/andcool/bytebuf/ByteBufUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@ public static void sendPacket(ChannelHandlerContext ctx, ByteBuf data) {
6363
data.release();
6464
}
6565
}
66+
67+
public static ByteBuf addSize(ChannelHandlerContext ctx, ByteBuf data) {
68+
ByteBuf packet = ctx.alloc().buffer();
69+
ByteBufUtils.writeVarInt(packet, data.readableBytes());
70+
packet.writeBytes(data);
71+
72+
return packet;
73+
}
6674
}

src/main/java/com/andcool/session/SessionHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public static void disconnect(ChannelHandlerContext ctx, String reason) throws I
8787
response.put("text", "");
8888
response.put("extra", OAuthServer.MOTD_FORMATTER.format(reason));
8989
ByteBufUtils.writeUTF8(out, response.toString());
90-
ctx.channel().writeAndFlush(out).addListener(ChannelFutureListener.CLOSE);
90+
ByteBuf packet = ByteBufUtils.addSize(ctx, out);
91+
ctx.channel().writeAndFlush(packet).addListener(ChannelFutureListener.CLOSE);
9192
}
9293
}

0 commit comments

Comments
 (0)