Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support plugin message in configuration stage #1096

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern;
import net.kyori.adventure.text.Component;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -188,10 +187,7 @@ public boolean handle(PluginMessage packet) {
PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion(),
serverConn.getPlayer().getProtocolVersion()));
} else {
// TODO: Change this so its usable for mod loaders
serverConn.disconnect();
resultFuture.complete(ConnectionRequestResults.forDisconnect(
Component.translatable("multiplayer.disconnect.missing_tags"), serverConn.getServer()));
serverConn.getPlayer().getConnection().write(packet.retain());
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.velocitypowered.proxy.connection.client;

import com.velocitypowered.api.event.player.PlayerClientBrandEvent;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
Expand All @@ -25,9 +26,11 @@
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
import com.velocitypowered.proxy.protocol.packet.KeepAlive;
import com.velocitypowered.proxy.protocol.packet.PingIdentify;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse;
import com.velocitypowered.proxy.protocol.packet.config.FinishedUpdate;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBuf;
import java.util.concurrent.CompletableFuture;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -105,6 +108,31 @@ public boolean handle(FinishedUpdate packet) {
return true;
}

@Override
public boolean handle(PluginMessage packet) {
VelocityServerConnection serverConn = player.getConnectionInFlight();
if (serverConn != null) {
if (PluginMessageUtil.isMcBrand(packet)) {
String brand = PluginMessageUtil.readBrandMessage(packet.content());
server.getEventManager().fireAndForget(new PlayerClientBrandEvent(player, brand));
player.setClientBrand(brand);
// Client sends `minecraft:brand` packet immediately after Login,
Copy link
Member

Choose a reason for hiding this comment

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

We should probably look into ensuring that this is at least sent somewhere if we can't just send it right now; I need to spend some time looking over this, ideally we should race hard to get the connection to the server into configuration so we can deal with syncing stuff, but, that is probably a wider headache to deal with someday (hopefully soon™)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The client also won't send minecraft:brand when it re-enters the configuration stage after being connected, so I think it is safe to discard this packet.

In the design of Fabric-API, the client will only respond after receiving a packet from the server, so it should not lose any other packets.

// but at this time the backend server may not be ready, just discard it.
} else {
serverConn.ensureConnected().write(packet.retain());
}
}
return true;
}

@Override
public boolean handle(PingIdentify packet) {
if (player.getConnectionInFlight() != null) {
player.getConnectionInFlight().ensureConnected().write(packet);
}
return true;
}

@Override
public void handleGeneric(MinecraftPacket packet) {
VelocityServerConnection serverConnection = player.getConnectedServer();
Expand Down