mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-22 14:34:59 +01:00
Remove unneeded code in CodecProcessor, make Bungee version checker automatically check for the required version
This commit is contained in:
parent
94d77b403b
commit
5b90b114b5
2 changed files with 20 additions and 101 deletions
|
@ -41,6 +41,7 @@ import org.geysermc.geyser.command.CommandSourceConverter;
|
||||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||||
import org.geysermc.geyser.configuration.GeyserConfiguration;
|
import org.geysermc.geyser.configuration.GeyserConfiguration;
|
||||||
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
||||||
|
import org.geysermc.geyser.network.GameProtocol;
|
||||||
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
|
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
|
||||||
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
||||||
import org.geysermc.geyser.platform.bungeecord.command.BungeeCommandSource;
|
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.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -80,18 +82,19 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
|
||||||
public void onGeyserInitialize() {
|
public void onGeyserInitialize() {
|
||||||
GeyserLocale.init(this);
|
GeyserLocale.init(this);
|
||||||
|
|
||||||
// Copied from ViaVersion.
|
|
||||||
// https://github.com/ViaVersion/ViaVersion/blob/b8072aad86695cc8ec6f5e4103e43baf3abf6cc5/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java#L43
|
|
||||||
try {
|
try {
|
||||||
ProtocolConstants.class.getField("MINECRAFT_1_21_4");
|
List<Integer> supportedProtocols = ProtocolConstants.SUPPORTED_VERSION_IDS;
|
||||||
} catch (NoSuchFieldException e) {
|
if (!supportedProtocols.contains(GameProtocol.getJavaProtocolVersion())) {
|
||||||
geyserLogger.error(" / \\");
|
geyserLogger.error(" / \\");
|
||||||
geyserLogger.error(" / \\");
|
geyserLogger.error(" / \\");
|
||||||
geyserLogger.error(" / | \\");
|
geyserLogger.error(" / | \\");
|
||||||
geyserLogger.error(" / | \\ " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy", getProxy().getName()));
|
geyserLogger.error(" / | \\ " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy", getProxy().getName()));
|
||||||
geyserLogger.error(" / \\ " + GeyserLocale.getLocaleStringLog("geyser.may_not_work_as_intended_all_caps"));
|
geyserLogger.error(" / \\ " + GeyserLocale.getLocaleStringLog("geyser.may_not_work_as_intended_all_caps"));
|
||||||
geyserLogger.error(" / o \\");
|
geyserLogger.error(" / o \\");
|
||||||
geyserLogger.error("/_____________\\");
|
geyserLogger.error("/_____________\\");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
geyserLogger.warning("Unable to check the versions supported by this proxy! " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.loadConfig()) {
|
if (!this.loadConfig()) {
|
||||||
|
|
|
@ -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.PlayerHotbarSerializer_v291;
|
||||||
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.SetEntityLinkSerializer_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.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.v419.serializer.MovePlayerSerializer_v419;
|
||||||
import org.cloudburstmc.protocol.bedrock.codec.v486.serializer.BossEventSerializer_v486;
|
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.v557.serializer.SetEntityDataSerializer_v557;
|
||||||
import org.cloudburstmc.protocol.bedrock.codec.v662.serializer.SetEntityMotionSerializer_v662;
|
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.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.InventoryContentSerializer_v748;
|
||||||
import org.cloudburstmc.protocol.bedrock.codec.v748.serializer.InventorySlotSerializer_v748;
|
import org.cloudburstmc.protocol.bedrock.codec.v748.serializer.InventorySlotSerializer_v748;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.AnvilDamagePacket;
|
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.
|
* Processes the Bedrock codec to remove or modify unused or unsafe packets and fields.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
class CodecProcessor {
|
class CodecProcessor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,27 +121,9 @@ class CodecProcessor {
|
||||||
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, BedrockPacket packet) {
|
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.
|
* Serializer that throws an exception when trying to deserialize InventoryContentPacket since server-auth inventory is used.
|
||||||
*/
|
*/
|
||||||
private static final BedrockPacketSerializer<InventoryContentPacket> 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<InventoryContentPacket> 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<InventoryContentPacket> INVENTORY_CONTENT_SERIALIZER_V748 = new InventoryContentSerializer_v748() {
|
private static final BedrockPacketSerializer<InventoryContentPacket> INVENTORY_CONTENT_SERIALIZER_V748 = new InventoryContentSerializer_v748() {
|
||||||
@Override
|
@Override
|
||||||
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventoryContentPacket packet) {
|
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventoryContentPacket packet) {
|
||||||
|
@ -154,40 +131,9 @@ class CodecProcessor {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final BedrockPacketSerializer<InventoryContentPacket> 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<InventorySlotPacket> 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.
|
* Serializer that throws an exception when trying to deserialize InventorySlotPacket since server-auth inventory is used.
|
||||||
*/
|
*/
|
||||||
private static final BedrockPacketSerializer<InventorySlotPacket> 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<InventorySlotPacket> 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<InventorySlotPacket> INVENTORY_SLOT_SERIALIZER_V748 = new InventorySlotSerializer_v748() {
|
private static final BedrockPacketSerializer<InventorySlotPacket> INVENTORY_SLOT_SERIALIZER_V748 = new InventorySlotSerializer_v748() {
|
||||||
@Override
|
@Override
|
||||||
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventorySlotPacket packet) {
|
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventorySlotPacket packet) {
|
||||||
|
@ -297,32 +243,6 @@ class CodecProcessor {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static BedrockCodec processCodec(BedrockCodec codec) {
|
static BedrockCodec processCodec(BedrockCodec codec) {
|
||||||
boolean is748OrAbove = codec.getProtocolVersion() >= 748;
|
|
||||||
boolean is729OrAbove = codec.getProtocolVersion() >= 729;
|
|
||||||
boolean is712OrAbove = codec.getProtocolVersion() >= 712;
|
|
||||||
|
|
||||||
BedrockPacketSerializer<InventoryContentPacket> 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<InventorySlotPacket> 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()
|
BedrockCodec.Builder codecBuilder = codec.toBuilder()
|
||||||
// Illegal unused serverbound EDU packets
|
// Illegal unused serverbound EDU packets
|
||||||
.updateSerializer(PhotoTransferPacket.class, ILLEGAL_SERIALIZER)
|
.updateSerializer(PhotoTransferPacket.class, ILLEGAL_SERIALIZER)
|
||||||
|
@ -350,15 +270,15 @@ class CodecProcessor {
|
||||||
.updateSerializer(AnvilDamagePacket.class, IGNORED_SERIALIZER)
|
.updateSerializer(AnvilDamagePacket.class, IGNORED_SERIALIZER)
|
||||||
.updateSerializer(RefreshEntitlementsPacket.class, IGNORED_SERIALIZER)
|
.updateSerializer(RefreshEntitlementsPacket.class, IGNORED_SERIALIZER)
|
||||||
// Illegal when serverbound due to Geyser specific setup
|
// Illegal when serverbound due to Geyser specific setup
|
||||||
.updateSerializer(InventoryContentPacket.class, inventoryContentSerializer)
|
.updateSerializer(InventoryContentPacket.class, INVENTORY_CONTENT_SERIALIZER_V748)
|
||||||
.updateSerializer(InventorySlotPacket.class, inventorySlotSerializer)
|
.updateSerializer(InventorySlotPacket.class, INVENTORY_SLOT_SERIALIZER_V748)
|
||||||
.updateSerializer(MovePlayerPacket.class, MOVE_PLAYER_SERIALIZER)
|
.updateSerializer(MovePlayerPacket.class, MOVE_PLAYER_SERIALIZER)
|
||||||
.updateSerializer(MoveEntityAbsolutePacket.class, MOVE_ENTITY_SERIALIZER)
|
.updateSerializer(MoveEntityAbsolutePacket.class, MOVE_ENTITY_SERIALIZER)
|
||||||
.updateSerializer(RiderJumpPacket.class, ILLEGAL_SERIALIZER)
|
.updateSerializer(RiderJumpPacket.class, ILLEGAL_SERIALIZER)
|
||||||
.updateSerializer(PlayerInputPacket.class, ILLEGAL_SERIALIZER)
|
.updateSerializer(PlayerInputPacket.class, ILLEGAL_SERIALIZER)
|
||||||
// Ignored only when serverbound
|
// Ignored only when serverbound
|
||||||
.updateSerializer(BossEventPacket.class, BOSS_EVENT_SERIALIZER)
|
.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(PlayerHotbarPacket.class, PLAYER_HOTBAR_SERIALIZER)
|
||||||
.updateSerializer(PlayerSkinPacket.class, PLAYER_SKIN_SERIALIZER)
|
.updateSerializer(PlayerSkinPacket.class, PLAYER_SKIN_SERIALIZER)
|
||||||
.updateSerializer(SetEntityDataPacket.class, SET_ENTITY_DATA_SERIALIZER)
|
.updateSerializer(SetEntityDataPacket.class, SET_ENTITY_DATA_SERIALIZER)
|
||||||
|
@ -373,12 +293,8 @@ class CodecProcessor {
|
||||||
// Ignored bidirectional packets
|
// Ignored bidirectional packets
|
||||||
.updateSerializer(ClientCacheStatusPacket.class, IGNORED_SERIALIZER)
|
.updateSerializer(ClientCacheStatusPacket.class, IGNORED_SERIALIZER)
|
||||||
.updateSerializer(SimpleEventPacket.class, IGNORED_SERIALIZER)
|
.updateSerializer(SimpleEventPacket.class, IGNORED_SERIALIZER)
|
||||||
.updateSerializer(MultiplayerSettingsPacket.class, IGNORED_SERIALIZER);
|
.updateSerializer(MultiplayerSettingsPacket.class, IGNORED_SERIALIZER)
|
||||||
|
.updateSerializer(TickSyncPacket.class, IGNORED_SERIALIZER);
|
||||||
if (codec.getProtocolVersion() < 685) {
|
|
||||||
// Ignored bidirectional packets
|
|
||||||
codecBuilder.updateSerializer(TickSyncPacket.class, IGNORED_SERIALIZER);
|
|
||||||
}
|
|
||||||
|
|
||||||
return codecBuilder.build();
|
return codecBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue