mirror of
https://github.com/PaperMC/Waterfall.git
synced 2025-01-20 22:51:31 +01:00
2e1620e860
While we originally aimed to avoid this, using a system property allows us to avoid breaking this configuration setting should any plugin attempt to extend this class
64 lines
3.2 KiB
Diff
64 lines
3.2 KiB
Diff
From 3f3c2f958efa77486d3163fbf7b5b7f058d8f08c Mon Sep 17 00:00:00 2001
|
|
From: Shane Freeder <theboyetronic@gmail.com>
|
|
Date: Tue, 26 Feb 2019 20:15:54 +0000
|
|
Subject: [PATCH] Handle empty minecraft packets
|
|
|
|
Actually detect this and print a message instead of just
|
|
throwing exceptions down the line, also includes support
|
|
for the "allow empty packets" for completeness, but,
|
|
follows the same set of recommendations.
|
|
|
|
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
|
|
index 9e9ea49c..a46bbc78 100644
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
|
|
@@ -20,11 +20,18 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
|
private int protocolVersion;
|
|
@Setter
|
|
private boolean supportsForge = false;
|
|
+ private final boolean allowEmptyPackets; // Waterfall
|
|
|
|
public MinecraftDecoder(Protocol protocol, boolean server, int protocolVersion) {
|
|
+ // Waterfall start
|
|
+ this(protocol, server, protocolVersion, false);
|
|
+ }
|
|
+ public MinecraftDecoder(Protocol protocol, boolean server, int protocolVersion, boolean allowEmptyPackets) {
|
|
+ // Waterfall end
|
|
this.protocol = protocol;
|
|
this.server = server;
|
|
this.protocolVersion = protocolVersion;
|
|
+ this.allowEmptyPackets = allowEmptyPackets; // Waterfall
|
|
}
|
|
|
|
@Override
|
|
@@ -36,6 +43,13 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
|
Object packetTypeInfo = null;
|
|
try
|
|
{
|
|
+ // Waterfall start
|
|
+ if (in.readableBytes() == 0) {
|
|
+ if (!allowEmptyPackets) throw new BadPacketException("Empty minecraft packet!");
|
|
+ return;
|
|
+ }
|
|
+ // Waterfall end
|
|
+
|
|
int packetId = DefinedPacket.readVarInt( in );
|
|
packetTypeInfo = packetId;
|
|
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
index a12fec7f..ade817e9 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
@@ -343,7 +343,7 @@ public final class UserConnection implements ProxiedPlayer
|
|
protected void initChannel(Channel ch) throws Exception
|
|
{
|
|
PipelineUtils.BASE.initChannel( ch );
|
|
- ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) );
|
|
+ ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion(), bungee.getConfig().isAllowEmptyPackets() ) ); // Waterfall
|
|
ch.pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) );
|
|
ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) );
|
|
}
|
|
--
|
|
2.21.0
|
|
|