Skip to content

Commit

Permalink
Initial pass payloads and status still need fixing.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Nov 13, 2023
1 parent ca32d0b commit f59da72
Show file tree
Hide file tree
Showing 135 changed files with 4,042 additions and 3,612 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ spotless {
}
bumpThisNumberIfACustomStepChanges(1)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
--- a/net/minecraft/client/multiplayer/ClientCommonPacketListenerImpl.java
+++ b/net/minecraft/client/multiplayer/ClientCommonPacketListenerImpl.java
@@ -97,12 +97,12 @@
@@ -49,6 +49,7 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.minecraft.tags.TagNetworkSerialization;
+import net.minecraft.util.thread.ReentrantBlockableEventLoop;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import org.slf4j.Logger;
@@ -97,12 +98,12 @@
this.serverBrand = brandpayload.brand();
this.telemetryManager.onServerBrandReceived(brandpayload.brand());
} else {
Expand All @@ -15,3 +23,30 @@

protected abstract RegistryAccess.Frozen registryAccess();

@@ -231,6 +232,10 @@
}

public void send(Packet<?> p_295097_) {
+ if (!net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().canSendPacket(p_295097_, this)) {
+ return;
+ }
+
this.connection.send(p_295097_);
}

@@ -263,5 +268,15 @@

