From 10fc8f846d8a3a24b4961a41953ed60c5bf12cb5 Mon Sep 17 00:00:00 2001 From: Myles Date: Thu, 29 Sep 2016 21:29:58 +0100 Subject: [PATCH] Fix PacketWrapper sending and implement Movement Transmitter for Bungee --- .../bukkit/platform/BukkitViaInjector.java | 5 +++ .../bungee/platform/BungeeConfigAPI.java | 2 +- .../bungee/platform/BungeeViaInjector.java | 5 +++ .../bungee/platform/BungeeViaLoader.java | 5 ++- .../providers/BungeeMovementTransmitter.java | 34 +++++++++++++++++++ .../myles/ViaVersion/api/PacketWrapper.java | 7 ++-- .../ViaVersion/api/platform/ViaInjector.java | 7 ++++ .../myles/ViaVersion/util/PipelineUtil.java | 1 + .../sponge/platform/SpongeViaInjector.java | 5 +++ 9 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMovementTransmitter.java diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java index ea10015d2..7eccdaf93 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java @@ -178,6 +178,11 @@ public class BukkitViaInjector implements ViaInjector { return "encoder"; } + @Override + public String getDecoderName() { + return "decoder"; + } + public static Object getServerConnection() throws Exception { Class serverClazz = NMSUtil.nms("MinecraftServer"); Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer"); diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java index cc4e784e6..9b1cdadb7 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java @@ -116,7 +116,7 @@ public class BungeeConfigAPI implements ViaVersionConfig, ConfigurationProvider @Override public boolean isStimulatePlayerTick() { - return false; + return true; } @Override diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaInjector.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaInjector.java index ef1b2719f..948247652 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaInjector.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaInjector.java @@ -50,4 +50,9 @@ public class BungeeViaInjector implements ViaInjector { public String getEncoderName() { return "via-encoder"; } + + @Override + public String getDecoderName() { + return "via-decoder"; + } } diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java index 343e16fdc..18dd21080 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java @@ -1,6 +1,9 @@ package us.myles.ViaVersion.bungee.platform; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.platform.ViaPlatformLoader; +import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; public class BungeeViaLoader implements ViaPlatformLoader { @Override @@ -8,6 +11,6 @@ public class BungeeViaLoader implements ViaPlatformLoader { // TODO: Movement Transmitter // TODO: Config // TODO: Platform specific commands - // TODO: Get rid of bungeecord-proxy just use reflection + Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter()); } } diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMovementTransmitter.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMovementTransmitter.java new file mode 100644 index 000000000..7f1d37206 --- /dev/null +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeMovementTransmitter.java @@ -0,0 +1,34 @@ +package us.myles.ViaVersion.bungee.providers; + +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; + +public class BungeeMovementTransmitter extends MovementTransmitterProvider { + @Override + public Object getFlyingPacket() { + return null; + } + + @Override + public Object getGroundPacket() { + return null; + } + + public void sendPlayer(UserConnection userConnection) { + if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) { + PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); + wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); + try { + wrapper.sendToServer(); + } catch (Exception e) { + e.printStackTrace(); + } + // PlayerPackets will increment idle + } + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 7c3441825..de15e497e 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -455,19 +455,16 @@ public class PacketWrapper { /** * Send the current packet to the server. - * (Ensure the ID is suitable for the server version) + * (Ensure the ID is suitable for viaversion) * * @throws Exception If it failed to write */ public void sendToServer() throws Exception { - // TODO: Fix for bungee if (!isCancelled()) { ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer(); - Type.VAR_INT.write(output, PacketWrapper.PASSTHROUGH_ID); // Pass through - writeToBuffer(output); - PipelineUtil.getContextBefore("decompress", user().getChannel().pipeline()).fireChannelRead(output); + user().getChannel().pipeline().context(Via.getManager().getInjector().getDecoderName()).fireChannelRead(output); } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaInjector.java b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaInjector.java index 86a0c3af8..14f853a2b 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaInjector.java +++ b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaInjector.java @@ -29,4 +29,11 @@ public interface ViaInjector { * @return The name */ String getEncoderName(); + + /** + * Get the name of the decoder for then netty pipeline for this platform. + * + * @return The name + */ + String getDecoderName(); } diff --git a/common/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java b/common/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java index 05b92e9d5..fca66ada5 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java +++ b/common/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java @@ -95,6 +95,7 @@ public class PipelineUtil { boolean mark = false; for (String s : pipeline.names()) { if (mark) { + System.out.println("Context before: " + s); return pipeline.context(pipeline.get(s)); } if (s.equalsIgnoreCase(name)) diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaInjector.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaInjector.java index 17301cb22..3e7a5545a 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaInjector.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaInjector.java @@ -137,6 +137,11 @@ public class SpongeViaInjector implements ViaInjector { return "encoder"; } + @Override + public String getDecoderName() { + return "decoder"; + } + public static Object getServerConnection() throws Exception { Class serverClazz = Class.forName("net.minecraft.server.MinecraftServer"); Object server = getServer();