mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-16 07:15:14 +01:00
ce48007a7d
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing BungeeCord Changes: 1ef4d27d #3543: Bump io.netty:netty-bom from 4.1.97.Final to 4.1.99.Final 94a1fb51 #3535: Queue packets of Title api 78aef86a #3533: Don't put initial client in configure phase until server is ready
115 lines
5.4 KiB
Diff
115 lines
5.4 KiB
Diff
From ff46baa5671121531007c00dc684dc035a16dd8c Mon Sep 17 00:00:00 2001
|
|
From: Techcable <Techcable@techcable.net>
|
|
Date: Thu, 19 May 2016 17:09:22 -0600
|
|
Subject: [PATCH] Allow invalid packet ids for forge servers
|
|
|
|
Some forge mods (COFH) use negative packet ids instead of plugin channels for 'reasons'.
|
|
Vanilla servers still error on negative/invalid packets.
|
|
|
|
Original issue: https://github.com/WaterfallMC/Waterfall-Old/issues/11
|
|
|
|
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 482341ef..76a3ddd0 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
|
|
@@ -18,6 +18,14 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
|
private final boolean server;
|
|
@Setter
|
|
private int protocolVersion;
|
|
+ @Setter
|
|
+ private boolean supportsForge = false;
|
|
+
|
|
+ public MinecraftDecoder(Protocol protocol, boolean server, int protocolVersion) {
|
|
+ this.protocol = protocol;
|
|
+ this.server = server;
|
|
+ this.protocolVersion = protocolVersion;
|
|
+ }
|
|
|
|
@Override
|
|
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
|
|
@@ -36,7 +44,7 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
|
{
|
|
int packetId = DefinedPacket.readVarInt( in );
|
|
|
|
- DefinedPacket packet = prot.createPacket( packetId, protocolVersion );
|
|
+ DefinedPacket packet = prot.createPacket( packetId, protocolVersion, supportsForge );
|
|
if ( packet != null )
|
|
{
|
|
packet.read( in, prot.getDirection(), protocolVersion );
|
|
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
|
index b6985fee..7f001b11 100644
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
|
@@ -749,14 +749,23 @@ public enum Protocol
|
|
return protocol;
|
|
}
|
|
|
|
+ public boolean hasPacket(int i, boolean supportsForge) {
|
|
+ return supportsForge || i >= 0 && i <= MAX_PACKET_ID;
|
|
+ }
|
|
+
|
|
public final DefinedPacket createPacket(int id, int version)
|
|
+ {
|
|
+ return createPacket(id, version, true);
|
|
+ }
|
|
+
|
|
+ public final DefinedPacket createPacket(int id, int version, boolean supportsForge)
|
|
{
|
|
ProtocolData protocolData = getProtocolData( version );
|
|
if ( protocolData == null )
|
|
{
|
|
throw new BadPacketException( "Unsupported protocol version " + version );
|
|
}
|
|
- if ( id > MAX_PACKET_ID || id < 0 )
|
|
+ if ( !hasPacket(id, supportsForge) )
|
|
{
|
|
throw new BadPacketException( "Packet with id " + id + " outside of range" );
|
|
}
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
|
|
index 3aacebe1..a5c8de90 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
|
|
@@ -34,7 +34,9 @@ import net.md_5.bungee.forge.ForgeUtils;
|
|
import net.md_5.bungee.netty.ChannelWrapper;
|
|
import net.md_5.bungee.netty.HandlerBoss;
|
|
import net.md_5.bungee.netty.PacketHandler;
|
|
+import net.md_5.bungee.netty.PipelineUtils;
|
|
import net.md_5.bungee.protocol.DefinedPacket;
|
|
+import net.md_5.bungee.protocol.MinecraftDecoder;
|
|
import net.md_5.bungee.protocol.PacketWrapper;
|
|
import net.md_5.bungee.protocol.Protocol;
|
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
|
@@ -222,6 +224,12 @@ public class ServerConnector extends PacketHandler
|
|
public static void handleLogin(ProxyServer bungee, ChannelWrapper ch, UserConnection user, BungeeServerInfo target, ForgeServerHandler handshakeHandler, ServerConnection server, Login login) throws Exception
|
|
{
|
|
ServerConnectedEvent event = new ServerConnectedEvent( user, server );
|
|
+
|
|
+ if (server.isForgeServer() && user.isForgeUser()) {
|
|
+ ((MinecraftDecoder) server.getCh().getHandle().pipeline().get(PipelineUtils.PACKET_DECODER)).setSupportsForge(true);
|
|
+ ((MinecraftDecoder) user.getCh().getHandle().pipeline().get(PipelineUtils.PACKET_DECODER)).setSupportsForge(true);
|
|
+ }
|
|
+
|
|
bungee.getPluginManager().callEvent( event );
|
|
|
|
ch.write( BungeeCord.getInstance().registerChannels( user.getPendingConnection().getVersion() ) );
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
|
|
index 30cc36a4..c033118f 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
|
|
@@ -338,6 +338,12 @@ public abstract class EntityMap
|
|
int packetId = DefinedPacket.readVarInt( packet );
|
|
int packetIdLength = packet.readerIndex() - readerIndex;
|
|
|
|
+ if (packetId < 0 || packetId > ints.length || packetId > varints.length) { // Invalid packet id
|
|
+ // Ignore these invalid packets for compatibility reasons
|
|
+ packet.readerIndex( readerIndex );
|
|
+ return;
|
|
+ }
|
|
+
|
|
if ( ints[packetId] )
|
|
{
|
|
rewriteInt( packet, oldId, newId, readerIndex + packetIdLength );
|
|
--
|
|
2.42.0
|
|
|