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;
|
2021-10-18 00:24:27 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v471.Bedrock_v471;
|
2021-11-20 19:41:29 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v475.Bedrock_v475;
|
2022-02-06 22:15:12 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v486.Bedrock_v486;
|
2020-08-11 14:00:14 +00:00
|
|
|
|
2022-02-28 15:07:45 +00:00
|
|
|
import java.util.*;
|
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-02-06 22:15:12 +00:00
|
|
|
public static final BedrockPacketCodec DEFAULT_BEDROCK_CODEC = Bedrock_v486.V486_CODEC;
|
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 {
|
2021-11-20 19:41:29 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v471.V471_CODEC);
|
2022-02-06 22:15:12 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v475.V475_CODEC.toBuilder().minecraftVersion("1.18.0/1.18.1/1.18.2").build());
|
2022-03-05 04:24:38 +00:00
|
|
|
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder()
|
|
|
|
.minecraftVersion("1.18.10/1.18.12") // 1.18.11 is also supported, but was only on Switch and since that auto-updates it's not needed
|
|
|
|
.build());
|
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
|
|
|
|
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-02-28 15:07:45 +00:00
|
|
|
return Collections.singletonList(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(", ");
|
|
|
|
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
|
|
|
}
|