Skip to content

Commit

Permalink
Add the unversioned patches.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Nov 13, 2023
1 parent f59da72 commit f4b4702
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/net/minecraft/client/multiplayer/CommonListenerCookie.java
+++ b/net/minecraft/client/multiplayer/CommonListenerCookie.java
@@ -15,6 +15,7 @@
WorldSessionTelemetryManager telemetryManager,
RegistryAccess.Frozen receivedRegistries,
FeatureFlagSet enabledFeatures,
+ boolean isModdedConnection,
@Nullable String serverBrand,
@Nullable ServerData serverData,
@Nullable Screen postDisconnectScreen
135 changes: 135 additions & 0 deletions patches/net/minecraft/network/ConnectionProtocol.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
--- a/net/minecraft/network/ConnectionProtocol.java
+++ b/net/minecraft/network/ConnectionProtocol.java
@@ -3,6 +3,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.logging.LogUtils;
+import io.netty.channel.ChannelHandlerContext;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
@@ -12,6 +13,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.function.BiFunction;
import java.util.function.Function;
import javax.annotation.Nullable;
import net.minecraft.Util;
@@ -238,7 +240,7 @@
.addPacket(ClientboundContainerSetSlotPacket.class, ClientboundContainerSetSlotPacket::new)
.addPacket(ClientboundCooldownPacket.class, ClientboundCooldownPacket::new)
.addPacket(ClientboundCustomChatCompletionsPacket.class, ClientboundCustomChatCompletionsPacket::new)
- .addPacket(ClientboundCustomPayloadPacket.class, ClientboundCustomPayloadPacket::new)
+ .addContextualPacket(ClientboundCustomPayloadPacket.class, (buf, context) -> new ClientboundCustomPayloadPacket(buf, context, ConnectionProtocol.play()))
.addPacket(ClientboundDamageEventPacket.class, ClientboundDamageEventPacket::new)
.addPacket(ClientboundDeleteChatPacket.class, ClientboundDeleteChatPacket::new)
.addPacket(ClientboundDisconnectPacket.class, ClientboundDisconnectPacket::new)
@@ -346,7 +348,7 @@
.addPacket(ServerboundContainerButtonClickPacket.class, ServerboundContainerButtonClickPacket::new)
.addPacket(ServerboundContainerClickPacket.class, ServerboundContainerClickPacket::new)
.addPacket(ServerboundContainerClosePacket.class, ServerboundContainerClosePacket::new)
- .addPacket(ServerboundCustomPayloadPacket.class, ServerboundCustomPayloadPacket::new)
+ .addContextualPacket(ServerboundCustomPayloadPacket.class, (buf, context) -> new ServerboundCustomPayloadPacket(buf, context, ConnectionProtocol.play()))
.addPacket(ServerboundEditBookPacket.class, ServerboundEditBookPacket::new)
.addPacket(ServerboundEntityTagQuery.class, ServerboundEntityTagQuery::new)
.addPacket(ServerboundInteractPacket.class, ServerboundInteractPacket::new)
@@ -430,7 +432,7 @@
.addFlow(
PacketFlow.CLIENTBOUND,
new ConnectionProtocol.PacketSet<net.minecraft.network.protocol.configuration.ClientConfigurationPacketListener>()
- .addPacket(ClientboundCustomPayloadPacket.class, ClientboundCustomPayloadPacket::new)
+ .addContextualPacket(ClientboundCustomPayloadPacket.class, (buf, context) -> new ClientboundCustomPayloadPacket(buf, context, ConnectionProtocol.configuration()))
.addPacket(ClientboundDisconnectPacket.class, ClientboundDisconnectPacket::new)
.addPacket(ClientboundFinishConfigurationPacket.class, ClientboundFinishConfigurationPacket::new)
.addPacket(ClientboundKeepAlivePacket.class, ClientboundKeepAlivePacket::new)
@@ -444,7 +446,7 @@
PacketFlow.SERVERBOUND,
new ConnectionProtocol.PacketSet<net.minecraft.network.protocol.configuration.ServerConfigurationPacketListener>()
.addPacket(ServerboundClientInformationPacket.class, ServerboundClientInformationPacket::new)
- .addPacket(ServerboundCustomPayloadPacket.class, ServerboundCustomPayloadPacket::new)
+ .addContextualPacket(ServerboundCustomPayloadPacket.class, (buf, context) -> new ServerboundCustomPayloadPacket(buf, context, ConnectionProtocol.play()))
.addPacket(ServerboundFinishConfigurationPacket.class, ServerboundFinishConfigurationPacket::new)
.addPacket(ServerboundKeepAlivePacket.class, ServerboundKeepAlivePacket::new)
.addPacket(ServerboundPongPacket.class, ServerboundPongPacket::new)
@@ -456,6 +458,22 @@
private final String id;
private final Map<PacketFlow, ConnectionProtocol.CodecData<?>> flows;

+ private static ConnectionProtocol play() {
+ return PLAY;
+ }
+
+ private static ConnectionProtocol configuration() {
+ return CONFIGURATION;
+ }
+
+ public boolean isPlay() {
+ return this == PLAY;
+ }
+
+ public boolean isConfiguration() {
+ return this == CONFIGURATION;
+ }
+
private static ConnectionProtocol.ProtocolBuilder protocol() {
return new ConnectionProtocol.ProtocolBuilder();
}
@@ -514,8 +532,8 @@
}

