Skip to content

Commit 0d25d43

Browse files
authored
Account for configuration channels in NetworkRegistryMixin#preserveSendableChannels (#171)
Fixes client disconnecting from dedicated server with Fabric mods that register configuration phase packets Signed-off-by: unilock <unilock@fennet.rentals>
1 parent cc242ef commit 0d25d43

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/NetworkRegistryMixin.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,22 @@ private static boolean includeFabricChannels(ICommonPacketListener listener, Res
8383
return original.call(listener, location) || NeoNetworkRegistrar.hasCodecFor(listener.protocol(), listener.flow() == PacketFlow.SERVERBOUND ? PacketFlow.CLIENTBOUND : PacketFlow.SERVERBOUND, location);
8484
}
8585

86-
@ModifyVariable(method = "initializeNeoForgeConnection", at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/network/registration/NetworkPayloadSetup;from(Ljava/util/Map;)Lnet/neoforged/neoforge/network/registration/NetworkPayloadSetup;"), ordinal = 1)
86+
@ModifyVariable(method = "initializeNeoForgeConnection(Lnet/minecraft/network/protocol/configuration/ServerConfigurationPacketListener;Ljava/util/Map;)V", at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/network/registration/NetworkPayloadSetup;from(Ljava/util/Map;)Lnet/neoforged/neoforge/network/registration/NetworkPayloadSetup;"), ordinal = 1)
8787
private static Map<ConnectionProtocol, NegotiationResult> preserveSendableChannels(Map<ConnectionProtocol, NegotiationResult> results, ServerConfigurationPacketListener listener, Map<ConnectionProtocol, Set<ModdedNetworkQueryComponent>> clientChannels) {
88-
Set<ModdedNetworkQueryComponent> channels = clientChannels.get(ConnectionProtocol.PLAY);
89-
if (channels != null && !channels.isEmpty()) {
88+
Set<ModdedNetworkQueryComponent> configChannels = clientChannels.get(ConnectionProtocol.CONFIGURATION);
89+
if (configChannels != null && !configChannels.isEmpty()) {
90+
NegotiationResult negotiation = results.get(ConnectionProtocol.CONFIGURATION);
91+
List<NegotiatedNetworkComponent> components = new ArrayList<>(negotiation.components());
92+
configChannels.stream()
93+
.filter(c -> components.stream().noneMatch(d -> c.id().equals(d.id())) && PayloadTypeRegistryImpl.CONFIGURATION_S2C.get(c.id()) != null)
94+
.forEach(c -> components.add(new NegotiatedNetworkComponent(c.id(), c.version())));
95+
results.put(ConnectionProtocol.CONFIGURATION, new NegotiationResult(components, negotiation.success(), negotiation.failureReasons()));
96+
}
97+
Set<ModdedNetworkQueryComponent> playChannels = clientChannels.get(ConnectionProtocol.PLAY);
98+
if (playChannels != null && !playChannels.isEmpty()) {
9099
NegotiationResult negotiation = results.get(ConnectionProtocol.PLAY);
91100
List<NegotiatedNetworkComponent> components = new ArrayList<>(negotiation.components());
92-
channels.stream()
101+
playChannels.stream()
93102
.filter(c -> components.stream().noneMatch(d -> c.id().equals(d.id())) && PayloadTypeRegistryImpl.PLAY_S2C.get(c.id()) != null)
94103
.forEach(c -> components.add(new NegotiatedNetworkComponent(c.id(), c.version())));
95104
results.put(ConnectionProtocol.PLAY, new NegotiationResult(components, negotiation.success(), negotiation.failureReasons()));

0 commit comments

Comments
 (0)