2020-06-23 23:13:11 +02:00
|
|
|
From 039537507c3f69d0df0093fc0ebedeb91e70ac0d Mon Sep 17 00:00:00 2001
|
2016-05-28 18:34:39 +02:00
|
|
|
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
|
2018-07-15 12:58:44 +02:00
|
|
|
index ea44573d..5b32effe 100644
|
2016-05-28 18:34:39 +02:00
|
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
|
|
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
|
|
|
|
@@ -16,6 +16,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
|
|
|
|
@@ -27,7 +35,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
|
2020-06-23 23:13:11 +02:00
|
|
|
index 3e1776f7..fa34de48 100644
|
2016-05-28 18:34:39 +02:00
|
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
|
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
2020-06-23 23:13:11 +02:00
|
|
|
@@ -431,14 +431,23 @@ public enum Protocol
|
2019-03-09 02:29:03 +01:00
|
|
|
return protocol;
|
2016-05-28 18:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ public boolean hasPacket(int i, boolean supportsForge) {
|
|
|
|
+ return supportsForge || i >= 0 && i <= MAX_PACKET_ID;
|
|
|
|
+ }
|
|
|
|
+
|
2017-05-14 17:20:22 +02:00
|
|
|
public final DefinedPacket createPacket(int id, int version)
|
2018-07-22 18:40:31 +02:00
|
|
|
+ {
|
2017-05-14 17:20:22 +02:00
|
|
|
+ return createPacket(id, version, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public final DefinedPacket createPacket(int id, int version, boolean supportsForge)
|
2018-07-22 18:40:31 +02:00
|
|
|
{
|
2019-03-09 02:29:03 +01:00
|
|
|
ProtocolData protocolData = getProtocolData( version );
|
2018-01-28 12:36:01 +01:00
|
|
|
if ( protocolData == null )
|
2016-05-28 18:34:39 +02:00
|
|
|
{
|
2019-02-26 20:53:11 +01:00
|
|
|
throw new BadPacketException( "Unsupported protocol version " + version );
|
2016-05-28 18:34:39 +02:00
|
|
|
}
|
|
|
|
- if ( id > MAX_PACKET_ID )
|
|
|
|
+ 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
|
2020-06-23 23:13:11 +02:00
|
|
|
index 28e0d5f3..3abf2047 100644
|
2016-05-28 18:34:39 +02:00
|
|
|
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
|
|
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
|
2020-01-21 18:36:22 +01:00
|
|
|
@@ -32,7 +32,9 @@ import net.md_5.bungee.forge.ForgeUtils;
|
2016-05-28 18:34:39 +02:00
|
|
|
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;
|
2018-07-15 12:58:44 +02:00
|
|
|
import net.md_5.bungee.protocol.PacketWrapper;
|
2016-05-28 18:34:39 +02:00
|
|
|
import net.md_5.bungee.protocol.Protocol;
|
2018-07-15 12:58:44 +02:00
|
|
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
2020-03-07 23:50:46 +01:00
|
|
|
@@ -203,6 +205,12 @@ public class ServerConnector extends PacketHandler
|
2016-05-28 18:34:39 +02:00
|
|
|
|
|
|
|
ServerConnection server = new ServerConnection( ch, target );
|
|
|
|
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 );
|
|
|
|
|
2018-07-15 12:58:44 +02:00
|
|
|
ch.write( BungeeCord.getInstance().registerChannels( user.getPendingConnection().getVersion() ) );
|
2016-05-28 18:34:39 +02:00
|
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
2020-06-23 23:13:11 +02:00
|
|
|
index 53b12482..001ee1c2 100644
|
2016-05-28 18:34:39 +02:00
|
|
|
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
2020-01-21 18:36:22 +01:00
|
|
|
@@ -72,6 +72,7 @@ public final class UserConnection implements ProxiedPlayer
|
2016-05-28 18:34:39 +02:00
|
|
|
@NonNull
|
|
|
|
private final ProxyServer bungee;
|
|
|
|
@NonNull
|
|
|
|
+ @Getter
|
|
|
|
private final ChannelWrapper ch;
|
|
|
|
@Getter
|
|
|
|
@NonNull
|
|
|
|
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
|
2020-06-23 23:13:11 +02:00
|
|
|
index 76fcce9f..8a16fa93 100644
|
2016-05-28 18:34:39 +02:00
|
|
|
--- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
|
|
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
|
2020-06-23 23:13:11 +02:00
|
|
|
@@ -317,6 +317,12 @@ public abstract class EntityMap
|
2016-05-28 18:34:39 +02:00
|
|
|
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 );
|
|
|
|
--
|
2020-06-23 23:13:11 +02:00
|
|
|
2.27.0
|
2016-05-28 18:34:39 +02:00
|
|
|
|