From d490f0d021d117a4be040470682349b4b92dd139 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:54:07 +0800 Subject: [PATCH] Update Syncmatica Protocol (#249) --- .../server/0007-Leaves-Protocol-Core.patch | 8 ++- patches/server/0055-Syncmatica-Protocol.patch | 65 ++++++++++++++----- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/patches/server/0007-Leaves-Protocol-Core.patch b/patches/server/0007-Leaves-Protocol-Core.patch index 82bbbf11..36c60412 100644 --- a/patches/server/0007-Leaves-Protocol-Core.patch +++ b/patches/server/0007-Leaves-Protocol-Core.patch @@ -179,10 +179,10 @@ index 0000000000000000000000000000000000000000..986d2a6641ff8017dddf3e5f2655adfc +} diff --git a/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java b/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..e7ce2e7a1686f1775c0a2e0cd731294025d2833b +index 0000000000000000000000000000000000000000..4fd8e06c8d2d3016ccc0baf1c43d77d87ea1dca5 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java -@@ -0,0 +1,384 @@ +@@ -0,0 +1,386 @@ +package org.leavesmc.leaves.protocol.core; + +import net.minecraft.network.FriendlyByteBuf; @@ -285,8 +285,10 @@ index 0000000000000000000000000000000000000000..e7ce2e7a1686f1775c0a2e0cd7312940 + if (!found) { + Constructor> constructor = receiver.payload().getConstructor(PAYLOAD_PARAMETER_TYPES); + if (constructor.isAnnotationPresent(LeavesCustomPayload.New.class)) { -+ map.put(receiver, constructor); + constructor.setAccessible(true); ++ map.put(receiver, constructor); ++ } else { ++ throw new NoSuchMethodException(); + } + } + } catch (NoSuchMethodException exception) { diff --git a/patches/server/0055-Syncmatica-Protocol.patch b/patches/server/0055-Syncmatica-Protocol.patch index f8583ff6..b00ae2b8 100644 --- a/patches/server/0055-Syncmatica-Protocol.patch +++ b/patches/server/0055-Syncmatica-Protocol.patch @@ -28,10 +28,10 @@ index bef88d547aefa9c5b701aa91ffc58114309a7db7..51a1be78de7a794d13b64db6958977e2 if (this.ackBlockChangesUpTo > -1) { diff --git a/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..8c0fd40a89681ef71d9dd2ad63d858e1aad82ceb +index 0000000000000000000000000000000000000000..c452bb80f8a51a11b9d4eca53fc6d977b35ae2ef --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java -@@ -0,0 +1,397 @@ +@@ -0,0 +1,396 @@ +package org.leavesmc.leaves.protocol.syncmatica; + +import com.mojang.authlib.GameProfile; @@ -46,7 +46,6 @@ index 0000000000000000000000000000000000000000..8c0fd40a89681ef71d9dd2ad63d858e1 +import org.jetbrains.annotations.NotNull; +import org.leavesmc.leaves.LeavesConfig; +import org.leavesmc.leaves.protocol.core.LeavesProtocol; -+import org.leavesmc.leaves.protocol.core.LeavesProtocolManager; +import org.leavesmc.leaves.protocol.core.ProtocolHandler; +import org.leavesmc.leaves.protocol.syncmatica.exchange.DownloadExchange; +import org.leavesmc.leaves.protocol.syncmatica.exchange.Exchange; @@ -129,12 +128,12 @@ index 0000000000000000000000000000000000000000..8c0fd40a89681ef71d9dd2ad63d858e1 + playerMap.remove(oldPlayer); + } + -+ @ProtocolHandler.PayloadReceiver(payload = LeavesProtocolManager.LeavesPayload.class, ignoreId = true) -+ public static void onPacketGet(ServerPlayer player, LeavesProtocolManager.LeavesPayload payload) { ++ @ProtocolHandler.PayloadReceiver(payload = SyncmaticaPayload.class, payloadId = "main") ++ public static void onPacketGet(ServerPlayer player, SyncmaticaPayload payload) { + if (!LeavesConfig.syncmaticaProtocol) { + return; + } -+ onPacket(player.connection.exchangeTarget, payload.id(), payload.data()); ++ onPacket(player.connection.exchangeTarget, payload.packetType(), payload.data()); + } + + public static void onPacket(final @NotNull ExchangeTarget source, final ResourceLocation id, final FriendlyByteBuf packetBuf) { @@ -1302,9 +1301,41 @@ index 0000000000000000000000000000000000000000..27a056b306daa91400946a30e68ce01d + } + } +} +diff --git a/src/main/java/org/leavesmc/leaves/protocol/syncmatica/SyncmaticaPayload.java b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/SyncmaticaPayload.java +new file mode 100644 +index 0000000000000000000000000000000000000000..d7a3c85df0f5950f3f0c69c33fa5d809f69de4de +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/SyncmaticaPayload.java +@@ -0,0 +1,26 @@ ++package org.leavesmc.leaves.protocol.syncmatica; ++ ++import net.minecraft.network.FriendlyByteBuf; ++import net.minecraft.resources.ResourceLocation; ++import org.leavesmc.leaves.protocol.core.LeavesCustomPayload; ++ ++public record SyncmaticaPayload(ResourceLocation packetType, FriendlyByteBuf data) implements LeavesCustomPayload { ++ ++ private static final ResourceLocation NETWORK_ID = new ResourceLocation(SyncmaticaProtocol.PROTOCOL_ID, "main"); ++ ++ @New ++ public static SyncmaticaPayload decode(ResourceLocation location, FriendlyByteBuf buf) { ++ return new SyncmaticaPayload(buf.readResourceLocation(), new FriendlyByteBuf(buf.readBytes(buf.readableBytes()))); ++ } ++ ++ @Override ++ public void write(FriendlyByteBuf buf) { ++ buf.writeResourceLocation(this.packetType); ++ buf.writeBytes(this.data.readBytes(this.data.readableBytes())); ++ } ++ ++ @Override ++ public ResourceLocation id() { ++ return NETWORK_ID; ++ } ++} diff --git a/src/main/java/org/leavesmc/leaves/protocol/syncmatica/SyncmaticaProtocol.java b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/SyncmaticaProtocol.java new file mode 100644 -index 0000000000000000000000000000000000000000..d91c913a283cef1f152c23653d48a85c42f9655b +index 0000000000000000000000000000000000000000..d0ceb4079680c0eaef362ab3fddce60ff5b839a3 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/SyncmaticaProtocol.java @@ -0,0 +1,123 @@ @@ -1326,7 +1357,7 @@ index 0000000000000000000000000000000000000000..d91c913a283cef1f152c23653d48a85c +public class SyncmaticaProtocol { + + public static final String PROTOCOL_ID = "syncmatica"; -+ public static final String PROTOCOL_VERSION = "leaves-syncmatica-1.0.0"; ++ public static final String PROTOCOL_VERSION = "leaves-syncmatica-1.1.0"; + + private static final File litematicFolder = new File("." + File.separator + "syncmatics"); + private static final PlayerIdentifierProvider playerIdentifierProvider = new PlayerIdentifierProvider(); @@ -1662,10 +1693,10 @@ index 0000000000000000000000000000000000000000..0f45ef7f4abcd7cff627e5a3df2a9fca +} diff --git a/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/ExchangeTarget.java b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/ExchangeTarget.java new file mode 100644 -index 0000000000000000000000000000000000000000..1ce637d91f12f8fdd54fce38534861836b6a93ca +index 0000000000000000000000000000000000000000..b0da7abf0748d4bdb3141c28f201906157a0eaad --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/ExchangeTarget.java -@@ -0,0 +1,40 @@ +@@ -0,0 +1,39 @@ +package org.leavesmc.leaves.protocol.syncmatica.exchange; + +import net.minecraft.network.FriendlyByteBuf; @@ -1673,6 +1704,7 @@ index 0000000000000000000000000000000000000000..1ce637d91f12f8fdd54fce3853486183 +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import org.leavesmc.leaves.protocol.core.ProtocolUtils; +import org.leavesmc.leaves.protocol.syncmatica.FeatureSet; ++import org.leavesmc.leaves.protocol.syncmatica.SyncmaticaPayload; + +import java.util.ArrayList; +import java.util.Collection; @@ -1689,9 +1721,7 @@ index 0000000000000000000000000000000000000000..1ce637d91f12f8fdd54fce3853486183 + } + + public void sendPacket(final ResourceLocation id, final FriendlyByteBuf packetBuf) { -+ ProtocolUtils.sendPayloadPacket(client.player, id, buf -> { -+ buf.writeBytes(packetBuf); -+ }); ++ ProtocolUtils.sendPayloadPacket(client.player, new SyncmaticaPayload(id, packetBuf)); + } + + public FeatureSet getFeatureSet() { @@ -1956,16 +1986,17 @@ index 0000000000000000000000000000000000000000..065a39942603f7b884cca40d8d7b4b47 +} diff --git a/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/VersionHandshakeServer.java b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/VersionHandshakeServer.java new file mode 100644 -index 0000000000000000000000000000000000000000..9614fce87e2522690aac0af4c04d9fbcb72167af +index 0000000000000000000000000000000000000000..cb7aed6c0aa31cd46c071da7b483c63e755a6bff --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/VersionHandshakeServer.java -@@ -0,0 +1,65 @@ +@@ -0,0 +1,66 @@ +package org.leavesmc.leaves.protocol.syncmatica.exchange; + +import io.netty.buffer.Unpooled; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; ++import org.leavesmc.leaves.protocol.syncmatica.CommunicationManager; +import org.leavesmc.leaves.protocol.syncmatica.FeatureSet; +import org.leavesmc.leaves.protocol.syncmatica.PacketType; +import org.leavesmc.leaves.protocol.syncmatica.ServerPlacement; @@ -1988,7 +2019,7 @@ index 0000000000000000000000000000000000000000..9614fce87e2522690aac0af4c04d9fbc + @Override + public void handle(final @NotNull ResourceLocation id, final FriendlyByteBuf packetBuf) { + if (id.equals(PacketType.REGISTER_VERSION.identifier)) { -+ String partnerVersion = packetBuf.readUtf(32767); ++ String partnerVersion = packetBuf.readUtf(); + if (partnerVersion.equals("0.0.1")) { + close(false); + return; @@ -2012,7 +2043,7 @@ index 0000000000000000000000000000000000000000..9614fce87e2522690aac0af4c04d9fbc + final Collection l = SyncmaticaProtocol.getSyncmaticManager().getAll(); + newBuf.writeInt(l.size()); + for (final ServerPlacement p : l) { -+ getManager().putMetaData(p, newBuf, getPartner()); ++ CommunicationManager.putMetaData(p, newBuf, getPartner()); + } + getPartner().sendPacket(PacketType.CONFIRM_USER.identifier, newBuf); + succeed();