Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "org.powernukkitx.anyversion"
version = "2.8.6"
version = "2.8.7"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -100,16 +103,28 @@ 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;
private final BedrockCodec CODEC;

private final BedrockCodecHelper HELPER;

/**
* TODO: We need a better code for this. This looks terrible
*/
private static final List<BedrockCodec> TEMP_CODECS = List.of(
Bedrock_v2168_hotfix4.CODEC,
Bedrock_v2168.CODEC
);

ProtocolVersion(int protocol, BedrockCodec codec) {
this.PROTOCOL = protocol;
this.CODEC = codec;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
}
Loading