3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Add support for retrieving the Player's client brand

Dieser Commit ist enthalten in:
Artuto 2021-06-11 23:44:51 -05:00
Ursprung 793ad443c6
Commit c8d50f3fdd
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 724D7A87AA4A082D
4 geänderte Dateien mit 27 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -275,4 +275,11 @@ public interface Player extends CommandSource, Identified, InboundConnection,
*/
@Override
boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data);
/**
* Gets the player's client brand.
*
* @return the player's client brand
*/
Optional<String> getClientBrand();
}

Datei anzeigen

@ -230,6 +230,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
player.getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
backendConn.write(packet.retain());
} else if (PluginMessageUtil.isMcBrand(packet)) {
player.setClientBrand(PluginMessageUtil.readBrandMessage(packet.content()));
backendConn.write(PluginMessageUtil
.rewriteMinecraftBrand(packet, server.getVersion(), player.getProtocolVersion()));
} else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) {

Datei anzeigen

@ -142,6 +142,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
private final Queue<ResourcePackInfo> outstandingResourcePacks = new ArrayDeque<>();
private @Nullable ResourcePackInfo pendingResourcePack;
private @Nullable ResourcePackInfo appliedResourcePack;
private @Nullable String clientBrand;
ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection,
@Nullable InetSocketAddress virtualHost, boolean onlineMode) {
@ -871,6 +872,15 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return true;
}
@Override
public Optional<String> getClientBrand() {
return Optional.ofNullable(clientBrand);
}
void setClientBrand(String clientBrand) {
this.clientBrand = clientBrand;
}
@Override
public void spoofChatInput(String input) {
Preconditions.checkArgument(input.length() <= Chat.MAX_SERVERBOUND_MESSAGE_LENGTH,

Datei anzeigen

@ -160,11 +160,15 @@ public final class PluginMessageUtil {
return new PluginMessage(message.getChannel(), rewrittenBuf);
}
private static String readBrandMessage(ByteBuf content) {
// Some clients (mostly poorly-implemented bots) do not send validly-formed brand messages.
// In order to accommodate their broken behavior, we'll first try to read in the 1.8 format, and
// if that fails, treat it as a 1.7-format message (which has no prefixed length). (The message
// Velocity sends will be in the correct format depending on the protocol.)
/**
* Some clients (mostly poorly-implemented bots) do not send validly-formed brand messages.
* In order to accommodate their broken behavior, we'll first try to read in the 1.8 format, and
* if that fails, treat it as a 1.7-format message (which has no prefixed length). (The message
* Velocity sends will be in the correct format depending on the protocol.)
* @param content the brand packet
* @return the client brand
*/
public static String readBrandMessage(ByteBuf content) {
try {
return ProtocolUtils.readString(content.slice());
} catch (Exception e) {