3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Only send the client brand on game join (#1299)

* Only send the client brand on game join

* Apply suggested changes
Dieser Commit ist enthalten in:
Camotoy 2020-09-21 16:06:25 -04:00 committet von GitHub
Ursprung 5fafa0759e
Commit 2db1d16f5c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 16 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -28,6 +28,7 @@ package org.geysermc.connector.network.translators.java;
import com.github.steveice10.mc.protocol.data.game.entity.player.HandPreference; import com.github.steveice10.mc.protocol.data.game.entity.player.HandPreference;
import com.github.steveice10.mc.protocol.data.game.setting.ChatVisibility; import com.github.steveice10.mc.protocol.data.game.setting.ChatVisibility;
import com.github.steveice10.mc.protocol.data.game.setting.SkinPart; import com.github.steveice10.mc.protocol.data.game.setting.SkinPart;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
import com.nukkitx.protocol.bedrock.data.GameRuleData; import com.nukkitx.protocol.bedrock.data.GameRuleData;
@ -38,6 +39,7 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.DimensionUtils; import org.geysermc.connector.utils.DimensionUtils;
import org.geysermc.connector.utils.PluginMessageUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -92,6 +94,8 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, skinParts, HandPreference.RIGHT_HAND); ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, skinParts, HandPreference.RIGHT_HAND);
session.sendDownstreamPacket(clientSettingsPacket); session.sendDownstreamPacket(clientSettingsPacket);
session.sendDownstreamPacket(new ClientPluginMessagePacket("minecraft:brand", PluginMessageUtils.getGeyserBrandData()));
if (!newDimension.equals(entity.getDimension())) { if (!newDimension.equals(entity.getDimension())) {
DimensionUtils.switchDimension(session, newDimension); DimensionUtils.switchDimension(session, newDimension);
} }

Datei anzeigen

@ -23,39 +23,30 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.connector.network.translators.java; package org.geysermc.connector.utils;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@Translator(packet = ServerPluginMessagePacket.class) public class PluginMessageUtils {
public class JavaPluginMessageTranslator extends PacketTranslator<ServerPluginMessagePacket> {
private static byte[] brandData; private static final byte[] BRAND_DATA;
static { static {
byte[] data = GeyserConnector.NAME.getBytes(StandardCharsets.UTF_8); byte[] data = GeyserConnector.NAME.getBytes(StandardCharsets.UTF_8);
byte[] varInt = writeVarInt(data.length); byte[] varInt = writeVarInt(data.length);
brandData = new byte[varInt.length + data.length]; BRAND_DATA = new byte[varInt.length + data.length];
System.arraycopy(varInt, 0, brandData, 0, varInt.length); System.arraycopy(varInt, 0, BRAND_DATA, 0, varInt.length);
System.arraycopy(data, 0, brandData, varInt.length, data.length); System.arraycopy(data, 0, BRAND_DATA, varInt.length, data.length);
} }
/**
@Override * Get the prebuilt brand as a byte array
public void translate(ServerPluginMessagePacket packet, GeyserSession session) { * @return the brand information of the Geyser client
if (packet.getChannel().equals("minecraft:brand")) { */
session.sendDownstreamPacket( public static byte[] getGeyserBrandData() {
new ClientPluginMessagePacket(packet.getChannel(), brandData) return BRAND_DATA;
);
}
} }
private static byte[] writeVarInt(int value) { private static byte[] writeVarInt(int value) {