@Nullable
- public Packet<?> createPacket(int p_294972_, FriendlyByteBuf p_296217_) {
- return this.packetSet.createPacket(p_294972_, p_296217_);
+ public Packet<?> createPacket(int p_294972_, FriendlyByteBuf p_296217_, ChannelHandlerContext p_130535_) {
+ return this.packetSet.createPacket(p_294972_, p_296217_, p_130535_);
}

public boolean isValidPacketType(Packet<?> p_294142_) {
@@ -528,19 +546,28 @@
final Object2IntMap<Class<? extends Packet<? super T>>> classToId = Util.make(
new Object2IntOpenHashMap<>(), p_129613_ -> p_129613_.defaultReturnValue(-1)
);
+ /**
+ * @deprecated Use {@link #contextualIdToDeserializer} instead it allows for context to be passed to the deserializer
+ */
+ @Deprecated
private final List<Function<FriendlyByteBuf, ? extends Packet<? super T>>> idToDeserializer = Lists.newArrayList();
+ private final List<BiFunction<FriendlyByteBuf, ChannelHandlerContext, ? extends Packet<? super T>>> contextualIdToDeserializer = Lists.newArrayList();
private BundlerInfo bundlerInfo = BundlerInfo.EMPTY;
private final Set<Class<? extends Packet<T>>> extraClasses = new HashSet<>();
-
+
public <P extends Packet<? super T>> ConnectionProtocol.PacketSet<T> addPacket(Class<P> p_178331_, Function<FriendlyByteBuf, P> p_178332_) {
- int i = this.idToDeserializer.size();
- int j = this.classToId.put(p_178331_, i);
+ return addContextualPacket(p_178331_, (buf, channelHandlerContext) -> p_178332_.apply(buf));
+ }
+
+ public <P extends Packet<? super T>> ConnectionProtocol.PacketSet<T> addContextualPacket(Class<P> packetClass, BiFunction<FriendlyByteBuf, ChannelHandlerContext, P> readerBuilder) {
+ int i = this.contextualIdToDeserializer.size();
+ int j = this.classToId.put(packetClass, i);
if (j != -1) {
- String s = "Packet " + p_178331_ + " is already registered to ID " + j;
+ String s = "Packet " + packetClass + " is already registered to ID " + j;
LOGGER.error(LogUtils.FATAL_MARKER, s);
throw new IllegalArgumentException(s);
} else {
- this.idToDeserializer.add(p_178332_);
+ this.contextualIdToDeserializer.add(readerBuilder);
return this;
}
}
@@ -566,9 +593,9 @@
}

@Nullable
- public Packet<?> createPacket(int p_178328_, FriendlyByteBuf p_178329_) {
- Function<FriendlyByteBuf, ? extends Packet<? super T>> function = this.idToDeserializer.get(p_178328_);
- return function != null ? function.apply(p_178329_) : null;
+ public Packet<?> createPacket(int p_178328_, FriendlyByteBuf p_178329_, ChannelHandlerContext p_130535_) {
+ BiFunction<FriendlyByteBuf, ChannelHandlerContext, ? extends Packet<? super T>> function = this.contextualIdToDeserializer.get(p_178328_);
+ return function != null ? function.apply(p_178329_, p_130535_) : null;
}

public BundlerInfo bundlerInfo() {
11 changes: 11 additions & 0 deletions patches/net/minecraft/network/PacketDecoder.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/net/minecraft/network/PacketDecoder.java
+++ b/net/minecraft/network/PacketDecoder.java
@@ -28,7 +28,7 @@
ConnectionProtocol.CodecData<?> codecdata = attribute.get();
FriendlyByteBuf friendlybytebuf = new FriendlyByteBuf(p_130536_);
int j = friendlybytebuf.readVarInt();
- Packet<?> packet = codecdata.createPacket(j, friendlybytebuf);
+ Packet<?> packet = codecdata.createPacket(j, friendlybytebuf, p_130535_);
if (packet == null) {
throw new IOException("Bad packet id " + j);
} else {
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/net/minecraft/network/protocol/common/ClientCommonPacketListener.java
+++ b/net/minecraft/network/protocol/common/ClientCommonPacketListener.java
@@ -2,7 +2,7 @@

import net.minecraft.network.ClientboundPacketListener;

-public interface ClientCommonPacketListener extends ClientboundPacketListener {
+public interface ClientCommonPacketListener extends ClientboundPacketListener, net.neoforged.neoforge.common.extensions.IClientCommonPacketListenerExtension {
void handleKeepAlive(ClientboundKeepAlivePacket p_295236_);

void handlePing(ClientboundPingPacket p_296451_);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/net/minecraft/network/protocol/common/ServerCommonPacketListener.java
+++ b/net/minecraft/network/protocol/common/ServerCommonPacketListener.java
@@ -2,7 +2,7 @@

import net.minecraft.network.protocol.game.ServerPacketListener;

-public interface ServerCommonPacketListener extends ServerPacketListener {
+public interface ServerCommonPacketListener extends ServerPacketListener, net.neoforged.neoforge.common.extensions.IClientboundPacketSenderExtension {
void handleKeepAlive(ServerboundKeepAlivePacket p_296457_);

void handlePong(ServerboundPongPacket p_294309_);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/net/minecraft/network/protocol/configuration/ServerConfigurationPacketListener.java
+++ b/net/minecraft/network/protocol/configuration/ServerConfigurationPacketListener.java
@@ -3,7 +3,7 @@
import net.minecraft.network.ConnectionProtocol;
import net.minecraft.network.protocol.common.ServerCommonPacketListener;

-public interface ServerConfigurationPacketListener extends ServerCommonPacketListener {
+public interface ServerConfigurationPacketListener extends ServerCommonPacketListener, net.neoforged.neoforge.common.extensions.IServerConfigurationPacketListenerExtension {
@Override
default ConnectionProtocol protocol() {
return ConnectionProtocol.CONFIGURATION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/net/minecraft/server/network/CommonListenerCookie.java
+++ b/net/minecraft/server/network/CommonListenerCookie.java
@@ -3,8 +3,8 @@
import com.mojang.authlib.GameProfile;
import net.minecraft.server.level.ClientInformation;

-public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation) {
+public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean isModdedConnection) {
public static CommonListenerCookie createInitial(GameProfile p_302024_) {
- return new CommonListenerCookie(p_302024_, 0, ClientInformation.createDefault());
+ return new CommonListenerCookie(p_302024_, 0, ClientInformation.createDefault(), false);
}
}
21 changes: 21 additions & 0 deletions patches/net/minecraft/server/network/ConfigurationTask.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--- a/net/minecraft/server/network/ConfigurationTask.java
+++ b/net/minecraft/server/network/ConfigurationTask.java
@@ -2,6 +2,7 @@

import java.util.function.Consumer;
import net.minecraft.network.protocol.Packet;
+import net.minecraft.resources.ResourceLocation;

public interface ConfigurationTask {
void start(Consumer<Packet<?>> p_294184_);
@@ -9,6 +10,10 @@
ConfigurationTask.Type type();

public static record Type(String id) {
+ public Type(ResourceLocation location) {
+ this(location.toString());
+ }
+
@Override
public String toString() {
return this.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
--- a/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
@@ -12,11 +12,7 @@
import net.minecraft.network.TickablePacketListener;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.PacketUtils;
-import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
-import net.minecraft.network.protocol.common.ClientboundDisconnectPacket;
-import net.minecraft.network.protocol.common.ClientboundUpdateTagsPacket;
-import net.minecraft.network.protocol.common.ServerboundClientInformationPacket;
-import net.minecraft.network.protocol.common.ServerboundResourcePackPacket;
+import net.minecraft.network.protocol.common.*;
import net.minecraft.network.protocol.common.custom.BrandPayload;
import net.minecraft.network.protocol.configuration.ClientboundRegistryDataPacket;
import net.minecraft.network.protocol.configuration.ClientboundUpdateEnabledFeaturesPacket;
@@ -31,6 +27,8 @@
import net.minecraft.server.players.PlayerList;
import net.minecraft.tags.TagNetworkSerialization;
import net.minecraft.world.flag.FeatureFlags;
+import net.neoforged.neoforge.network.payload.ModdedNetworkQueryPayload;
+import net.neoforged.neoforge.network.registration.NetworkRegistry;
import org.slf4j.Logger;

public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketListenerImpl implements TickablePacketListener, ServerConfigurationPacketListener {
@@ -41,6 +39,8 @@
@Nullable
private ConfigurationTask currentTask;
private ClientInformation clientInformation;
+ private boolean isModdedConnection = false;
+ private boolean isHandlingModdedConfigurationPhase = false;

public ServerConfigurationPacketListenerImpl(MinecraftServer p_294645_, Connection p_295787_, CommonListenerCookie p_302003_) {
super(p_294645_, p_295787_, p_302003_);
@@ -65,6 +65,11 @@
}

public void startConfiguration() {
+ this.send(new ModdedNetworkQueryPayload());
+ this.send(new ClientboundPingPacket(0));
+ }
+
+ private void runConfiguration() {
this.send(new ClientboundCustomPayloadPacket(new BrandPayload(this.server.getServerModName())));
LayeredRegistryAccess<RegistryLayer> layeredregistryaccess = this.server.registries();
this.send(new ClientboundUpdateEnabledFeaturesPacket(FeatureFlags.REGISTRY.toNames(this.server.getWorldData().enabledFeatures())));
@@ -86,6 +91,10 @@

private void addOptionalTasks() {
this.server.getServerResourcePack().ifPresent(p_296496_ -> this.configurationTasks.add(new ServerResourcePackConfigurationTask(p_296496_)));
+
+ this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseStarted(this));
+ this.configurationTasks.addAll(net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.network.event.OnGameConfiguration()).getConfigurationTasks());
+ this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseCompleted(this));
}

@Override
@@ -100,7 +109,40 @@
this.finishCurrentTask(ServerResourcePackConfigurationTask.TYPE);
}
}
-
+
+ @Override
+ public void handleCustomPayload(ServerboundCustomPayloadPacket p_294276_) {
+ if (p_294276_.payload() instanceof ModdedNetworkQueryPayload moddedEnvironmentPayload) {
+ this.isModdedConnection = true;
+ NetworkRegistry.getInstance()
+ .onModdedConnectionDetectedAtServer(
+ this,
+ moddedEnvironmentPayload.configuration(),
+ moddedEnvironmentPayload.play()
+ );
+ return;
+ }
+
+ if (!isHandlingModdedConfigurationPhase) {
+ super.handleCustomPayload(p_294276_);
+ return;
+ }
+
+ NetworkRegistry.getInstance().onModdedPacketAtServer(this, p_294276_);
+ }
+
+ @Override
+ public void handlePong(ServerboundPongPacket p_295142_) {
+ super.handlePong(p_295142_);
+ if (p_295142_.getId() == 0) {
+ if (!this.isModdedConnection && !net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().onVanillaConnectionDetectedAtServer(this)) {
+ return;
+ }
+
+ this.runConfiguration();
+ }
+ }
+
@Override
public void handleConfigurationFinished(ServerboundFinishConfigurationPacket p_294283_) {
this.connection.suspendInboundAfterProtocolChange();
@@ -121,7 +163,7 @@
}

ServerPlayer serverplayer = playerlist.getPlayerForLogin(this.gameProfile, this.clientInformation);
- playerlist.placeNewPlayer(this.connection, serverplayer, this.createCookie(this.clientInformation));
+ playerlist.placeNewPlayer(this.connection, serverplayer, this.createCookie(this.clientInformation, this.isModdedConnection));
this.connection.resumeInboundAfterProtocolChange();
} catch (Exception exception) {
LOGGER.error("Couldn't place player in world", (Throwable)exception);
@@ -147,7 +189,8 @@
}
}

- private void finishCurrentTask(ConfigurationTask.Type p_294853_) {
+ @Override
+ public void finishCurrentTask(ConfigurationTask.Type p_294853_) {
ConfigurationTask.Type configurationtask$type = this.currentTask != null ? this.currentTask.type() : null;
if (!p_294853_.equals(configurationtask$type)) {
throw new IllegalStateException("Unexpected request for task finish, current task: " + configurationtask$type + ", requested: " + p_294853_);
@@ -155,5 +198,15 @@
this.currentTask = null;
this.startNextTask();
}
+ }
+
+ public void onModdedConfigurationPhaseStarted() {
+ isHandlingModdedConfigurationPhase = true;
+ finishCurrentTask(net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseStarted.TYPE);
+ }
+
+ public void onModdedConfigurationPhaseEnded() {
+ isHandlingModdedConfigurationPhase = false;
+ finishCurrentTask(net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseCompleted.TYPE);
}
}

0 comments on commit f4b4702

Please sign in to comment.