2020-08-11 14:00:14 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2020-08-11 14:00:14 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.network;
|
2020-08-11 14:00:14 +00:00
|
|
|
|
2021-11-14 05:07:24 +00:00
|
|
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodec;
|
|
|
|
import com.github.steveice10.mc.protocol.codec.PacketCodec;
|
2022-10-30 00:23:21 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
|
2023-06-07 14:44:18 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.codec.v589.Bedrock_v589;
|
2023-07-11 23:17:01 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.codec.v594.Bedrock_v594;
|
2023-09-12 02:22:50 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.codec.v618.Bedrock_v618;
|
2023-10-19 05:11:59 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.codec.v622.Bedrock_v622;
|
2023-11-21 22:31:56 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.codec.v630.Bedrock_v630;
|
2022-10-30 00:23:21 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.netty.codec.packet.BedrockPacketCodec;
|
2023-05-11 17:23:27 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2020-08-11 14:00:14 +00:00
|
|
|
|
2022-04-21 01:37:50 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.StringJoiner;
|
2020-08-11 14:00:14 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-14 05:07:24 +00:00
|
|
|
* Contains information about the supported protocols in Geyser.
|
2020-08-11 14:00:14 +00:00
|
|
|
*/
|
2022-03-20 02:55:29 +00:00
|
|
|
public final class GameProtocol {
|
2020-08-11 14:00:14 +00:00
|
|
|
/**
|
2020-08-29 00:11:32 +00:00
|
|
|
* Default Bedrock codec that should act as a fallback. Should represent the latest available
|
|
|
|
* release of the game that Geyser supports.
|
2020-08-11 14:00:14 +00:00
|
|
|
*/
|
2023-11-21 22:31:56 +00:00
|
|
|
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = Bedrock_v630.CODEC;
|
2023-05-24 06:33:43 +00:00
|
|
|
|
2020-08-11 14:00:14 +00:00
|
|
|
/**
|
|
|
|
* A list of all supported Bedrock versions that can join Geyser
|
|
|
|
*/
|
2022-10-30 00:23:21 +00:00
|
|
|
public static final List<BedrockCodec> SUPPORTED_BEDROCK_CODECS = new ArrayList<>();
|
2020-08-11 14:00:14 +00:00
|
|
|
|
2021-11-14 05:07:24 +00:00
|
|
|
/**
|
|
|
|
* Java codec that is supported. We only ever support one version for
|
|
|
|
* Java Edition.
|
|
|
|
*/
|
|
|
|
private static final PacketCodec DEFAULT_JAVA_CODEC = MinecraftCodec.CODEC;
|
|
|
|
|
2020-08-11 14:00:14 +00:00
|
|
|
static {
|
2023-09-12 02:22:50 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v589.CODEC.toBuilder()
|
|
|
|
.minecraftVersion("1.20.0/1.20.1")
|
|
|
|
.build());
|
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v594.CODEC.toBuilder()
|
|
|
|
.minecraftVersion("1.20.10/1.20.15")
|
|
|
|
.build());
|
2023-10-19 05:11:59 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v618.CODEC.toBuilder()
|
|
|
|
.minecraftVersion("1.20.30/1.20.32")
|
2023-11-21 22:31:56 +00:00
|
|
|
.build());
|
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v622.CODEC.toBuilder()
|
|
|
|
.minecraftVersion("1.20.40/1.20.41")
|
2023-09-29 21:14:49 +00:00
|
|
|
.build());
|
2023-10-19 05:11:59 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC);
|
2020-08-11 14:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the {@link BedrockPacketCodec} of the given protocol version.
|
|
|
|
* @param protocolVersion The protocol version to attempt to find
|
|
|
|
* @return The packet codec, or null if the client's protocol is unsupported
|
|
|
|
*/
|
2022-10-30 00:23:21 +00:00
|
|
|
public static BedrockCodec getBedrockCodec(int protocolVersion) {
|
|
|
|
for (BedrockCodec packetCodec : SUPPORTED_BEDROCK_CODECS) {
|
2020-08-11 14:00:14 +00:00
|
|
|
if (packetCodec.getProtocolVersion() == protocolVersion) {
|
|
|
|
return packetCodec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2021-07-24 00:11:50 +00:00
|
|
|
|
2023-05-11 17:23:27 +00:00
|
|
|
/* Bedrock convenience methods to gatekeep features and easily remove the check on version removal */
|
|
|
|
|
2023-07-17 18:45:45 +00:00
|
|
|
public static boolean isPre1_20_10(GeyserSession session) {
|
|
|
|
return session.getUpstream().getProtocolVersion() < Bedrock_v594.CODEC.getProtocolVersion();
|
|
|
|
}
|
|
|
|
|
2023-11-10 19:45:15 +00:00
|
|
|
/**
|
|
|
|
* @param session the session to check
|
|
|
|
* @return true if the session needs an experiment for recipe unlocking
|
|
|
|
*/
|
|
|
|
public static boolean isUsingExperimentalRecipeUnlocking(GeyserSession session) {
|
|
|
|
return session.getUpstream().getProtocolVersion() == Bedrock_v594.CODEC.getProtocolVersion();
|
|
|
|
}
|
|
|
|
|
2021-11-14 05:07:24 +00:00
|
|
|
/**
|
|
|
|
* Gets the {@link PacketCodec} for Minecraft: Java Edition.
|
|
|
|
*
|
|
|
|
* @return the packet codec for Minecraft: Java Edition
|
|
|
|
*/
|
|
|
|
public static PacketCodec getJavaCodec() {
|
|
|
|
return DEFAULT_JAVA_CODEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-12-10 21:27:23 +00:00
|
|
|
* Gets the supported Minecraft: Java Edition version names.
|
2021-11-14 05:07:24 +00:00
|
|
|
*
|
2021-12-10 21:27:23 +00:00
|
|
|
* @return the supported Minecraft: Java Edition version names
|
2021-11-14 05:07:24 +00:00
|
|
|
*/
|
2021-12-10 21:27:23 +00:00
|
|
|
public static List<String> getJavaVersions() {
|
2022-12-09 02:31:45 +00:00
|
|
|
return List.of(DEFAULT_JAVA_CODEC.getMinecraftVersion());
|
2021-11-14 05:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the supported Minecraft: Java Edition protocol version.
|
|
|
|
*
|
|
|
|
* @return the supported Minecraft: Java Edition protocol version
|
|
|
|
*/
|
|
|
|
public static int getJavaProtocolVersion() {
|
|
|
|
return DEFAULT_JAVA_CODEC.getProtocolVersion();
|
|
|
|
}
|
|
|
|
|
2022-03-20 02:55:29 +00:00
|
|
|
/**
|
|
|
|
* Gets the supported Minecraft: Java Edition version.
|
|
|
|
*
|
|
|
|
* @return the supported Minecraft: Java Edition version
|
|
|
|
*/
|
|
|
|
public static String getJavaMinecraftVersion() {
|
|
|
|
return DEFAULT_JAVA_CODEC.getMinecraftVersion();
|
|
|
|
}
|
|
|
|
|
2021-07-24 00:11:50 +00:00
|
|
|
/**
|
2021-12-10 21:27:23 +00:00
|
|
|
* @return a string showing all supported Bedrock versions for this Geyser instance
|
2021-07-24 00:11:50 +00:00
|
|
|
*/
|
2021-12-10 21:27:23 +00:00
|
|
|
public static String getAllSupportedBedrockVersions() {
|
2021-07-24 00:11:50 +00:00
|
|
|
StringJoiner joiner = new StringJoiner(", ");
|
2022-10-30 00:23:21 +00:00
|
|
|
for (BedrockCodec packetCodec : SUPPORTED_BEDROCK_CODECS) {
|
2021-07-24 00:11:50 +00:00
|
|
|
joiner.add(packetCodec.getMinecraftVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
return joiner.toString();
|
|
|
|
}
|
2021-12-04 01:26:20 +00:00
|
|
|
|
2021-12-10 21:27:23 +00:00
|
|
|
/**
|
|
|
|
* @return a string showing all supported Java versions for this Geyser instance
|
|
|
|
*/
|
|
|
|
public static String getAllSupportedJavaVersions() {
|
|
|
|
StringJoiner joiner = new StringJoiner(", ");
|
|
|
|
for (String version : getJavaVersions()) {
|
|
|
|
joiner.add(version);
|
|
|
|
}
|
|
|
|
|
|
|
|
return joiner.toString();
|
|
|
|
}
|
|
|
|
|
2022-03-20 02:55:29 +00:00
|
|
|
private GameProtocol() {
|
2021-12-04 01:26:20 +00:00
|
|
|
}
|
2020-08-11 14:00:14 +00:00
|
|
|
}
|