2023-11-07 12:47:27 +01:00
|
|
|
From c900fddebb1bbe7539c16204f74c9565840d4427 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
|
2023-10-29 17:02:58 +01:00
|
|
|
index d79d5e5c..250e7620 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
|
2023-09-21 12:33:23 +02:00
|
|
|
@@ -18,6 +18,14 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
2016-05-28 18:34:39 +02:00
|
|
|
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
|
2023-09-21 12:33:23 +02:00
|
|
|
@@ -36,7 +44,7 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
2016-05-28 18:34:39 +02:00
|
|
|
{
|
|
|
|
int packetId = DefinedPacket.readVarInt( in );
|
|
|
|
|
|
|
|
- DefinedPacket packet = prot.createPacket( packetId, protocolVersion );
|
|
|
|
+ DefinedPacket packet = prot.createPacket( packetId, protocolVersion, supportsForge );
|
|
|
|
if ( packet != null )
|
|
|
|
{
|
2023-10-29 17:02:58 +01:00
|
|
|
packet.read( in, protocol, prot.getDirection(), protocolVersion );
|
2016-05-28 18:34:39 +02:00
|
|
|
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
|
2023-10-29 17:02:58 +01:00
|
|
|
index 2eeca50b..9bd62ceb 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
|
2023-10-29 17:02:58 +01:00
|
|
|
@@ -751,14 +751,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
|
|
|
}
|
2022-03-21 15:08:26 +01:00
|
|
|
- if ( id > MAX_PACKET_ID || id < 0 )
|
2016-05-28 18:34:39 +02:00
|
|
|
+ if ( !hasPacket(id, supportsForge) )
|
|
|
|
{
|
2021-06-11 22:13:31 +02:00
|
|
|
throw new BadPacketException( "Packet with id " + id + " outside of range" );
|
2016-05-28 18:34:39 +02:00
|
|
|
}
|
|
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
|
2023-11-07 12:47:27 +01:00
|
|
|
index ce925db2..6db704bd 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
|
2023-11-07 12:47:27 +01:00
|
|
|
@@ -224,6 +224,12 @@ public class ServerConnector extends PacketHandler
|
2023-09-21 12:33:23 +02:00
|
|
|
public static void handleLogin(ProxyServer bungee, ChannelWrapper ch, UserConnection user, BungeeServerInfo target, ForgeServerHandler handshakeHandler, ServerConnection server, Login login) throws Exception
|
|
|
|
{
|
2016-05-28 18:34:39 +02:00
|
|
|
ServerConnectedEvent event = new ServerConnectedEvent( user, server );
|
|
|
|
+
|
|
|
|
+ if (server.isForgeServer() && user.isForgeUser()) {
|
2023-11-07 12:47:27 +01:00
|
|
|
+ ((net.md_5.bungee.protocol.MinecraftDecoder) server.getCh().getHandle().pipeline().get(net.md_5.bungee.netty.PipelineUtils.PACKET_DECODER)).setSupportsForge(true);
|
|
|
|
+ ((net.md_5.bungee.protocol.MinecraftDecoder) user.getCh().getHandle().pipeline().get(net.md_5.bungee.netty.PipelineUtils.PACKET_DECODER)).setSupportsForge(true);
|
2016-05-28 18:34:39 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
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/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
|
2023-10-29 17:02:58 +01:00
|
|
|
index 9a47f2ec..b768d54a 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
|
2023-10-29 17:02:58 +01:00
|
|
|
@@ -340,6 +340,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 );
|
|
|
|
--
|
2023-11-07 12:47:27 +01:00
|
|
|
2.42.1
|
2016-05-28 18:34:39 +02:00
|
|
|
|