Waterfall/BungeeCord-Patches/0045-Add-Configuration-to-allow-empty-packets.patch

112 lines
5.0 KiB
Diff
Raw Normal View History

From 59cd643646283aa72acf873abea280d7c59ceeba Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Fri, 12 Oct 2018 14:28:52 +0100
Subject: [PATCH] Add Configuration to allow empty packets
This setting provides the ability to allow servers/clients
to send empty packets without kicking the player with an error.
This option is not encouraged or supported in any capacity, and is
provided as a last ditch effort for server owners to allow players
to connect in such a broken state as allowed by vanilla.
diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
index 058cca67..46adc983 100644
--- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
@@ -207,4 +207,11 @@ public interface ProxyConfig
* @return should we disable the tab completion limit for 1.13+ clients
*/
boolean isDisableModernTabLimiter();
+
+ /**
+ * Should we allow empty packets
+ *
+ * @return should we allow empty packets
+ */
+ boolean isAllowEmptyPackets();
}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
index e903fd09..98a54601 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
@@ -11,6 +11,13 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
{
private static boolean DIRECT_WARNING;
+ // Waterfall start
+ private boolean allowEmptyPackets;
+
+ public Varint21FrameDecoder(boolean allowEmptyPackets) {
+ this.allowEmptyPackets = allowEmptyPackets;
+ }
+ // Waterfall end
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
@@ -30,7 +37,7 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
if ( buf[i] >= 0 )
{
int length = DefinedPacket.readVarInt( Unpooled.wrappedBuffer( buf ) );
- if ( length == 0 )
+ if ( length == 0 && !allowEmptyPackets) // Waterfall
{
throw new CorruptedFrameException( "Empty Packet!" );
}
diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
index 4ff8da6d..f28f0111 100644
--- a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
@@ -42,6 +42,17 @@ public class WaterfallConfiguration extends Configuration {
private int tabThrottle = 1000;
private boolean disableModernTabLimiter = true;
+
+ /**
+ * This setting provides the ability to allow servers/clients
+ * to send empty packets without kicking the player with an error.
+ *
+ * This option is not encouraged or supported in any capacity, and is
+ * provided as a last ditch effort for server owners to allow players
+ * to connect in such a broken state as allowed by vanilla.
+ */
+ private boolean allowEmptyPackets = false;
+
@Override
public void load() {
super.load();
@@ -53,6 +64,7 @@ public class WaterfallConfiguration extends Configuration {
// Throttling options
tabThrottle = config.getInt("throttling.tab_complete", tabThrottle);
disableModernTabLimiter = config.getBoolean("disable_modern_tab_limiter", disableModernTabLimiter);
+ allowEmptyPackets = config.getBoolean("allow_empty_packets", allowEmptyPackets);
}
@Override
@@ -79,4 +91,9 @@ public class WaterfallConfiguration extends Configuration {
public boolean isDisableModernTabLimiter() {
return disableModernTabLimiter;
}
+
+ @Override
+ public boolean isAllowEmptyPackets() {
+ return allowEmptyPackets;
+ }
}
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
index 23241d68..051430ce 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
2018-12-27 00:40:37 +01:00
@@ -146,7 +146,7 @@ public class PipelineUtils
ch.config().setWriteBufferWaterMark( MARK );
ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
- ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );
+ ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder( BungeeCord.getInstance().getConfig().isAllowEmptyPackets()) ); // Waterfall
ch.pipeline().addLast( FRAME_PREPENDER, framePrepender );
ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
--
2.21.0