Skip to content

Commit

Permalink
Update Syncmatica Protocol (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jul 22, 2024
1 parent fd5e8be commit d490f0d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
8 changes: 5 additions & 3 deletions patches/server/0007-Leaves-Protocol-Core.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -285,8 +285,10 @@ index 0000000000000000000000000000000000000000..e7ce2e7a1686f1775c0a2e0cd7312940
+ if (!found) {
+ Constructor<? extends LeavesCustomPayload<?>> 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) {
Expand Down
65 changes: 48 additions & 17 deletions patches/server/0055-Syncmatica-Protocol.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<SyncmaticaPayload> {
+
+ 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 @@
Expand All @@ -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();
Expand Down Expand Up @@ -1662,17 +1693,18 @@ 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;
+import net.minecraft.resources.ResourceLocation;
+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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -2012,7 +2043,7 @@ index 0000000000000000000000000000000000000000..9614fce87e2522690aac0af4c04d9fbc
+ final Collection<ServerPlacement> 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();
Expand Down

0 comments on commit d490f0d

Please sign in to comment.