@OnlyIn(Dist.CLIENT)
static record DeferredPacket(Packet<? extends ServerboundPacketListener> packet, BooleanSupplier sendCondition, long expirationTime) {
+ }
+
+ @Override
+ public Connection getConnection() {
+ return connection;
+ }
+
+ @Override
+ public ReentrantBlockableEventLoop<?> getMainThreadEventLoop() {
+ return minecraft;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,107 @@
--- a/net/minecraft/client/multiplayer/ClientConfigurationPacketListenerImpl.java
+++ b/net/minecraft/client/multiplayer/ClientConfigurationPacketListenerImpl.java
@@ -44,11 +44,15 @@
@@ -3,28 +3,39 @@
import com.mojang.authlib.GameProfile;
import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.Connection;
import net.minecraft.network.TickablePacketListener;
+import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.PacketUtils;
+import net.minecraft.network.protocol.common.custom.BrandPayload;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.configuration.ClientConfigurationPacketListener;
import net.minecraft.network.protocol.configuration.ClientboundFinishConfigurationPacket;
import net.minecraft.network.protocol.configuration.ClientboundRegistryDataPacket;
import net.minecraft.network.protocol.configuration.ClientboundUpdateEnabledFeaturesPacket;
import net.minecraft.network.protocol.configuration.ServerboundFinishConfigurationPacket;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
+import net.neoforged.neoforge.network.registration.NetworkRegistry;
import org.slf4j.Logger;

+import java.util.HashMap;
+import java.util.Map;
+
@OnlyIn(Dist.CLIENT)
public class ClientConfigurationPacketListenerImpl extends ClientCommonPacketListenerImpl implements TickablePacketListener, ClientConfigurationPacketListener {
private static final Logger LOGGER = LogUtils.getLogger();
private final GameProfile localGameProfile;
private RegistryAccess.Frozen receivedRegistries;
private FeatureFlagSet enabledFeatures;
+ private boolean isModdedConnection = false;
+ private boolean isVanillaConnection = true;
+ private Map<ResourceLocation, Component> failureReasons = new HashMap<>();

public ClientConfigurationPacketListenerImpl(Minecraft p_295262_, Connection p_296339_, CommonListenerCookie p_294706_) {
super(p_295262_, p_296339_, p_294706_);
@@ -44,11 +55,38 @@
}

@Override
- protected void handleCustomPayload(CustomPacketPayload p_295411_) {
- this.handleUnknownCustomPayload(p_295411_);
+ protected void handleCustomPayload(net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket p_295727_, CustomPacketPayload p_295411_) {
+ if (p_295411_ instanceof net.neoforged.neoforge.network.payload.ModdedNetworkQueryPayload) {
+ this.isModdedConnection = true;
+ net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().onNetworkQuery(this);
+ return;
+ }
+
+ if (p_295411_ instanceof net.neoforged.neoforge.network.payload.ModdedNetworkPayload moddedNetworkPayload) {
+ net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().onModdedNetworkConnectionEstablished(this, moddedNetworkPayload.configuration(), moddedNetworkPayload.play());
+ return;
+ }
+
+ if (p_295411_ instanceof net.neoforged.neoforge.network.payload.ModdedNetworkSetupFailedPayload setupFailedPayload) {
+ failureReasons = setupFailedPayload.failureReasons();
+ }
+
+ if (!this.isModdedConnection && p_295411_ instanceof BrandPayload) {
+ this.isVanillaConnection = true;
+ if (!net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().onVanillaNetworkConnectionEstablished(this)) {
+ return;
+ }
+ }
+
+ if (this.isModdedConnection) {
+ NetworkRegistry.getInstance().onModdedPacketAtClient(this, p_295727_);
+ return;
+ }
+
+ this.handleUnknownCustomPayload(p_295727_, p_295411_);
}

- private void handleUnknownCustomPayload(CustomPacketPayload p_296412_) {
+ private void handleUnknownCustomPayload(net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket p_295727_, CustomPacketPayload p_296412_) {
+ if (p_296412_ instanceof net.neoforged.neoforge.network.custom.payload.SimplePayload simplePayload && net.neoforged.neoforge.network.NetworkHooks.onCustomPayload(p_295727_, simplePayload, connection)) {
+ return;
+ }
+
LOGGER.warn("Unknown custom packet payload: {}", p_296412_.id());
}

@@ -84,6 +122,7 @@
this.telemetryManager,
this.receivedRegistries,
this.enabledFeatures,
+ this.isModdedConnection,
this.serverBrand,
this.serverData,
this.postDisconnectScreen
@@ -97,5 +136,14 @@
@Override
public void tick() {
this.sendDeferredPackets();
+ }
+
+ @Override
+ protected Screen createDisconnectScreen(Component p_296470_) {
+ final Screen superScreen = super.createDisconnectScreen(p_296470_);
+ if (failureReasons.isEmpty())
+ return superScreen;
+
+ return new net.neoforged.neoforge.client.gui.ModMismatchDisconnectedScreen(superScreen, p_296470_, failureReasons);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
--- a/net/minecraft/client/multiplayer/ClientHandshakePacketListenerImpl.java
+++ b/net/minecraft/client/multiplayer/ClientHandshakePacketListenerImpl.java
@@ -180,7 +180,7 @@
@@ -165,6 +165,7 @@
this.minecraft.getTelemetryManager().createWorldSessionManager(this.newWorld, this.worldLoadDuration, this.minigameName),
ClientRegistryLayer.createRegistryAccess().compositeAccess(),
FeatureFlags.DEFAULT_FLAGS,
+ false,
null,
this.serverData,
this.parent
@@ -180,7 +181,7 @@
if (this.serverData != null && this.serverData.isRealm()) {
this.minecraft.setScreen(new DisconnectedRealmsScreen(this.parent, CommonComponents.CONNECT_FAILED, p_104543_));
} else {
Expand All @@ -9,7 +17,7 @@
}
}

@@ -203,6 +203,7 @@
@@ -203,6 +204,7 @@

@Override
public void handleCustomQuery(ClientboundCustomQueryPacket p_104545_) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
--- a/net/minecraft/client/multiplayer/ClientPacketListener.java
+++ b/net/minecraft/client/multiplayer/ClientPacketListener.java
@@ -403,6 +403,7 @@
@@ -334,6 +334,7 @@
private MessageSignatureCache messageSignatureCache = MessageSignatureCache.createDefault();
private final ChunkBatchSizeCalculator chunkBatchSizeCalculator = new ChunkBatchSizeCalculator();
private final PingDebugMonitor pingDebugMonitor;
+ private final boolean isModdedConnection;
private boolean seenInsecureChatWarning = false;
private volatile boolean closed;

@@ -345,6 +346,7 @@
this.advancements = new ClientAdvancements(p_253924_, this.telemetryManager);
this.suggestionsProvider = new ClientSuggestionProvider(this, p_253924_);
this.pingDebugMonitor = new PingDebugMonitor(this, p_253924_.getDebugOverlay().getPingLogger());
+ this.isModdedConnection = p_295121_.isModdedConnection();
}

public ClientSuggestionProvider getSuggestionsProvider() {
@@ -403,6 +405,7 @@

this.minecraft.debugRenderer.clear();
this.minecraft.player.resetPos();
+ net.neoforged.neoforge.client.ClientHooks.firePlayerLogin(this.minecraft.gameMode, this.minecraft.player, this.minecraft.getConnection().connection);
this.minecraft.player.setId(p_105030_.playerId());
this.level.addEntity(this.minecraft.player);
this.minecraft.player.input = new KeyboardInput(this.minecraft.options);
@@ -416,6 +417,7 @@
this.minecraft.player.setPortalCooldown(commonplayerspawninfo.portalCooldown());
this.minecraft.gameMode.setLocalMode(commonplayerspawninfo.gameType(), commonplayerspawninfo.previousGameType());
this.minecraft.options.setServerRenderDistance(p_105030_.chunkRadius());
+ net.neoforged.neoforge.network.NetworkHooks.sendMCRegistryPackets(connection, net.neoforged.neoforge.network.PlayNetworkDirection.PLAY_TO_SERVER);
this.chatSession = null;
this.lastSeenMessages = new LastSeenMessagesTracker(20);
this.messageSignatureCache = MessageSignatureCache.createDefault();
@@ -1110,7 +1112,9 @@
@@ -764,6 +767,7 @@
this.telemetryManager,
this.registryAccess,
this.enabledFeatures,
+ this.isModdedConnection,
this.serverBrand,
this.serverData,
this.postDisconnectScreen
@@ -1110,7 +1114,9 @@
localplayer1.getAttributes().assignValues(localplayer.getAttributes());
}

Expand All @@ -26,7 +42,7 @@
this.level.addEntity(localplayer1);
localplayer1.setYRot(-180.0F);
localplayer1.input = new KeyboardInput(this.minecraft.options);
@@ -1230,10 +1234,7 @@
@@ -1230,10 +1236,7 @@
PacketUtils.ensureRunningOnSameThread(p_104976_, this, this.minecraft);
BlockPos blockpos = p_104976_.getPos();
this.minecraft.level.getBlockEntity(blockpos, p_104976_.getType()).ifPresent(p_205557_ -> {
Expand All @@ -38,7 +54,7 @@

if (p_205557_ instanceof CommandBlockEntity && this.minecraft.screen instanceof CommandBlockEditScreen) {
((CommandBlockEditScreen)this.minecraft.screen).updateGui();
@@ -1395,7 +1396,9 @@
@@ -1395,7 +1398,9 @@
@Override
public void handleCommands(ClientboundCommandsPacket p_104990_) {
PacketUtils.ensureRunningOnSameThread(p_104990_, this, this.minecraft);
Expand All @@ -49,15 +65,15 @@
}

@Override
@@ -1417,6 +1420,7 @@
@@ -1417,6 +1422,7 @@
ClientRecipeBook clientrecipebook = this.minecraft.player.getRecipeBook();
clientrecipebook.setupCollections(this.recipeManager.getRecipes(), this.minecraft.level.registryAccess());
this.minecraft.populateSearchTree(SearchRegistry.RECIPE_COLLECTIONS, clientrecipebook.getCollections());
+ net.neoforged.neoforge.client.ClientHooks.onRecipesUpdated(this.recipeManager);
}

@Override
@@ -1523,7 +1527,8 @@
@@ -1523,7 +1529,8 @@
Blocks.rebuildCache();
}

Expand All @@ -67,7 +83,7 @@
}

@Override
@@ -1855,7 +1860,7 @@
@@ -1855,7 +1862,7 @@
}

@Override
Expand All @@ -76,25 +92,25 @@
if (p_295851_ instanceof PathfindingDebugPayload pathfindingdebugpayload) {
this.minecraft
.debugRenderer
@@ -1922,11 +1927,15 @@
@@ -1922,10 +1929,16 @@
.gameEventListenerRenderer
.trackListener(gameeventlistenerdebugpayload.listenerPos(), gameeventlistenerdebugpayload.listenerRange());
} else {
- this.handleUnknownCustomPayload(p_295851_);
+ this.handleUnknownCustomPayload(p_295727_, p_295851_);
+ if (this.isModdedConnection) {
+ net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().onModdedPacketAtClient(
+ this, p_295727_
+ );
+ return;
+ }
this.handleUnknownCustomPayload(p_295851_);
}
}

- private void handleUnknownCustomPayload(CustomPacketPayload p_294389_) {
+ private void handleUnknownCustomPayload(net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket p_295727_, CustomPacketPayload p_294389_) {
+ if (p_294389_ instanceof net.neoforged.neoforge.network.custom.payload.SimplePayload simplePayload && net.neoforged.neoforge.network.NetworkHooks.onCustomPayload(p_295727_, simplePayload, connection)) {
+ return;
+ }
+
-
+
private void handleUnknownCustomPayload(CustomPacketPayload p_294389_) {
LOGGER.warn("Unknown custom packet payload: {}", p_294389_.id());
}

@@ -2302,6 +2311,8 @@
@@ -2302,6 +2315,8 @@
}

public void sendChat(String p_249888_) {
Expand All @@ -103,7 +119,7 @@
Instant instant = Instant.now();
long i = Crypt.SaltSupplier.getLong();
LastSeenMessagesTracker.Update lastseenmessagestracker$update = this.lastSeenMessages.generateAndApplyUpdate();
@@ -2311,6 +2322,7 @@
@@ -2311,6 +2326,7 @@
}

public void sendCommand(String p_250092_) {
Expand Down
33 changes: 16 additions & 17 deletions patches/net/minecraft/network/Connection.java.patch
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -97,6 +97,7 @@
private volatile Component delayedDisconnect;
@Nullable
BandwidthDebugMonitor bandwidthDebugMonitor;
+ private java.util.function.Consumer<Connection> activationHandler;

public Connection(PacketFlow p_129482_) {
this.receiving = p_129482_;
@@ -107,6 +108,7 @@
super.channelActive(p_129525_);
this.channel = p_129525_.channel();
this.address = this.channel.remoteAddress();
+ if (activationHandler != null) activationHandler.accept(this);
@@ -110,6 +110,7 @@
if (this.delayedDisconnect != null) {
this.disconnect(this.delayedDisconnect);
}
+ net.neoforged.neoforge.network.connection.ConnectionUtils.setConnection(p_129525_, this);
}

public static void setInitialProtocolAttributes(Channel p_294962_) {
@@ -120,6 +121,7 @@
@Override
public void channelInactive(ChannelHandlerContext p_129527_) {
this.disconnect(Component.translatable("disconnect.endOfStream"));
+ net.neoforged.neoforge.network.connection.ConnectionUtils.removeConnection(p_129527_);
}

@Override
@@ -371,7 +373,7 @@
if (this.address == null) {
return "local";
Expand All @@ -25,24 +25,23 @@
}
}

@@ -410,6 +412,8 @@
@@ -410,6 +412,7 @@
}

public static ChannelFuture connect(InetSocketAddress p_290034_, boolean p_290035_, final Connection p_290031_) {
+ net.neoforged.neoforge.network.DualStackUtils.checkIPv6(p_290034_.getAddress());
+ p_290031_.activationHandler = net.neoforged.neoforge.network.NetworkHooks::registerClientLoginChannel;
Class<? extends SocketChannel> oclass;
EventLoopGroup eventloopgroup;
if (Epoll.isAvailable() && p_290035_) {
@@ -466,6 +470,7 @@
@@ -466,6 +469,7 @@

public static Connection connectToLocalServer(SocketAddress p_129494_) {
final Connection connection = new Connection(PacketFlow.CLIENTBOUND);
+ connection.activationHandler = net.neoforged.neoforge.network.NetworkHooks::registerClientLoginChannel;
new Bootstrap().group(LOCAL_WORKER_GROUP.get()).handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel p_129557_) {
@@ -558,6 +563,14 @@
@@ -558,6 +562,14 @@

public float getAverageSentPackets() {
return this.averageSentPackets;
Expand Down
Loading

0 comments on commit f59da72

Please sign in to comment.