diff --git a/build.gradle.kts b/build.gradle.kts index 8c839cc..0937b96 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "org.powernukkitx.anyversion" -version = "2.8.6" +version = "2.8.7" java { toolchain { diff --git a/src/main/java/org/powernukkitx/anyversion/manager/ProtocolManager.java b/src/main/java/org/powernukkitx/anyversion/manager/ProtocolManager.java index 4e41641..73fe55e 100644 --- a/src/main/java/org/powernukkitx/anyversion/manager/ProtocolManager.java +++ b/src/main/java/org/powernukkitx/anyversion/manager/ProtocolManager.java @@ -245,13 +245,16 @@ private void handleLenient(LoginPacket packet, PlayerSessionHolder holder, Serve return; } - if (lenient.chain.isEduMode()) { + var clientChainData = lenient.chain; + + if (clientChainData.isEduMode()) { holder.sendPlayStatus(PlayStatus.LOGIN_FAILED_EDITION_MISMATCH_EDU_TO_VANILLA); holder.disconnect(DisconnectFailReason.EDITION_MISMATCH_EDU_TO_VANILLA); return; } - holder.setPlayerInfo(new Player.PlayerInfo(identityClaims, lenient.chain, lenient.skin, result.signed())); + holder.getSession().setCodec(ProtocolVersion.codecForGameVersion(clientChainData.getGameVersion())); + holder.setPlayerInfo(new Player.PlayerInfo(identityClaims, clientChainData, lenient.skin, result.signed())); if (server.enabledNetworkEncryption) { enableEncryption(identityClaims, holder); diff --git a/src/main/java/org/powernukkitx/anyversion/utils/ProtocolVersion.java b/src/main/java/org/powernukkitx/anyversion/utils/ProtocolVersion.java index 7725ca1..dc2e916 100644 --- a/src/main/java/org/powernukkitx/anyversion/utils/ProtocolVersion.java +++ b/src/main/java/org/powernukkitx/anyversion/utils/ProtocolVersion.java @@ -1,6 +1,7 @@ package org.powernukkitx.anyversion.utils; import org.cloudburstmc.protocol.bedrock.codec.v2168.Bedrock_v2168; +import org.cloudburstmc.protocol.bedrock.codec.v2168.Bedrock_v2168_hotfix4; import org.powernukkitx.network.NetworkConstants; import lombok.Getter; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; @@ -35,8 +36,10 @@ import org.cloudburstmc.protocol.bedrock.codec.v975.Bedrock_v975; import org.cloudburstmc.protocol.bedrock.codec.v1001.Bedrock_v1001; import org.cloudburstmc.protocol.bedrock.data.EncodingSettings; +import org.powernukkitx.utils.SemVersion; import java.util.Arrays; +import java.util.List; public enum ProtocolVersion { /*MINECRAFT_PE_1_8(313, Bedrock_v313.CODEC), @@ -100,9 +103,13 @@ public enum ProtocolVersion { MINECRAFT_PE_1_26_10(944, Bedrock_v944.CODEC), MINECRAFT_PE_1_26_20(975, Bedrock_v975.CODEC), MINECRAFT_PE_1_26_30(1001, Bedrock_v1001.CODEC), - MINECRAFT_PE_1_26_40(2168, Bedrock_v2168.CODEC); + MINECRAFT_PE_1_26_40(2168, Bedrock_v2168.CODEC), + MINECRAFT_PE_1_26_44(2168, Bedrock_v2168_hotfix4.CODEC), + MINECRAFT_PE_1_26_45(2169, Bedrock_v2168.CODEC.toBuilder().minecraftVersion("1.26.45").protocolVersion(2169).build()); // lmao what a headache + @Getter private static final ProtocolVersion[] versions = values(); + @Getter private static final ProtocolVersion current = findCurrent(); private final int PROTOCOL; @@ -110,6 +117,14 @@ public enum ProtocolVersion { private final BedrockCodecHelper HELPER; + /** + * TODO: We need a better code for this. This looks terrible + */ + private static final List TEMP_CODECS = List.of( + Bedrock_v2168_hotfix4.CODEC, + Bedrock_v2168.CODEC + ); + ProtocolVersion(int protocol, BedrockCodec codec) { this.PROTOCOL = protocol; this.CODEC = codec; @@ -150,7 +165,7 @@ public static ProtocolVersion getMax() { private static ProtocolVersion findCurrent() { int serverProtocol = NetworkConstants.CODEC.getProtocolVersion(); return Arrays.stream(versions) - .filter(p -> p.protocol() == serverProtocol) + .filter(p -> p.protocol() == serverProtocol && p.version().equals(NetworkConstants.CODEC.getMinecraftVersion())) // TODO: temp, or persistent maybe? not bad .findAny() .orElseGet(ProtocolVersion::getMax); } @@ -163,11 +178,30 @@ public static boolean has(int protocol) { return Arrays.stream(versions).anyMatch(p -> p.protocol() == protocol); } - public static ProtocolVersion[] getVersions() { - return versions; + public static BedrockCodec codecForGameVersion(String gameVersion) { + if (gameVersion == null || gameVersion.equals(getMax().CODEC.getMinecraftVersion())) { // temporary for 1.26.45 + return getMax().CODEC; + } + final SemVersion clientVersion = SemVersion.fromString(gameVersion); + for (BedrockCodec codec : TEMP_CODECS) { + if (compare(SemVersion.fromString(codec.getMinecraftVersion()), clientVersion) <= 0) { + return codec; + } + } + return getMax().CODEC; } - public static ProtocolVersion getCurrent() { - return current; + private static int compare(SemVersion left, SemVersion right) { + int result = Integer.compare(left.major(), right.major()); + if (result == 0) { + result = Integer.compare(left.minor(), right.minor()); + } + if (result == 0) { + result = Integer.compare(left.patch(), right.patch()); + } + if (result == 0) { + result = Integer.compare(left.revision(), right.revision()); + } + return result; } }