From f49d36b719787eb8ef0c1ccb0433f4e150bfa677 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 12 Apr 2020 17:05:36 -0400 Subject: [PATCH] Close one last "proxy crasher" loophole --- .../proxy/connection/MinecraftConnection.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index 8d2e4c895..dc1151fe8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -152,7 +152,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { } } - ctx.pipeline().addBefore(MINECRAFT_DECODER, "discard", DiscardHandler.HANDLER); + installDiscardHandler(ctx); ctx.close(); } } @@ -168,6 +168,14 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { Preconditions.checkState(this.channel.eventLoop().inEventLoop(), "Not in event loop"); } + private void installDiscardHandler(ChannelHandlerContext ctx) { + ctx.pipeline().addBefore(MINECRAFT_DECODER, "discard", DiscardHandler.HANDLER); + } + + private void installDiscardHandler() { + channel.pipeline().addBefore(MINECRAFT_DECODER, "discard", DiscardHandler.HANDLER); + } + public EventLoop eventLoop() { return channel.eventLoop(); } @@ -208,6 +216,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { public void closeWith(Object msg) { if (channel.isActive()) { knownDisconnect = true; + installDiscardHandler(); channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); } } @@ -217,6 +226,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { */ public void close() { if (channel.isActive()) { + installDiscardHandler(); channel.close(); } }