From b0da4b60c79b3c42b0a7f59dde2076ebdb78535e Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 12 Jun 2021 10:30:46 -0400 Subject: [PATCH] Do not check if a plugin message channel is registered before forwarding it This fixes issues with Servux and probably a crap ton of other bad mods. Purity on this front serves no real purpose than to say we're pedantic. A future commit may remove all tracking of registered channels altogether. There's strong evidence (back to Minecraft 1.8, at least) that we don't have to track this data and only need to send channels for plugin message channels registered by Velocity itself. This will likely involve more testing to see if this uncovers client bugs with older versions of the game. --- .../backend/BackendPlaySessionHandler.java | 5 ---- .../backend/TransitionSessionHandler.java | 5 ---- .../connection/client/ConnectedPlayer.java | 27 ------------------- .../protocol/util/PluginMessageUtil.java | 21 --------------- 4 files changed, 58 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 eaa81709f..557b78844 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 @@ -157,11 +157,6 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { return true; } - if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected() - .getProtocolVersion(), packet)) { - return true; - } - // We need to specially handle REGISTER and UNREGISTER packets. Later on, we'll write them to // the client. if (PluginMessageUtil.isRegister(packet)) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java index 3ba2fd217..356825841 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java @@ -168,11 +168,6 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(PluginMessage packet) { - if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected() - .getProtocolVersion(), packet)) { - return true; - } - if (PluginMessageUtil.isRegister(packet)) { serverConn.getPlayer().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet)); } else if (PluginMessageUtil.isUnregister(packet)) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 0360bc255..2839b0278 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -52,7 +52,6 @@ import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; -import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants; import com.velocitypowered.proxy.connection.player.VelocityResourcePackInfo; import com.velocitypowered.proxy.connection.util.ConnectionMessages; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; @@ -66,7 +65,6 @@ import com.velocitypowered.proxy.protocol.packet.KeepAlive; import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest; import com.velocitypowered.proxy.protocol.packet.title.GenericTitlePacket; -import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.tablist.VelocityTabList; import com.velocitypowered.proxy.tablist.VelocityTabListLegacy; @@ -928,31 +926,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return knownChannels; } - /** - * Determines whether or not we can forward a plugin message onto the client. - * @param version the Minecraft protocol version - * @param message the plugin message to forward to the client - * @return {@code true} if the message can be forwarded, {@code false} otherwise - */ - public boolean canForwardPluginMessage(ProtocolVersion version, PluginMessage message) { - boolean minecraftOrFmlMessage; - - // By default, all internal Minecraft and Forge channels are forwarded from the server. - if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) <= 0) { - String channel = message.getChannel(); - minecraftOrFmlMessage = channel.startsWith("MC|") - || channel.startsWith(LegacyForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL) - || PluginMessageUtil.isLegacyRegister(message) - || PluginMessageUtil.isLegacyUnregister(message); - } else { - minecraftOrFmlMessage = message.getChannel().startsWith("minecraft:"); - } - - // Otherwise, we need to see if the player already knows this channel or it's known by the - // proxy. - return minecraftOrFmlMessage || knownChannels.contains(message.getChannel()); - } - private class IdentityImpl implements Identity { @Override public @NonNull UUID uuid() { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java index 5e30c1352..bad56a843 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java @@ -79,27 +79,6 @@ public final class PluginMessageUtil { .equals(UNREGISTER_CHANNEL); } - /** - * Determines whether or not this plugin message is a legacy (<1.13) registration plugin message. - * @param message the plugin message - * @return whether this is a legacy register message - */ - public static boolean isLegacyRegister(PluginMessage message) { - checkNotNull(message, "message"); - return message.getChannel().equals(REGISTER_CHANNEL_LEGACY); - } - - /** - * Determines whether or not this plugin message is a legacy (<1.13) unregistration plugin - * message. - * @param message the plugin message - * @return whether this is a legacy unregister message - */ - public static boolean isLegacyUnregister(PluginMessage message) { - checkNotNull(message, "message"); - return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY); - } - /** * Fetches all the channels in a register or unregister plugin message. * @param message the message to get the channels from