Skip to content

Commit

Permalink
Do not track plugin channels registered per-player on the proxy (#591)
Browse files Browse the repository at this point in the history
We don't need to track this information since Velocity uses the JoinGame packet, which is about as good of a server rejoin mechanism we're likely to get in vanilla Minecraft.
  • Loading branch information
astei authored Aug 18, 2023
1 parent 2aaf702 commit f62d759
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,8 @@ public boolean handle(PluginMessage 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)) {
serverConn.getPlayer().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
return false;
} else if (PluginMessageUtil.isUnregister(packet)) {
serverConn.getPlayer().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
// Register and unregister packets are simply forwarded to the server as-is.
if (PluginMessageUtil.isRegister(packet) || PluginMessageUtil.isUnregister(packet)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.velocitypowered.proxy.protocol.packet.JoinGame;
import com.velocitypowered.proxy.protocol.packet.KeepAlive;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -180,12 +179,6 @@ public boolean handle(PluginMessage packet) {
return true;
}

if (PluginMessageUtil.isRegister(packet)) {
serverConn.getPlayer().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
} else if (PluginMessageUtil.isUnregister(packet)) {
serverConn.getPlayer().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
}

// We always need to handle plugin messages, for Forge compatibility.
if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) {
// Handled, but check the server connection phase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public void activated() {
if (!channels.isEmpty()) {
PluginMessage register = constructChannelsPacket(player.getProtocolVersion(), channels);
player.getConnection().write(register);
player.getKnownChannels().addAll(channels);
}
}

Expand Down Expand Up @@ -295,7 +294,6 @@ public boolean handle(PluginMessage packet) {
packet.getChannel());
} else if (PluginMessageUtil.isRegister(packet)) {
List<String> channels = PluginMessageUtil.getChannels(packet);
player.getKnownChannels().addAll(channels);
List<ChannelIdentifier> channelIdentifiers = new ArrayList<>();
for (String channel : channels) {
try {
Expand All @@ -309,7 +307,6 @@ public boolean handle(PluginMessage packet) {
new PlayerChannelRegisterEvent(player, ImmutableList.copyOf(channelIdentifiers)));
backendConn.write(packet.retain());
} else if (PluginMessageUtil.isUnregister(packet)) {
player.getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
backendConn.write(packet.retain());
} else if (PluginMessageUtil.isMcBrand(packet)) {
String brand = PluginMessageUtil.readBrandMessage(packet.content());
Expand Down Expand Up @@ -485,12 +482,6 @@ public void handleBackendJoinGame(JoinGame joinGame, VelocityServerConnection de
}
serverBossBars.clear();

// Tell the server about this client's plugin message channels.
ProtocolVersion serverVersion = serverMc.getProtocolVersion();
if (!player.getKnownChannels().isEmpty()) {
serverMc.delayedWrite(constructChannelsPacket(serverVersion, player.getKnownChannels()));
}

// If we had plugin messages queued during login/FML handshake, send them now.
PluginMessage pm;
while ((pm = loginPluginMessages.poll()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@
import com.velocitypowered.proxy.tablist.VelocityTabListLegacy;
import com.velocitypowered.proxy.util.ClosestLocaleMatcher;
import com.velocitypowered.proxy.util.DurationUtils;
import com.velocitypowered.proxy.util.collect.CappedSet;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import java.net.InetSocketAddress;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -155,7 +153,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
private final InternalTabList tabList;
private final VelocityServer server;
private ClientConnectionPhase connectionPhase;
private final Collection<String> knownChannels;
private final CompletableFuture<Void> teardownFuture = new CompletableFuture<>();
private @MonotonicNonNull List<String> serversToTry = null;
private @MonotonicNonNull Boolean previousResourceResponse;
Expand Down Expand Up @@ -185,7 +182,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
this.virtualHost = virtualHost;
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
this.connectionPhase = connection.getType().getInitialClientPhase();
this.knownChannels = CappedSet.create(MAX_PLUGIN_CHANNELS);
this.onlineMode = onlineMode;

if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) {
Expand Down Expand Up @@ -1103,15 +1099,6 @@ public void setPhase(ClientConnectionPhase connectionPhase) {
this.connectionPhase = connectionPhase;
}

/**
* Return all the plugin message channels "known" to the client.
*
* @return the channels
*/
public Collection<String> getKnownChannels() {
return knownChannels;
}

@Override
public @Nullable IdentifiedKey getIdentifiedKey() {
return playerKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -55,15 +54,7 @@ public boolean handle(PluginMessage packet) {
return true;
}

if (PluginMessageUtil.isRegister(packet)) {
player.getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
serverConn.ensureConnected().write(packet.retain());
return true;
} else if (PluginMessageUtil.isUnregister(packet)) {
player.getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
serverConn.ensureConnected().write(packet.retain());
return true;
} else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) {
if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) {
return true;
}

Expand Down

This file was deleted.

This file was deleted.

1 comment on commit f62d759

@AoElite
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Please sign in to comment.