From 5b90b114b52131da79e9579adb359041c9b703b2 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 11 Dec 2024 01:28:30 +0800 Subject: [PATCH] Remove unneeded code in CodecProcessor, make Bungee version checker automatically check for the required version --- .../bungeecord/GeyserBungeePlugin.java | 25 ++--- .../geyser/network/CodecProcessor.java | 96 ++----------------- 2 files changed, 20 insertions(+), 101 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java index 290bf2a4e..918c13b93 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java @@ -41,6 +41,7 @@ import org.geysermc.geyser.command.CommandSourceConverter; import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.dump.BootstrapDumpInfo; +import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough; import org.geysermc.geyser.ping.IGeyserPingPassthrough; import org.geysermc.geyser.platform.bungeecord.command.BungeeCommandSource; @@ -58,6 +59,7 @@ import java.net.SocketAddress; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; +import java.util.List; import java.util.Optional; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -80,18 +82,19 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { public void onGeyserInitialize() { GeyserLocale.init(this); - // Copied from ViaVersion. - // https://github.com/ViaVersion/ViaVersion/blob/b8072aad86695cc8ec6f5e4103e43baf3abf6cc5/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java#L43 try { - ProtocolConstants.class.getField("MINECRAFT_1_21_4"); - } catch (NoSuchFieldException e) { - geyserLogger.error(" / \\"); - geyserLogger.error(" / \\"); - geyserLogger.error(" / | \\"); - geyserLogger.error(" / | \\ " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy", getProxy().getName())); - geyserLogger.error(" / \\ " + GeyserLocale.getLocaleStringLog("geyser.may_not_work_as_intended_all_caps")); - geyserLogger.error(" / o \\"); - geyserLogger.error("/_____________\\"); + List supportedProtocols = ProtocolConstants.SUPPORTED_VERSION_IDS; + if (!supportedProtocols.contains(GameProtocol.getJavaProtocolVersion())) { + geyserLogger.error(" / \\"); + geyserLogger.error(" / \\"); + geyserLogger.error(" / | \\"); + geyserLogger.error(" / | \\ " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy", getProxy().getName())); + geyserLogger.error(" / \\ " + GeyserLocale.getLocaleStringLog("geyser.may_not_work_as_intended_all_caps")); + geyserLogger.error(" / o \\"); + geyserLogger.error("/_____________\\"); + } + } catch (Throwable e) { + geyserLogger.warning("Unable to check the versions supported by this proxy! " + e.getMessage()); } if (!this.loadConfig()) { diff --git a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java index 15aa8bc2c..de654ed62 100644 --- a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java +++ b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java @@ -35,17 +35,11 @@ import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.MoveEntityAbsolut import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.PlayerHotbarSerializer_v291; import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.SetEntityLinkSerializer_v291; import org.cloudburstmc.protocol.bedrock.codec.v390.serializer.PlayerSkinSerializer_v390; -import org.cloudburstmc.protocol.bedrock.codec.v407.serializer.InventoryContentSerializer_v407; -import org.cloudburstmc.protocol.bedrock.codec.v407.serializer.InventorySlotSerializer_v407; import org.cloudburstmc.protocol.bedrock.codec.v419.serializer.MovePlayerSerializer_v419; import org.cloudburstmc.protocol.bedrock.codec.v486.serializer.BossEventSerializer_v486; import org.cloudburstmc.protocol.bedrock.codec.v557.serializer.SetEntityDataSerializer_v557; import org.cloudburstmc.protocol.bedrock.codec.v662.serializer.SetEntityMotionSerializer_v662; -import org.cloudburstmc.protocol.bedrock.codec.v712.serializer.InventoryContentSerializer_v712; -import org.cloudburstmc.protocol.bedrock.codec.v712.serializer.InventorySlotSerializer_v712; import org.cloudburstmc.protocol.bedrock.codec.v712.serializer.MobArmorEquipmentSerializer_v712; -import org.cloudburstmc.protocol.bedrock.codec.v729.serializer.InventoryContentSerializer_v729; -import org.cloudburstmc.protocol.bedrock.codec.v729.serializer.InventorySlotSerializer_v729; import org.cloudburstmc.protocol.bedrock.codec.v748.serializer.InventoryContentSerializer_v748; import org.cloudburstmc.protocol.bedrock.codec.v748.serializer.InventorySlotSerializer_v748; import org.cloudburstmc.protocol.bedrock.packet.AnvilDamagePacket; @@ -95,6 +89,7 @@ import org.cloudburstmc.protocol.common.util.VarInts; /** * Processes the Bedrock codec to remove or modify unused or unsafe packets and fields. */ +@SuppressWarnings("deprecation") class CodecProcessor { /** @@ -126,27 +121,9 @@ class CodecProcessor { public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, BedrockPacket packet) { } }; - /** * Serializer that throws an exception when trying to deserialize InventoryContentPacket since server-auth inventory is used. */ - private static final BedrockPacketSerializer INVENTORY_CONTENT_SERIALIZER_V407 = new InventoryContentSerializer_v407() { - @Override - public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventoryContentPacket packet) { - throw new IllegalArgumentException("Client cannot send InventoryContentPacket in server-auth inventory environment!"); - } - }; - - /** - * Serializer that throws an exception when trying to deserialize InventoryContentPacket since server-auth inventory is used. - */ - private static final BedrockPacketSerializer INVENTORY_CONTENT_SERIALIZER_V712 = new InventoryContentSerializer_v712() { - @Override - public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventoryContentPacket packet) { - throw new IllegalArgumentException("Client cannot send InventoryContentPacket in server-auth inventory environment!"); - } - }; - private static final BedrockPacketSerializer INVENTORY_CONTENT_SERIALIZER_V748 = new InventoryContentSerializer_v748() { @Override public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventoryContentPacket packet) { @@ -154,40 +131,9 @@ class CodecProcessor { } }; - private static final BedrockPacketSerializer INVENTORY_CONTENT_SERIALIZER_V729 = new InventoryContentSerializer_v729() { - @Override - public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventoryContentPacket packet) { - throw new IllegalArgumentException("Client cannot send InventoryContentPacket in server-auth inventory environment!"); - } - }; - - /** - * Serializer that throws an exception when trying to deserialize InventorySlotPacket since server-auth inventory is used. - */ - private static final BedrockPacketSerializer INVENTORY_SLOT_SERIALIZER_V407 = new InventorySlotSerializer_v407() { - @Override - public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventorySlotPacket packet) { - throw new IllegalArgumentException("Client cannot send InventorySlotPacket in server-auth inventory environment!"); - } - }; - /* * Serializer that throws an exception when trying to deserialize InventorySlotPacket since server-auth inventory is used. */ - private static final BedrockPacketSerializer INVENTORY_SLOT_SERIALIZER_V712 = new InventorySlotSerializer_v712() { - @Override - public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventorySlotPacket packet) { - throw new IllegalArgumentException("Client cannot send InventorySlotPacket in server-auth inventory environment!"); - } - }; - - private static final BedrockPacketSerializer INVENTORY_SLOT_SERIALIZER_V729 = new InventorySlotSerializer_v729() { - @Override - public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventorySlotPacket packet) { - throw new IllegalArgumentException("Client cannot send InventorySlotPacket in server-auth inventory environment!"); - } - }; - private static final BedrockPacketSerializer INVENTORY_SLOT_SERIALIZER_V748 = new InventorySlotSerializer_v748() { @Override public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventorySlotPacket packet) { @@ -297,32 +243,6 @@ class CodecProcessor { @SuppressWarnings("unchecked") static BedrockCodec processCodec(BedrockCodec codec) { - boolean is748OrAbove = codec.getProtocolVersion() >= 748; - boolean is729OrAbove = codec.getProtocolVersion() >= 729; - boolean is712OrAbove = codec.getProtocolVersion() >= 712; - - BedrockPacketSerializer inventoryContentSerializer; - if (is748OrAbove) { - inventoryContentSerializer = INVENTORY_CONTENT_SERIALIZER_V748; - } else if (is729OrAbove) { - inventoryContentSerializer = INVENTORY_CONTENT_SERIALIZER_V729; - } else if (is712OrAbove) { - inventoryContentSerializer = INVENTORY_CONTENT_SERIALIZER_V712; - } else { - inventoryContentSerializer = INVENTORY_CONTENT_SERIALIZER_V407; - } - - BedrockPacketSerializer inventorySlotSerializer; - if (is748OrAbove) { - inventorySlotSerializer = INVENTORY_SLOT_SERIALIZER_V748; - } else if (is729OrAbove) { - inventorySlotSerializer = INVENTORY_SLOT_SERIALIZER_V729; - } else if (is712OrAbove) { - inventorySlotSerializer = INVENTORY_SLOT_SERIALIZER_V712; - } else { - inventorySlotSerializer = INVENTORY_SLOT_SERIALIZER_V407; - } - BedrockCodec.Builder codecBuilder = codec.toBuilder() // Illegal unused serverbound EDU packets .updateSerializer(PhotoTransferPacket.class, ILLEGAL_SERIALIZER) @@ -350,15 +270,15 @@ class CodecProcessor { .updateSerializer(AnvilDamagePacket.class, IGNORED_SERIALIZER) .updateSerializer(RefreshEntitlementsPacket.class, IGNORED_SERIALIZER) // Illegal when serverbound due to Geyser specific setup - .updateSerializer(InventoryContentPacket.class, inventoryContentSerializer) - .updateSerializer(InventorySlotPacket.class, inventorySlotSerializer) + .updateSerializer(InventoryContentPacket.class, INVENTORY_CONTENT_SERIALIZER_V748) + .updateSerializer(InventorySlotPacket.class, INVENTORY_SLOT_SERIALIZER_V748) .updateSerializer(MovePlayerPacket.class, MOVE_PLAYER_SERIALIZER) .updateSerializer(MoveEntityAbsolutePacket.class, MOVE_ENTITY_SERIALIZER) .updateSerializer(RiderJumpPacket.class, ILLEGAL_SERIALIZER) .updateSerializer(PlayerInputPacket.class, ILLEGAL_SERIALIZER) // Ignored only when serverbound .updateSerializer(BossEventPacket.class, BOSS_EVENT_SERIALIZER) - .updateSerializer(MobArmorEquipmentPacket.class, is712OrAbove ? MOB_ARMOR_EQUIPMENT_SERIALIZER_V712 : MOB_ARMOR_EQUIPMENT_SERIALIZER_V291) + .updateSerializer(MobArmorEquipmentPacket.class, MOB_ARMOR_EQUIPMENT_SERIALIZER_V712) .updateSerializer(PlayerHotbarPacket.class, PLAYER_HOTBAR_SERIALIZER) .updateSerializer(PlayerSkinPacket.class, PLAYER_SKIN_SERIALIZER) .updateSerializer(SetEntityDataPacket.class, SET_ENTITY_DATA_SERIALIZER) @@ -373,12 +293,8 @@ class CodecProcessor { // Ignored bidirectional packets .updateSerializer(ClientCacheStatusPacket.class, IGNORED_SERIALIZER) .updateSerializer(SimpleEventPacket.class, IGNORED_SERIALIZER) - .updateSerializer(MultiplayerSettingsPacket.class, IGNORED_SERIALIZER); - - if (codec.getProtocolVersion() < 685) { - // Ignored bidirectional packets - codecBuilder.updateSerializer(TickSyncPacket.class, IGNORED_SERIALIZER); - } + .updateSerializer(MultiplayerSettingsPacket.class, IGNORED_SERIALIZER) + .updateSerializer(TickSyncPacket.class, IGNORED_SERIALIZER); return codecBuilder.build(); }