From a21eaa085a0549b07daf1c8709289734cc9c17ee Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 15 May 2019 18:59:28 -0400 Subject: [PATCH] Do a better job of passing channel (un)registration to the client. Also fixes a regression related to WDLCompanion. --- .../connection/backend/BackendPlaySessionHandler.java | 4 ++++ .../proxy/protocol/packet/PluginMessage.java | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index a2afbae6a..055e5a7d0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -95,8 +95,12 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { // the client. if (PluginMessageUtil.isRegister(packet)) { serverConn.getPlayer().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet)); + serverConn.getPlayer().getMinecraftConnection().write(packet); + return true; } else if (PluginMessageUtil.isUnregister(packet)) { serverConn.getPlayer().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet)); + serverConn.getPlayer().getMinecraftConnection().write(packet); + return true; } if (PluginMessageUtil.isMcBrand(packet)) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java index 6fdd884fd..7c5045568 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java @@ -47,7 +47,7 @@ public class PluginMessage implements MinecraftPacket { @Override public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { this.channel = ProtocolUtils.readString(buf); - if (version.compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { + if (version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) { this.channel = transformLegacyToModernChannel(this.channel); } this.data = new byte[buf.readableBytes()]; @@ -59,8 +59,11 @@ public class PluginMessage implements MinecraftPacket { if (channel == null) { throw new IllegalStateException("Channel is not specified."); } - ProtocolUtils.writeString(buf, version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 - ? channel : transformLegacyToModernChannel(this.channel)); + if (version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) { + ProtocolUtils.writeString(buf, transformLegacyToModernChannel(this.channel)); + } else { + ProtocolUtils.writeString(buf, this.channel); + } buf.writeBytes(data); }