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-04-21 04:36:51 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.codec.v582.Bedrock_v582;
|
2023-06-07 14:44:18 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.codec.v589.Bedrock_v589;
|
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-06-07 14:44:18 +00:00
|
|
|
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = Bedrock_v589.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-05-24 06:33:43 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v582.CODEC.toBuilder()
|
2023-04-27 17:09:15 +00:00
|
|
|
.minecraftVersion("1.19.80/1.19.81")
|
|
|
|
.build());
|
2023-05-24 06:33:43 +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 */
|
|
|
|
|
|
|
|
public static boolean isPre1_20(GeyserSession session) {
|
2023-06-07 14:44:18 +00:00
|
|
|
return session.getUpstream().getProtocolVersion() < Bedrock_v589.CODEC.getProtocolVersion();
|
2023-05-11 17:23:27 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|