Skip to content

Commit

Permalink
fix backend not receiving brands from 1.20.2 clients (PaperMC#1147)
Browse files Browse the repository at this point in the history
  • Loading branch information
AoElite authored Nov 30, 2023
1 parent 8dcc7ee commit e517671
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.velocitypowered.proxy.protocol.packet.config.FinishedUpdate;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand All @@ -46,6 +48,7 @@ public class ClientConfigSessionHandler implements MinecraftSessionHandler {
private static final Logger logger = LogManager.getLogger(ClientConfigSessionHandler.class);
private final VelocityServer server;
private final ConnectedPlayer player;
private String brandChannel = null;

private CompletableFuture<Void> configSwitchFuture;

Expand Down Expand Up @@ -116,8 +119,9 @@ public boolean handle(PluginMessage packet) {
String brand = PluginMessageUtil.readBrandMessage(packet.content());
server.getEventManager().fireAndForget(new PlayerClientBrandEvent(player, brand));
player.setClientBrand(brand);
brandChannel = packet.getChannel();
// Client sends `minecraft:brand` packet immediately after Login,
// but at this time the backend server may not be ready, just discard it.
// but at this time the backend server may not be ready
} else {
serverConn.ensureConnected().write(packet.retain());
}
Expand Down Expand Up @@ -182,6 +186,14 @@ public void exception(Throwable throwable) {
* @return a future that completes when the config stage is finished
*/
public CompletableFuture<Void> handleBackendFinishUpdate(VelocityServerConnection serverConn) {
String brand = serverConn.getPlayer().getClientBrand();
if (brand != null && brandChannel != null) {
ByteBuf buf = Unpooled.buffer();
buf.writeCharSequence(brand, StandardCharsets.UTF_8);
PluginMessage brandPacket = new PluginMessage(brandChannel, buf);
serverConn.ensureConnected().write(brandPacket);
}

player.getConnection().write(new FinishedUpdate());
serverConn.ensureConnected().write(new FinishedUpdate());
return configSwitchFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ public boolean handle(PluginMessage packet) {
String brand = PluginMessageUtil.readBrandMessage(packet.content());
server.getEventManager().fireAndForget(new PlayerClientBrandEvent(player, brand));
player.setClientBrand(brand);
backendConn.write(
PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion(),
player.getProtocolVersion()));
backendConn.write(packet.retain());
} else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) {
return true;
} else {
Expand Down

0 comments on commit e517671

Please sign in to comment.