mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-10-29 22:59:54 +01:00
a218f5750f
Bungee works around mojang adding a metatype to the middle of the list of ids by decrementing the type ID, which results in the incorrect value being shown in server logs. Also, if we see this exception, we'll point people to the configuration option to disable this system.
64 lines
3.2 KiB
Diff
64 lines
3.2 KiB
Diff
From 7960a4c2a4959570f74e1c931b1d0332a4cd8259 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 8a524a64..e649678e 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
@@ -351,7 +351,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
|
|
|