From 643cf0b4ca242e9c1b323d99cec04a04d513b458 Mon Sep 17 00:00:00 2001
From: RaphiMC <50594595+RaphiMC@users.noreply.github.com>
Date: Sun, 2 Apr 2023 21:21:50 +0200
Subject: [PATCH] Implemented abstracted netty pipeline
---
README.md | 8 +-
build.gradle | 18 +++-
.../platform/ViaAprilFoolsPlatformImpl.java | 46 +++++++++
.../impl/platform/ViaBedrockPlatformImpl.java | 46 +++++++++
.../VPHMovementTransmitterProvider.java | 7 +-
.../impl/viaversion/VPHInjector.java | 4 +-
.../netty/CompressionReorderEvent.java | 27 +++++
.../netty/VPHDecodeHandler.java | 61 ------------
.../netty/VPHEncodeHandler.java | 61 ------------
.../viaprotocolhack/netty/VPHPipeline.java | 98 ++++++++++++++++++-
.../viaprotocolhack/netty/ViaCodec.java | 96 ++++++++++++++++++
.../netty/viabedrock/DisconnectHandler.java | 38 +++++++
.../viabedrock/PingEncapsulationCodec.java | 64 ++++++++++++
.../RakMessageEncapsulationCodec.java | 61 ++++++++++++
14 files changed, 497 insertions(+), 138 deletions(-)
create mode 100644 src/main/java/net/raphimc/viaprotocolhack/impl/platform/ViaAprilFoolsPlatformImpl.java
create mode 100644 src/main/java/net/raphimc/viaprotocolhack/impl/platform/ViaBedrockPlatformImpl.java
create mode 100644 src/main/java/net/raphimc/viaprotocolhack/netty/CompressionReorderEvent.java
delete mode 100644 src/main/java/net/raphimc/viaprotocolhack/netty/VPHDecodeHandler.java
delete mode 100644 src/main/java/net/raphimc/viaprotocolhack/netty/VPHEncodeHandler.java
create mode 100644 src/main/java/net/raphimc/viaprotocolhack/netty/ViaCodec.java
create mode 100644 src/main/java/net/raphimc/viaprotocolhack/netty/viabedrock/DisconnectHandler.java
create mode 100644 src/main/java/net/raphimc/viaprotocolhack/netty/viabedrock/PingEncapsulationCodec.java
create mode 100644 src/main/java/net/raphimc/viaprotocolhack/netty/viabedrock/RakMessageEncapsulationCodec.java
diff --git a/README.md b/README.md
index 174e91c..b1ee507 100644
--- a/README.md
+++ b/README.md
@@ -36,14 +36,14 @@ To include ViaLegacy and ViaAprilFools, you can look at their READMEs: [ViaLegac
Here is an example dependency configuration for all components:
```groovy
-implementation "com.viaversion:viaversion:4.7.0-23w12a-SNAPSHOT"
-implementation("com.viaversion:viabackwards-common:4.7.0-23w12a-SNAPSHOT") {
+implementation "com.viaversion:viaversion:4.7.0-23w13a-SNAPSHOT"
+implementation("com.viaversion:viabackwards-common:4.7.0-23w13a-SNAPSHOT") {
exclude group: "com.viaversion", module: "viaversion" // Exclude transitive dependency. Include manually for more control
exclude group: "io.netty", module: "netty-all" // Don't include the outdated netty version
}
implementation "com.viaversion:viarewind-core:2.0.4-SNAPSHOT"
-implementation "net.raphimc:ViaLegacy:2.2.9"
-implementation "net.raphimc:ViaAprilFools:2.0.5"
+implementation "net.raphimc:ViaLegacy:2.2.11"
+implementation "net.raphimc:ViaAprilFools:2.0.6"
```
## Implementation
diff --git a/build.gradle b/build.gradle
index 684f59b..b6d4884 100644
--- a/build.gradle
+++ b/build.gradle
@@ -17,6 +17,18 @@ repositories {
name = "Lenni0451"
url "https://maven.lenni0451.net/releases"
}
+ maven {
+ name = "Lenni0451 Snapshots"
+ url "https://maven.lenni0451.net/snapshots"
+ }
+ maven {
+ name = "OpenCollab Releases"
+ url = "https://repo.opencollab.dev/maven-releases/"
+ }
+ maven {
+ name = "OpenCollab Snapshots"
+ url = "https://repo.opencollab.dev/maven-snapshots/"
+ }
maven {
name = "ViaVersion"
url "https://repo.viaversion.com"
@@ -27,9 +39,13 @@ dependencies {
compileOnly "com.viaversion:viaversion:4.7.0-23w12a-SNAPSHOT"
compileOnly("com.viaversion:viabackwards-common:4.7.0-23w12a-SNAPSHOT") {
exclude group: "com.viaversion", module: "viaversion"
+ exclude group: "io.netty", module: "netty-all"
}
compileOnly "com.viaversion:viarewind-core:2.0.4-SNAPSHOT"
- compileOnly "net.raphimc:ViaLegacy:2.2.6"
+ compileOnly "net.raphimc:ViaLegacy:2.2.11"
+ compileOnly "net.raphimc:ViaAprilFools:2.0.6"
+ compileOnly "net.raphimc:ViaBedrock:0.0.1-SNAPSHOT"
+ compileOnly "org.cloudburstmc.netty:netty-transport-raknet:1.0.0.CR1-SNAPSHOT"
api "org.slf4j:slf4j-api:2.0.7"
api "org.yaml:snakeyaml:2.0"
diff --git a/src/main/java/net/raphimc/viaprotocolhack/impl/platform/ViaAprilFoolsPlatformImpl.java b/src/main/java/net/raphimc/viaprotocolhack/impl/platform/ViaAprilFoolsPlatformImpl.java
new file mode 100644
index 0000000..dde85df
--- /dev/null
+++ b/src/main/java/net/raphimc/viaprotocolhack/impl/platform/ViaAprilFoolsPlatformImpl.java
@@ -0,0 +1,46 @@
+/*
+ * This file is part of ViaProtocolHack - https://github.com/RaphiMC/ViaProtocolHack
+ * Copyright (C) 2023 RK_01/RaphiMC and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.raphimc.viaprotocolhack.impl.platform;
+
+import com.viaversion.viaversion.api.Via;
+import net.raphimc.viaaprilfools.platform.ViaAprilFoolsPlatform;
+import net.raphimc.viaprotocolhack.util.JLoggerToSLF4J;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.util.logging.Logger;
+
+public class ViaAprilFoolsPlatformImpl implements ViaAprilFoolsPlatform {
+
+ private static final Logger LOGGER = new JLoggerToSLF4J(LoggerFactory.getLogger("ViaAprilFools"));
+
+ public ViaAprilFoolsPlatformImpl() {
+ this.init(this.getDataFolder());
+ }
+
+ @Override
+ public Logger getLogger() {
+ return LOGGER;
+ }
+
+ @Override
+ public File getDataFolder() {
+ return Via.getPlatform().getDataFolder();
+ }
+
+}
diff --git a/src/main/java/net/raphimc/viaprotocolhack/impl/platform/ViaBedrockPlatformImpl.java b/src/main/java/net/raphimc/viaprotocolhack/impl/platform/ViaBedrockPlatformImpl.java
new file mode 100644
index 0000000..f1dae18
--- /dev/null
+++ b/src/main/java/net/raphimc/viaprotocolhack/impl/platform/ViaBedrockPlatformImpl.java
@@ -0,0 +1,46 @@
+/*
+ * This file is part of ViaProtocolHack - https://github.com/RaphiMC/ViaProtocolHack
+ * Copyright (C) 2023 RK_01/RaphiMC and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.raphimc.viaprotocolhack.impl.platform;
+
+import com.viaversion.viaversion.api.Via;
+import net.raphimc.viabedrock.platform.ViaBedrockPlatform;
+import net.raphimc.viaprotocolhack.util.JLoggerToSLF4J;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.util.logging.Logger;
+
+public class ViaBedrockPlatformImpl implements ViaBedrockPlatform {
+
+ private static final Logger LOGGER = new JLoggerToSLF4J(LoggerFactory.getLogger("ViaBedrock"));
+
+ public ViaBedrockPlatformImpl() {
+ this.init(this.getDataFolder());
+ }
+
+ @Override
+ public Logger getLogger() {
+ return LOGGER;
+ }
+
+ @Override
+ public File getDataFolder() {
+ return Via.getPlatform().getDataFolder();
+ }
+
+}
diff --git a/src/main/java/net/raphimc/viaprotocolhack/impl/providers/VPHMovementTransmitterProvider.java b/src/main/java/net/raphimc/viaprotocolhack/impl/providers/VPHMovementTransmitterProvider.java
index 7fe21c5..b4a05e6 100644
--- a/src/main/java/net/raphimc/viaprotocolhack/impl/providers/VPHMovementTransmitterProvider.java
+++ b/src/main/java/net/raphimc/viaprotocolhack/impl/providers/VPHMovementTransmitterProvider.java
@@ -46,12 +46,11 @@ public class VPHMovementTransmitterProvider extends MovementTransmitterProvider
final MovementTracker tracker = userConnection.get(MovementTracker.class);
tracker.incrementIdlePacket();
- final PacketWrapper wrapper = PacketWrapper.create(ServerboundPackets1_8.PLAYER_MOVEMENT, userConnection);
- wrapper.write(Type.BOOLEAN, tracker.isGround());
-
userConnection.getChannel().eventLoop().submit(() -> {
try {
- wrapper.sendToServer(Protocol1_9To1_8.class);
+ final PacketWrapper playerMovement = PacketWrapper.create(ServerboundPackets1_8.PLAYER_MOVEMENT, userConnection);
+ playerMovement.write(Type.BOOLEAN, tracker.isGround());
+ playerMovement.sendToServer(Protocol1_9To1_8.class);
} catch (Throwable ignored) {
}
});
diff --git a/src/main/java/net/raphimc/viaprotocolhack/impl/viaversion/VPHInjector.java b/src/main/java/net/raphimc/viaprotocolhack/impl/viaversion/VPHInjector.java
index 3773ceb..66f7281 100644
--- a/src/main/java/net/raphimc/viaprotocolhack/impl/viaversion/VPHInjector.java
+++ b/src/main/java/net/raphimc/viaprotocolhack/impl/viaversion/VPHInjector.java
@@ -50,12 +50,12 @@ public class VPHInjector implements ViaInjector {
@Override
public String getEncoderName() {
- return VPHPipeline.ENCODER_HANDLER_NAME;
+ return VPHPipeline.VIA_CODEC_NAME;
}
@Override
public String getDecoderName() {
- return VPHPipeline.DECODER_HANDLER_NAME;
+ return VPHPipeline.VIA_CODEC_NAME;
}
@Override
diff --git a/src/main/java/net/raphimc/viaprotocolhack/netty/CompressionReorderEvent.java b/src/main/java/net/raphimc/viaprotocolhack/netty/CompressionReorderEvent.java
new file mode 100644
index 0000000..1923d47
--- /dev/null
+++ b/src/main/java/net/raphimc/viaprotocolhack/netty/CompressionReorderEvent.java
@@ -0,0 +1,27 @@
+/*
+ * This file is part of ViaProtocolHack - https://github.com/RaphiMC/ViaProtocolHack
+ * Copyright (C) 2023 RK_01/RaphiMC and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.raphimc.viaprotocolhack.netty;
+
+public class CompressionReorderEvent {
+
+ public static final CompressionReorderEvent INSTANCE = new CompressionReorderEvent();
+
+ private CompressionReorderEvent() {
+ }
+
+}
diff --git a/src/main/java/net/raphimc/viaprotocolhack/netty/VPHDecodeHandler.java b/src/main/java/net/raphimc/viaprotocolhack/netty/VPHDecodeHandler.java
deleted file mode 100644
index cd5ca13..0000000
--- a/src/main/java/net/raphimc/viaprotocolhack/netty/VPHDecodeHandler.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * This file is part of ViaProtocolHack - https://github.com/RaphiMC/ViaProtocolHack
- * Copyright (C) 2023 RK_01/RaphiMC and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package net.raphimc.viaprotocolhack.netty;
-
-import com.viaversion.viaversion.api.connection.UserConnection;
-import com.viaversion.viaversion.exception.CancelCodecException;
-import com.viaversion.viaversion.exception.CancelDecoderException;
-import com.viaversion.viaversion.util.PipelineUtil;
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.MessageToMessageDecoder;
-
-import java.util.List;
-
-public class VPHDecodeHandler extends MessageToMessageDecoder {
-
- protected final UserConnection user;
-
- public VPHDecodeHandler(final UserConnection user) {
- this.user = user;
- }
-
- @Override
- protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List