From bb8e4067b0d21826b7e6910dced986c428a8620f Mon Sep 17 00:00:00 2001 From: Alemiz Date: Mon, 16 Oct 2023 13:54:14 +0200 Subject: [PATCH] Start working on 1.20.40 protocol --- .../bedrock/codec/compat/BedrockCompat.java | 10 +- .../DisconnectSerializerCompat.java | 15 ++- .../bedrock/codec/v618/Bedrock_v618.java | 1 - .../bedrock/codec/v622/Bedrock_v622.java | 53 +++++++++++ .../serializer/DisconnectSerializer_v622.java | 27 ++++++ .../bedrock/data/DisconnectFailReason.java | 95 +++++++++++++++++++ .../bedrock/data/PlayerActionType.java | 6 +- .../bedrock/data/PlayerAuthInputData.java | 6 +- .../protocol/bedrock/data/SoundEvent.java | 8 ++ .../bedrock/data/entity/EntityFlag.java | 14 ++- .../bedrock/packet/DisconnectPacket.java | 2 + 11 files changed, 228 insertions(+), 9 deletions(-) create mode 100644 bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v622/Bedrock_v622.java create mode 100644 bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v622/serializer/DisconnectSerializer_v622.java create mode 100644 bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/DisconnectFailReason.java diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/compat/BedrockCompat.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/compat/BedrockCompat.java index 2b2e8f9e5..9bfc73884 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/compat/BedrockCompat.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/compat/BedrockCompat.java @@ -18,9 +18,17 @@ public class BedrockCompat { .helper(() -> NoopBedrockCodecHelper.INSTANCE) .registerPacket(LoginPacket::new, LoginSerializerCompat.INSTANCE, 1) .registerPacket(PlayStatusPacket::new, PlayStatusSerializerCompat.INSTANCE, 2) - .registerPacket(DisconnectPacket::new, DisconnectSerializerCompat.INSTANCE, 5) + .registerPacket(DisconnectPacket::new, new DisconnectSerializerCompat(true), 5) .registerPacket(RequestNetworkSettingsPacket::new, RequestNetworkSettingsSerializerCompat.INSTANCE, 193) .protocolVersion(0) .minecraftVersion("0.0.0") .build(); + + /** + * This is legacy version of the compat codec which does not use DisconnectFailReason in DisconnectPacket. + * Use this for servers that do not support Minecraft: Bedrock Edition 1.20.40 and above. + */ + public static BedrockCodec CODEC_LEGACY = CODEC.toBuilder() + .updateSerializer(DisconnectPacket.class, new DisconnectSerializerCompat(false)) + .build(); } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/compat/serializer/DisconnectSerializerCompat.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/compat/serializer/DisconnectSerializerCompat.java index 88a14a0b2..f6dca303c 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/compat/serializer/DisconnectSerializerCompat.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/compat/serializer/DisconnectSerializerCompat.java @@ -1,18 +1,22 @@ package org.cloudburstmc.protocol.bedrock.codec.compat.serializer; import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper; import org.cloudburstmc.protocol.bedrock.codec.BedrockPacketSerializer; +import org.cloudburstmc.protocol.bedrock.data.DisconnectFailReason; import org.cloudburstmc.protocol.bedrock.packet.DisconnectPacket; +import org.cloudburstmc.protocol.common.util.VarInts; -@NoArgsConstructor(access = AccessLevel.PRIVATE) +@RequiredArgsConstructor public class DisconnectSerializerCompat implements BedrockPacketSerializer { - public static final DisconnectSerializerCompat INSTANCE = new DisconnectSerializerCompat(); + private final boolean reasonEnum; @Override public void serialize(ByteBuf buffer, BedrockCodecHelper helper, DisconnectPacket packet) { + if (this.reasonEnum) { + VarInts.writeInt(buffer, packet.getReason().ordinal()); + } buffer.writeBoolean(packet.isMessageSkipped()); if (!packet.isMessageSkipped()) { helper.writeString(buffer, packet.getKickMessage()); @@ -21,6 +25,9 @@ public void serialize(ByteBuf buffer, BedrockCodecHelper helper, DisconnectPacke @Override public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, DisconnectPacket packet) { + if (this.reasonEnum) { + packet.setReason(DisconnectFailReason.values()[VarInts.readInt(buffer)]); + } packet.setMessageSkipped(buffer.readBoolean()); if (!packet.isMessageSkipped()) { packet.setKickMessage(helper.readString(buffer)); diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v618/Bedrock_v618.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v618/Bedrock_v618.java index 210ed6a69..a16db93d1 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v618/Bedrock_v618.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v618/Bedrock_v618.java @@ -20,7 +20,6 @@ import org.cloudburstmc.protocol.common.util.TypeMap; public class Bedrock_v618 extends Bedrock_v594 { - // TODO: check command params protected static final TypeMap SOUND_EVENTS = Bedrock_v594.SOUND_EVENTS .toBuilder() diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v622/Bedrock_v622.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v622/Bedrock_v622.java new file mode 100644 index 000000000..fde896618 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v622/Bedrock_v622.java @@ -0,0 +1,53 @@ +package org.cloudburstmc.protocol.bedrock.codec.v622; + +import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; +import org.cloudburstmc.protocol.bedrock.codec.EntityDataTypeMap; +import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.LevelSoundEvent1Serializer_v291; +import org.cloudburstmc.protocol.bedrock.codec.v313.serializer.LevelSoundEvent2Serializer_v313; +import org.cloudburstmc.protocol.bedrock.codec.v332.serializer.LevelSoundEventSerializer_v332; +import org.cloudburstmc.protocol.bedrock.codec.v575.BedrockCodecHelper_v575; +import org.cloudburstmc.protocol.bedrock.codec.v618.Bedrock_v618; +import org.cloudburstmc.protocol.bedrock.codec.v622.serializer.DisconnectSerializer_v622; +import org.cloudburstmc.protocol.bedrock.data.SoundEvent; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.cloudburstmc.protocol.bedrock.packet.DisconnectPacket; +import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEvent1Packet; +import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEvent2Packet; +import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; +import org.cloudburstmc.protocol.bedrock.transformer.FlagTransformer; +import org.cloudburstmc.protocol.common.util.TypeMap; + +public class Bedrock_v622 extends Bedrock_v618 { + + protected static final TypeMap ENTITY_FLAGS = Bedrock_v618.ENTITY_FLAGS + .toBuilder() + .insert(115, EntityFlag.TIMER_FLAG_1) + .insert(116, EntityFlag.TIMER_FLAG_2) + .insert(117, EntityFlag.TIMER_FLAG_3) + .build(); + + protected static final EntityDataTypeMap ENTITY_DATA = Bedrock_v618.ENTITY_DATA + .toBuilder() + .update(EntityDataTypes.FLAGS, new FlagTransformer(ENTITY_FLAGS, 0)) + .update(EntityDataTypes.FLAGS_2, new FlagTransformer(ENTITY_FLAGS, 1)) + .build(); + + protected static final TypeMap SOUND_EVENTS = Bedrock_v618.SOUND_EVENTS + .toBuilder() + .replace(477, SoundEvent.BOTTLE_FILL) + .insert(478, SoundEvent.BOTTLE_EMPTY) + .insert(479, SoundEvent.UNDEFINED) + .build(); + + public static final BedrockCodec CODEC = Bedrock_v618.CODEC.toBuilder() + .raknetProtocolVersion(11) + .protocolVersion(622) + .minecraftVersion("1.20.40") + .helper(() -> new BedrockCodecHelper_v575(ENTITY_DATA, GAME_RULE_TYPES, ITEM_STACK_REQUEST_TYPES, CONTAINER_SLOT_TYPES, PLAYER_ABILITIES, TEXT_PROCESSING_ORIGINS)) + .updateSerializer(DisconnectPacket.class, DisconnectSerializer_v622.INSTANCE) + .updateSerializer(LevelSoundEvent1Packet.class, new LevelSoundEvent1Serializer_v291(SOUND_EVENTS)) + .updateSerializer(LevelSoundEvent2Packet.class, new LevelSoundEvent2Serializer_v313(SOUND_EVENTS)) + .updateSerializer(LevelSoundEventPacket.class, new LevelSoundEventSerializer_v332(SOUND_EVENTS)) + .build(); +} \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v622/serializer/DisconnectSerializer_v622.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v622/serializer/DisconnectSerializer_v622.java new file mode 100644 index 000000000..a58df1fdb --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v622/serializer/DisconnectSerializer_v622.java @@ -0,0 +1,27 @@ +package org.cloudburstmc.protocol.bedrock.codec.v622.serializer; + +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper; +import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.DisconnectSerializer_v291; +import org.cloudburstmc.protocol.bedrock.data.DisconnectFailReason; +import org.cloudburstmc.protocol.bedrock.packet.DisconnectPacket; +import org.cloudburstmc.protocol.common.util.VarInts; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class DisconnectSerializer_v622 extends DisconnectSerializer_v291 { + public static final DisconnectSerializer_v622 INSTANCE = new DisconnectSerializer_v622(); + + @Override + public void serialize(ByteBuf buffer, BedrockCodecHelper helper, DisconnectPacket packet) { + VarInts.writeInt(buffer, packet.getReason().ordinal()); + super.serialize(buffer, helper, packet); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, DisconnectPacket packet) { + packet.setReason(DisconnectFailReason.values()[VarInts.readInt(buffer)]); + super.deserialize(buffer, helper, packet); + } +} diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/DisconnectFailReason.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/DisconnectFailReason.java new file mode 100644 index 000000000..40b0b80c4 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/DisconnectFailReason.java @@ -0,0 +1,95 @@ +package org.cloudburstmc.protocol.bedrock.data; + +public enum DisconnectFailReason { + UNKNOWN, + CANT_CONNECT_NO_INTERNET, + NO_PERMISSIONS, + UNRECOVERABLE_ERROR, + THIRD_PARTY_BLOCKED, + THIRD_PARTY_NO_INTERNET, + THIRD_PARTY_BAD_IP, + THIRD_PARTY_NO_SERVER_OR_SERVER_LOCKED, + VERSION_MISMATCH, + SKIN_ISSUE, + INVITE_SESSION_NOT_FOUND, + EDU_LEVEL_SETTINGS_MISSING, + LOCAL_SERVER_NOT_FOUND, + LEGACY_DISCONNECT, + USER_LEAVE_GAME_ATTEMPTED, + PLATFORM_LOCKED_SKINS_ERROR, + REALMS_WORLD_UNASSIGNED, + REALMS_SERVER_CANT_CONNECT, + REALMS_SERVER_HIDDEN, + REALMS_SERVER_DISABLED_BETA, + REALMS_SERVER_DISABLED, + CROSS_PLATFORM_DISALLOWED, + CANT_CONNECT, + SESSION_NOT_FOUND, + CLIENT_SETTINGS_INCOMPATIBLE_WITH_SERVER, + SERVER_FULL, + INVALID_PLATFORM_SKIN, + EDITION_VERSION_MISMATCH, + EDITION_MISMATCH, + LEVEL_NEWER_THAN_EXE_VERSION, + NO_FAIL_OCCURRED, + BANNED_SKIN, + TIMEOUT, + SERVER_NOT_FOUND, + OUTDATED_SERVER, + OUTDATED_CLIENT, + NO_PREMIUM_PLATFORM, + MULTIPLAYER_DISABLED, + NO_WIFI, + WORLD_CORRUPTION, + NO_REASON, + DISCONNECTED, + INVALID_PLAYER, + LOGGED_IN_OTHER_LOCATION, + SERVER_ID_CONFLICT, + NOT_ALLOWED, + NOT_AUTHENTICATED, + INVALID_TENANT, + UNKNOWN_PACKET, + UNEXPECTED_PACKET, + INVALID_COMMAND_REQUEST_PACKET, + HOST_SUSPENDED, + LOGIN_PACKET_NO_REQUEST, + LOGIN_PACKET_NO_CERT, + MISSING_CLIENT, + KICKED, + KICKED_FOR_EXPLOIT, + KICKED_FOR_IDLE, + RESOURCE_PACK_PROBLEM, + INCOMPATIBLE_PACK, + OUT_OF_STORAGE, + INVALID_LEVEL, + DISCONNECT_PACKET_DEPRECATED, + BLOCK_MISMATCH, + INVALID_HEIGHTS, + INVALID_WIDTHS, + CONNECTION_LOST, + ZOMBIE_CONNECTION, + SHUTDOWN, + REASON_NOT_SET, + LOADING_STATE_TIMEOUT, + RESOURCE_PACK_LOADING_FAILED, + SEARCHING_FOR_SESSION_LOADING_SCREEN_FAILED, + CONN_PROTOCOL_VERSION, + SUBSYSTEM_STATUS_ERROR, + EMPTY_AUTH_FROM_DISCOVERY, + EMPTY_URL_FROM_DISCOVERY, + EXPIRED_AUTH_FROM_DISCOVERY, + UNKNOWN_SIGNAL_SERVICE_SIGN_IN_FAILURE, + XBL_JOIN_LOBBY_FAILURE, + UNSPECIFIED_CLIENT_INSTANCE_DISCONNECTION, + CONN_SESSION_NOT_FOUND, + CONN_CREATE_PEER_CONNECTION, + CONN_ICE, + CONN_CONNECT_REQUEST, + CONN_CONNECT_RESPONSE, + CONN_NEGOTIATION_TIMEOUT, + CONN_INACTIVITY_TIMEOUT, + STALE_CONNECTION_BEING_REPLACED, + REALMS_SESSION_NOT_FOUND, + BAD_PACKET +} diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerActionType.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerActionType.java index 91e1fbc96..cf67fe038 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerActionType.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerActionType.java @@ -66,5 +66,9 @@ public enum PlayerActionType { /** * @since v618 */ - STOP_FLYING + STOP_FLYING, + /** + * @since v622 + */ + RECEIVED_SERVER_DATA } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerAuthInputData.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerAuthInputData.java index d73e2c9bb..bdc1a46a5 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerAuthInputData.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerAuthInputData.java @@ -65,5 +65,9 @@ public enum PlayerAuthInputData { /** * @since v618 */ - STOP_FLYING + STOP_FLYING, + /** + * @since v622 + */ + RECEIVED_SERVER_DATA } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/SoundEvent.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/SoundEvent.java index 07981f2a7..72327242a 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/SoundEvent.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/SoundEvent.java @@ -529,6 +529,14 @@ public enum SoundEvent { * @since v618 */ AMBIENT_UNDERWATER_EXIT, + /** + * @since v622 + */ + BOTTLE_FILL, + /** + * @since v622 + */ + BOTTLE_EMPTY, UNDEFINED } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/entity/EntityFlag.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/entity/EntityFlag.java index 7fe77b67f..55ee189bb 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/entity/EntityFlag.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/entity/EntityFlag.java @@ -130,5 +130,17 @@ public enum EntityFlag { /** * @since v594 */ - CRAWLING + CRAWLING, + /** + * @since v622 + */ + TIMER_FLAG_1, + /** + * @since v622 + */ + TIMER_FLAG_2, + /** + * @since v622 + */ + TIMER_FLAG_3 } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/DisconnectPacket.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/DisconnectPacket.java index 93ffd2091..ade057f14 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/DisconnectPacket.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/DisconnectPacket.java @@ -3,12 +3,14 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cloudburstmc.protocol.bedrock.data.DisconnectFailReason; import org.cloudburstmc.protocol.common.PacketSignal; @Data @EqualsAndHashCode(doNotUseGetters = true) @ToString(doNotUseGetters = true) public class DisconnectPacket implements BedrockPacket { + private DisconnectFailReason reason = DisconnectFailReason.UNKNOWN; private boolean messageSkipped; private String kickMessage;