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 29e24b2f0..be62948cc 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 @@ -103,10 +103,12 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { (ClientPlaySessionHandler) connection.getPlayer().getConnection().getSessionHandler(); if (connection.getMinecraftConnection().getProtocolVersion() <= ProtocolConstants.MINECRAFT_1_12_2) { return message.getChannel().startsWith("MC|") || - playerHandler.getClientPluginMsgChannels().contains(message.getChannel()); + playerHandler.getClientPluginMsgChannels().contains(message.getChannel()) || + VelocityServer.getServer().getChannelRegistrar().registered(message.getChannel()); } else { return message.getChannel().startsWith("minecraft:") || - playerHandler.getClientPluginMsgChannels().contains(message.getChannel()); + playerHandler.getClientPluginMsgChannels().contains(message.getChannel()) || + VelocityServer.getServer().getChannelRegistrar().registered(message.getChannel()); } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 0cce4bfc4..d5f040d2c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -42,6 +42,17 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { this.player = player; } + @Override + public void activated() { + PluginMessage message; + if (player.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) { + message = PluginMessageUtil.constructChannelsPacket("minecraft:register", VelocityServer.getServer().getChannelRegistrar().getModernChannelIds()); + } else { + message = PluginMessageUtil.constructChannelsPacket("REGISTER", VelocityServer.getServer().getChannelRegistrar().getLegacyChannelIds()); + } + player.getConnection().write(message); + } + @Override public void handle(MinecraftPacket packet) { if (packet instanceof KeepAlive) { @@ -174,11 +185,17 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { serverBossBars.clear(); // Tell the server about this client's plugin messages. Velocity will forward them on to the client. - if (!clientPluginMsgChannels.isEmpty()) { + Collection toRegister = new HashSet<>(clientPluginMsgChannels); + if (player.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) { + toRegister.addAll(VelocityServer.getServer().getChannelRegistrar().getModernChannelIds()); + } else { + toRegister.addAll(VelocityServer.getServer().getChannelRegistrar().getLegacyChannelIds()); + } + if (!toRegister.isEmpty()) { String channel = player.getConnection().getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:register" : "REGISTER"; - player.getConnectedServer().getMinecraftConnection().delayedWrite( - PluginMessageUtil.constructChannelsPacket(channel, clientPluginMsgChannels)); + player.getConnectedServer().getMinecraftConnection().delayedWrite(PluginMessageUtil.constructChannelsPacket( + channel, toRegister)); } // Flush everything diff --git a/proxy/src/main/java/com/velocitypowered/proxy/messages/VelocityChannelRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/messages/VelocityChannelRegistrar.java index 03f6bbb56..dff2f5d3e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/messages/VelocityChannelRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/messages/VelocityChannelRegistrar.java @@ -6,8 +6,10 @@ import com.velocitypowered.proxy.protocol.packet.PluginMessage; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; public class VelocityChannelRegistrar implements ChannelRegistrar { private static final Logger logger = LogManager.getLogger(VelocityChannelRegistrar.class); @@ -55,4 +57,22 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { identifierMap.remove(identifier.getId()); } } + + public Collection getLegacyChannelIds() { + return identifierMap.values().stream() + .filter(i -> i instanceof LegacyChannelIdentifier) + .map(ChannelIdentifier::getId) + .collect(Collectors.toList()); + } + + public Collection getModernChannelIds() { + return identifierMap.values().stream() + .filter(i -> i instanceof MinecraftChannelIdentifier) + .map(ChannelIdentifier::getId) + .collect(Collectors.toList()); + } + + public boolean registered(String id) { + return identifierMap.containsKey(id); + } }