9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-26 02:19:19 +00:00

AlternativeJoin to skip sync in syncAfterConfigurationChange

This commit is contained in:
Taiyou06
2025-05-08 11:17:05 +02:00
parent 56cc95b9ee
commit f0ff93a1ce
2 changed files with 106 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Thu, 8 May 2025 11:14:06 +0200
Subject: [PATCH] Alternative join logic
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index f998cf8d70302a21289de4d84b46d322d0b8a8fe..85b3e78ae72d550c5cce0b46e059737086527a7e 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -66,6 +66,8 @@ import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
+import static org.dreeam.leaf.config.modules.network.AlternativeJoin.AlternativeJoin;
+
public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
private static final float AVERAGE_PACKETS_SMOOTHING = 0.75F;
private static final Logger LOGGER = LogUtils.getLogger();
@@ -340,36 +342,43 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
public <T extends PacketListener> void setupInboundProtocol(ProtocolInfo<T> protocolInfo, T packetInfo) {
this.validateListener(protocolInfo, packetInfo);
if (protocolInfo.flow() != this.getReceiving()) {
- throw new IllegalStateException("Invalid inbound protocol: " + protocolInfo.id());
+ throw new IllegalStateException("Invalid inbound protocol: " + String.valueOf(protocolInfo.id()));
+ }
+ this.packetListener = packetInfo;
+ this.disconnectListener = null;
+ UnconfiguredPipelineHandler.InboundConfigurationTask inboundConfigurationTask = UnconfiguredPipelineHandler.setupInboundProtocol(protocolInfo);
+ BundlerInfo bundlerInfo = protocolInfo.bundlerInfo();
+ if (bundlerInfo != null) {
+ PacketBundlePacker packetBundlePacker = new PacketBundlePacker(bundlerInfo);
+ inboundConfigurationTask = inboundConfigurationTask.andThen(context -> context.pipeline().addAfter("decoder", "bundler", (ChannelHandler)packetBundlePacker));
+ }
+ if (!AlternativeJoin) {
+ Connection.syncAfterConfigurationChange(this.channel.writeAndFlush(inboundConfigurationTask));
} else {
- this.packetListener = packetInfo;
- this.disconnectListener = null;
- UnconfiguredPipelineHandler.InboundConfigurationTask inboundConfigurationTask = UnconfiguredPipelineHandler.setupInboundProtocol(protocolInfo);
- BundlerInfo bundlerInfo = protocolInfo.bundlerInfo();
- if (bundlerInfo != null) {
- PacketBundlePacker packetBundlePacker = new PacketBundlePacker(bundlerInfo);
- inboundConfigurationTask = inboundConfigurationTask.andThen(context -> context.pipeline().addAfter("decoder", "bundler", packetBundlePacker));
- }
-
- syncAfterConfigurationChange(this.channel.writeAndFlush(inboundConfigurationTask));
+ this.channel.writeAndFlush(inboundConfigurationTask);
}
}
public void setupOutboundProtocol(ProtocolInfo<?> protocolInfo) {
+ boolean flag;
if (protocolInfo.flow() != this.getSending()) {
- throw new IllegalStateException("Invalid outbound protocol: " + protocolInfo.id());
+ throw new IllegalStateException("Invalid outbound protocol: " + String.valueOf(protocolInfo.id()));
+ }
+ UnconfiguredPipelineHandler.OutboundConfigurationTask outboundConfigurationTask = UnconfiguredPipelineHandler.setupOutboundProtocol(protocolInfo);
+ BundlerInfo bundlerInfo = protocolInfo.bundlerInfo();
+ if (bundlerInfo != null) {
+ PacketBundleUnpacker packetBundleUnpacker = new PacketBundleUnpacker(bundlerInfo);
+ outboundConfigurationTask = outboundConfigurationTask.andThen(context -> context.pipeline().addAfter("encoder", "unbundler", (ChannelHandler)packetBundleUnpacker));
+ }
+ boolean bl = flag = protocolInfo.id() == ConnectionProtocol.LOGIN;
+ if (!AlternativeJoin) {
+ Connection.syncAfterConfigurationChange(this.channel.writeAndFlush(outboundConfigurationTask.andThen(context -> {
+ this.sendLoginDisconnect = flag;
+ })));
} else {
- UnconfiguredPipelineHandler.OutboundConfigurationTask outboundConfigurationTask = UnconfiguredPipelineHandler.setupOutboundProtocol(protocolInfo);
- BundlerInfo bundlerInfo = protocolInfo.bundlerInfo();
- if (bundlerInfo != null) {
- PacketBundleUnpacker packetBundleUnpacker = new PacketBundleUnpacker(bundlerInfo);
- outboundConfigurationTask = outboundConfigurationTask.andThen(
- context -> context.pipeline().addAfter("encoder", "unbundler", packetBundleUnpacker)
- );
- }
-
- boolean flag = protocolInfo.id() == ConnectionProtocol.LOGIN;
- syncAfterConfigurationChange(this.channel.writeAndFlush(outboundConfigurationTask.andThen(context -> this.sendLoginDisconnect = flag)));
+ this.channel.writeAndFlush(outboundConfigurationTask.andThen(context -> {
+ this.sendLoginDisconnect = flag;
+ }));
}
}

View File

@@ -0,0 +1,20 @@
package org.dreeam.leaf.config.modules.network;
import org.dreeam.leaf.config.ConfigModules;
import org.dreeam.leaf.config.EnumConfigCategory;
public class AlternativeJoin extends ConfigModules {
public String getBasePath() {
return EnumConfigCategory.NETWORK.getBaseKeyName();
}
public static boolean AlternativeJoin = true;
@Override
public void onLoaded() {
AlternativeJoin = config.getBoolean(getBasePath() + ".alternative-join", AlternativeJoin, config.pickStringRegionBased(
"Use alternative login logic to skip synchronization.",
"使用替代登录逻辑以跳过同步。"));
}
}