From fd8e7df5bd3669c5b8e24f9012a5e51f56f01efb Mon Sep 17 00:00:00 2001 From: MrNavaStar Date: Sat, 24 Aug 2024 13:57:03 -0600 Subject: [PATCH] internal changes --- .../protoweaver/api/protocol/Protocol.java | 12 ++++----- .../{Furious.java => ObjectSerializer.java} | 27 ++++++++++--------- gradle.properties | 2 +- paper/src/main/resources/plugin.yml | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) rename common/src/main/java/me/mrnavastar/protoweaver/core/util/{Furious.java => ObjectSerializer.java} (54%) diff --git a/common/src/main/java/me/mrnavastar/protoweaver/api/protocol/Protocol.java b/common/src/main/java/me/mrnavastar/protoweaver/api/protocol/Protocol.java index f069c9c..d7c72c1 100644 --- a/common/src/main/java/me/mrnavastar/protoweaver/api/protocol/Protocol.java +++ b/common/src/main/java/me/mrnavastar/protoweaver/api/protocol/Protocol.java @@ -6,9 +6,7 @@ import me.mrnavastar.protoweaver.api.auth.ClientAuthHandler; import me.mrnavastar.protoweaver.api.auth.ServerAuthHandler; import me.mrnavastar.protoweaver.api.netty.ProtoConnection; -import me.mrnavastar.protoweaver.core.util.Furious; -import org.apache.fury.Fury; -import org.apache.fury.ThreadSafeFury; +import me.mrnavastar.protoweaver.core.util.ObjectSerializer; import org.apache.fury.exception.InsecureException; import java.lang.reflect.Modifier; @@ -19,7 +17,7 @@ */ public class Protocol { - private final ThreadSafeFury fury = Fury.builder().withJdkClassSerializableCheck(false).buildThreadSafeFury(); + private final ObjectSerializer serializer = new ObjectSerializer(); @Getter private final String namespace; @Getter private final String name; @@ -87,11 +85,11 @@ public ClientAuthHandler newClientAuthHandler() { } public byte[] serialize(@NonNull Object packet) throws InsecureException { - return Furious.serialize(fury, packet); + return serializer.serialize(packet); } public Object deserialize(byte @NonNull [] packet) throws InsecureException { - return Furious.deserialize(fury, packet); + return serializer.deserialize(packet); } /** @@ -183,7 +181,7 @@ public Builder setClientAuthHandler(Class handler) * @param packet The packet to register. */ public Builder addPacket(@NonNull Class packet) { - Furious.register(protocol.fury, packet); + protocol.serializer.register(packet); protocol.packetHash = 31 * protocol.packetHash + packet.getName().hashCode(); return this; } diff --git a/common/src/main/java/me/mrnavastar/protoweaver/core/util/Furious.java b/common/src/main/java/me/mrnavastar/protoweaver/core/util/ObjectSerializer.java similarity index 54% rename from common/src/main/java/me/mrnavastar/protoweaver/core/util/Furious.java rename to common/src/main/java/me/mrnavastar/protoweaver/core/util/ObjectSerializer.java index 64a99ec..a9afb73 100644 --- a/common/src/main/java/me/mrnavastar/protoweaver/core/util/Furious.java +++ b/common/src/main/java/me/mrnavastar/protoweaver/core/util/ObjectSerializer.java @@ -1,48 +1,51 @@ package me.mrnavastar.protoweaver.core.util; import me.mrnavastar.r.R; -import org.apache.fury.BaseFury; +import org.apache.fury.Fury; +import org.apache.fury.ThreadSafeFury; import org.apache.fury.exception.InsecureException; import org.apache.fury.logging.LoggerFactory; import java.util.ArrayList; import java.util.List; -public class Furious { +public class ObjectSerializer { + + private final ThreadSafeFury fury = Fury.builder().withJdkClassSerializableCheck(false).buildThreadSafeFury(); static { // Make fury be quiet LoggerFactory.disableLogging(); } - private static void recursiveRegister(BaseFury fury, Class type, List> registered) { + private void recursiveRegister(Class type, List> registered) { if (type == null || type == Object.class || registered.contains(type)) return; fury.register(type); registered.add(type); - List.of(type.getDeclaredFields()).forEach(field -> recursiveRegister(fury, field.getType(), registered)); - List.of(R.of(type).generics()).forEach(t -> recursiveRegister(fury, t, registered)); - if (!type.isEnum()) recursiveRegister(fury, type.getSuperclass(), registered); + List.of(type.getDeclaredFields()).forEach(field -> recursiveRegister(field.getType(), registered)); + List.of(R.of(type).generics()).forEach(t -> recursiveRegister(t, registered)); + if (!type.isEnum()) recursiveRegister(type.getSuperclass(), registered); } - public static void register(BaseFury fury, Class type) { - recursiveRegister(fury, type, new ArrayList<>()); + public void register(Class type) { + recursiveRegister(type, new ArrayList<>()); } - public static byte[] serialize(BaseFury fury, Object object) throws InsecureException { + public byte[] serialize(Object object) throws InsecureException { try { return fury.serialize(object); } catch (InsecureException e) { - throw new InsecureException("unregistered packet: " + object.getClass().getName()); + throw new InsecureException("unregistered object: " + object.getClass().getName()); } } - public static Object deserialize(BaseFury fury, byte[] bytes) throws InsecureException { + public Object deserialize(byte[] bytes) throws InsecureException { try { return fury.deserialize(bytes); } catch (InsecureException e) { String packet = e.getMessage().split(" is not registered")[0].replace("class ", ""); - throw new InsecureException("unregistered packet: " + packet); + throw new InsecureException("unregistered object: " + packet); } } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 755ce96..212a4cd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ waterfall_version=1.21-R0.1-SNAPSHOT # Dependencies # https://github.com/apache/fury/releases fury_version=0.7.0 -r_version=1.0.5 +r_version=1.0.6 # should always match the netty version in (latest) minecraft release netty_version=4.1.97.Final # https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk18on diff --git a/paper/src/main/resources/plugin.yml b/paper/src/main/resources/plugin.yml index e1522e6..20c57d2 100644 --- a/paper/src/main/resources/plugin.yml +++ b/paper/src/main/resources/plugin.yml @@ -7,4 +7,4 @@ libraries: - io.netty:netty-codec-http:4.1.97.Final - io.netty:netty-codec-http2:4.1.97.Final - org.bouncycastle:bcpkix-jdk18on:1.78.1 - - me.mrnavastar:r:1.0.5 \ No newline at end of file + - me.mrnavastar:r:1.0.6 \ No newline at end of file