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;
|
2020-08-11 14:00:14 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
|
2022-06-07 02:56:08 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v527.Bedrock_v527;
|
2022-07-10 17:33:39 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v534.Bedrock_v534;
|
2022-08-07 16:09:54 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v544.Bedrock_v544;
|
2022-09-17 20:37:30 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v554.Bedrock_v554;
|
2022-07-10 17:33:39 +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
|
|
|
*/
|
2022-08-23 17:20:57 +00:00
|
|
|
public static final BedrockPacketCodec DEFAULT_BEDROCK_CODEC = Bedrock_v544.V544_CODEC.toBuilder()
|
2022-09-03 18:03:22 +00:00
|
|
|
.minecraftVersion("1.19.22")
|
2022-08-23 17:20:57 +00:00
|
|
|
.protocolVersion(545)
|
|
|
|
.build();
|
2020-08-11 14:00:14 +00:00
|
|
|
/**
|
|
|
|
* A list of all supported Bedrock versions that can join Geyser
|
|
|
|
*/
|
2020-08-29 00:11:32 +00:00
|
|
|
public static final List<BedrockPacketCodec> 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 {
|
2022-07-10 17:33:39 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v527.V527_CODEC.toBuilder()
|
2022-06-24 01:24:26 +00:00
|
|
|
.minecraftVersion("1.19.0/1.19.2")
|
2022-04-28 00:04:13 +00:00
|
|
|
.build());
|
2022-08-10 00:30:49 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v534.V534_CODEC.toBuilder()
|
2022-07-28 22:09:35 +00:00
|
|
|
.minecraftVersion("1.19.10/1.19.11")
|
|
|
|
.build());
|
2022-08-23 17:20:57 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v544.V544_CODEC);
|
2022-09-03 18:03:22 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder()
|
|
|
|
.minecraftVersion("1.19.21/1.19.22")
|
|
|
|
.build());
|
2022-09-17 20:37:30 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v554.V554_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
|
|
|
|
*/
|
|
|
|
public static BedrockPacketCodec getBedrockCodec(int protocolVersion) {
|
|
|
|
for (BedrockPacketCodec packetCodec : SUPPORTED_BEDROCK_CODECS) {
|
|
|
|
if (packetCodec.getProtocolVersion() == protocolVersion) {
|
|
|
|
return packetCodec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2021-07-24 00:11:50 +00:00
|
|
|
|
2022-07-10 17:33:39 +00:00
|
|
|
/* Bedrock convenience methods to gatekeep features and easily remove the check on version removal */
|
|
|
|
|
|
|
|
public static boolean supports1_19_10(GeyserSession session) {
|
|
|
|
return session.getUpstream().getProtocolVersion() >= Bedrock_v534.V534_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-08-05 15:29:47 +00:00
|
|
|
return List.of(DEFAULT_JAVA_CODEC.getMinecraftVersion(), "1.19.2");
|
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(", ");
|
|
|
|
for (BedrockPacketCodec packetCodec : SUPPORTED_BEDROCK_CODECS) {
|
|
|
|
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
|
|
|
}
|