geforkt von Mirrors/Velocity
Rework and expose ProtocolVersion to the API
Dieser Commit ist enthalten in:
Ursprung
74ee716480
Commit
6b4c809c39
138
api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java
Normale Datei
138
api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java
Normale Datei
@ -0,0 +1,138 @@
|
||||
package com.velocitypowered.api.network;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents each Minecraft protocol version
|
||||
*/
|
||||
public enum ProtocolVersion {
|
||||
UNKNOWN(-1, "Unknown"),
|
||||
LEGACY(-1, "Legacy"),
|
||||
MINECRAFT_1_8(47, "1.8"),
|
||||
MINECRAFT_1_9(107, "1.9"),
|
||||
MINECRAFT_1_9_1(108, "1.9.1"),
|
||||
MINECRAFT_1_9_2(109, "1.9.2"),
|
||||
MINECRAFT_1_9_4(110, "1.9.4"),
|
||||
MINECRAFT_1_10(210, "1.10"),
|
||||
MINECRAFT_1_11(315, "1.11"),
|
||||
MINECRAFT_1_11_1(316, "1.11.1"),
|
||||
MINECRAFT_1_12(335, "1.12"),
|
||||
MINECRAFT_1_12_1(338, "1.12.1"),
|
||||
MINECRAFT_1_12_2(340, "1.12.2"),
|
||||
MINECRAFT_1_13(393, "1.13"),
|
||||
MINECRAFT_1_13_1(401, "1.13.1"),
|
||||
MINECRAFT_1_13_2(404, "1.13.2");
|
||||
|
||||
private final int protocol;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Represents the lowest supported version
|
||||
*/
|
||||
public static final ProtocolVersion MINIMUM_VERSION = MINECRAFT_1_8;
|
||||
/**
|
||||
* Represents the highest supported version
|
||||
*/
|
||||
public static final ProtocolVersion MAXIMUM_VERSION = MINECRAFT_1_13_2;
|
||||
|
||||
/**
|
||||
* The user-friendly representation of the lowest and highest supported versions
|
||||
*/
|
||||
public static final String SUPPORTED_VERSION_STRING = String.format("%s-%s", MINIMUM_VERSION, MAXIMUM_VERSION);
|
||||
|
||||
/**
|
||||
* A map linking the protocol version number to its {@link ProtocolVersion} representation
|
||||
*/
|
||||
public static final ImmutableMap<Integer, ProtocolVersion> ID_TO_PROTOCOL_CONSTANT;
|
||||
|
||||
static {
|
||||
Map<Integer, ProtocolVersion> versions = new HashMap<>();
|
||||
for (ProtocolVersion version : values()) {
|
||||
versions.put(version.protocol, version);
|
||||
}
|
||||
|
||||
ID_TO_PROTOCOL_CONSTANT = ImmutableMap.copyOf(versions);
|
||||
}
|
||||
|
||||
ProtocolVersion(int protocol, String name) {
|
||||
this.protocol = protocol;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol as an int
|
||||
*
|
||||
* @return the protocol version
|
||||
*/
|
||||
public int getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user-friendly name for this protocol
|
||||
*
|
||||
* @return the protocol name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link ProtocolVersion} for the given protocol
|
||||
*
|
||||
* @param protocol the protocol as an int
|
||||
* @return the protocol version
|
||||
*/
|
||||
public static ProtocolVersion getProtocolVersion(int protocol) {
|
||||
return ID_TO_PROTOCOL_CONSTANT.getOrDefault(protocol, UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the protocol is supported
|
||||
*
|
||||
* @param protocol the protocol as an int
|
||||
* @return if the protocol supported
|
||||
*/
|
||||
public static boolean isSupported(int protocol) {
|
||||
ProtocolVersion version = ID_TO_PROTOCOL_CONSTANT.get(protocol);
|
||||
|
||||
return version != null && !version.isUnknown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the {@link ProtocolVersion} is supported
|
||||
*
|
||||
* @param version the protocol version
|
||||
* @return if the protocol supported
|
||||
*/
|
||||
public static boolean isSupported(ProtocolVersion version) {
|
||||
return version != null && !version.isUnknown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this {@link ProtocolVersion} is unknown to the proxy
|
||||
*
|
||||
* @return if the protocol is unknown
|
||||
*/
|
||||
public boolean isUnknown() {
|
||||
return this == UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this {@link ProtocolVersion} is a legacy protocol
|
||||
*
|
||||
* @return if the protocol is legacy
|
||||
*/
|
||||
public boolean isLegacy() {
|
||||
return this == LEGACY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.velocitypowered.api.proxy;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -34,5 +36,5 @@ public interface InboundConnection {
|
||||
*
|
||||
* @return the protocol version the connection uses
|
||||
*/
|
||||
int getProtocolVersion();
|
||||
ProtocolVersion getProtocolVersion();
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import net.kyori.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
|
@ -10,13 +10,13 @@ import static com.velocitypowered.proxy.network.Connections.MINECRAFT_DECODER;
|
||||
import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.natives.compression.VelocityCompressor;
|
||||
import com.velocitypowered.natives.encryption.VelocityCipher;
|
||||
import com.velocitypowered.natives.encryption.VelocityCipherFactory;
|
||||
import com.velocitypowered.natives.util.Natives;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder;
|
||||
@ -53,8 +53,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
|
||||
private SocketAddress remoteAddress;
|
||||
private StateRegistry state;
|
||||
private @Nullable MinecraftSessionHandler sessionHandler;
|
||||
private int protocolVersion;
|
||||
private int nextProtocolVersion;
|
||||
private ProtocolVersion protocolVersion;
|
||||
private ProtocolVersion nextProtocolVersion;
|
||||
private @Nullable MinecraftConnectionAssociation association;
|
||||
private boolean isLegacyForge;
|
||||
private final VelocityServer server;
|
||||
@ -204,14 +204,14 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
|
||||
this.channel.pipeline().get(MinecraftDecoder.class).setState(state);
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
public void setProtocolVersion(int protocolVersion) {
|
||||
public void setProtocolVersion(ProtocolVersion protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.nextProtocolVersion = protocolVersion;
|
||||
if (protocolVersion != ProtocolConstants.LEGACY) {
|
||||
if (protocolVersion != ProtocolVersion.LEGACY) {
|
||||
this.channel.pipeline().get(MinecraftEncoder.class).setProtocolVersion(protocolVersion);
|
||||
this.channel.pipeline().get(MinecraftDecoder.class).setProtocolVersion(protocolVersion);
|
||||
} else {
|
||||
@ -295,11 +295,11 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
|
||||
this.canSendLegacyFmlResetPacket = isLegacyForge && canSendLegacyFMLResetPacket;
|
||||
}
|
||||
|
||||
public int getNextProtocolVersion() {
|
||||
public ProtocolVersion getNextProtocolVersion() {
|
||||
return this.nextProtocolVersion;
|
||||
}
|
||||
|
||||
public void setNextProtocolVersion(int nextProtocolVersion) {
|
||||
public void setNextProtocolVersion(ProtocolVersion nextProtocolVersion) {
|
||||
this.nextProtocolVersion = nextProtocolVersion;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.velocitypowered.proxy.connection.backend;
|
||||
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
@ -9,7 +10,6 @@ import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler;
|
||||
import com.velocitypowered.proxy.connection.forge.ForgeConstants;
|
||||
import com.velocitypowered.proxy.connection.util.ConnectionMessages;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.packet.BossBar;
|
||||
import com.velocitypowered.proxy.protocol.packet.Disconnect;
|
||||
import com.velocitypowered.proxy.protocol.packet.JoinGame;
|
||||
@ -171,7 +171,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
return false;
|
||||
}
|
||||
boolean minecraftOrFmlMessage;
|
||||
if (mc.getProtocolVersion() <= ProtocolConstants.MINECRAFT_1_12_2) {
|
||||
if (mc.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_12_2) <= 0) {
|
||||
String channel = message.getChannel();
|
||||
minecraftOrFmlMessage = channel.startsWith("MC|") || channel
|
||||
.startsWith(ForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL);
|
||||
|
@ -14,12 +14,13 @@ import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
|
||||
@ -69,9 +70,9 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
||||
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
|
||||
.addLast(MINECRAFT_DECODER,
|
||||
new MinecraftDecoder(ProtocolConstants.Direction.CLIENTBOUND))
|
||||
new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND))
|
||||
.addLast(MINECRAFT_ENCODER,
|
||||
new MinecraftEncoder(ProtocolConstants.Direction.SERVERBOUND));
|
||||
new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND));
|
||||
|
||||
MinecraftConnection mc = new MinecraftConnection(ch, server);
|
||||
mc.setState(StateRegistry.HANDSHAKE);
|
||||
@ -137,7 +138,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
handshake.setPort(registeredServer.getServerInfo().getAddress().getPort());
|
||||
mc.write(handshake);
|
||||
|
||||
int protocolVersion = proxyPlayer.getConnection().getNextProtocolVersion();
|
||||
ProtocolVersion protocolVersion = proxyPlayer.getConnection().getNextProtocolVersion();
|
||||
mc.setProtocolVersion(protocolVersion);
|
||||
mc.setState(StateRegistry.LOGIN);
|
||||
mc.write(new ServerLogin(proxyPlayer.getUsername()));
|
||||
|
@ -4,6 +4,7 @@ import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.util.ModInfo;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
@ -11,7 +12,6 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.connection.forge.ForgeConstants;
|
||||
import com.velocitypowered.proxy.connection.forge.ForgeUtil;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.packet.BossBar;
|
||||
import com.velocitypowered.proxy.protocol.packet.Chat;
|
||||
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
|
||||
@ -335,9 +335,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
serverBossBars.clear();
|
||||
|
||||
// Tell the server about this client's plugin message channels.
|
||||
int serverVersion = serverMc.getProtocolVersion();
|
||||
ProtocolVersion serverVersion = serverMc.getProtocolVersion();
|
||||
Collection<String> toRegister = new HashSet<>(knownChannels);
|
||||
if (serverVersion >= ProtocolConstants.MINECRAFT_1_13) {
|
||||
if (serverVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) {
|
||||
toRegister.addAll(server.getChannelRegistrar().getModernChannelIds());
|
||||
} else {
|
||||
toRegister.addAll(server.getChannelRegistrar().getIdsForLegacyConnections());
|
||||
|
@ -22,6 +22,7 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.MessagePosition;
|
||||
import com.velocitypowered.api.util.ModInfo;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.util.title.TextTitle;
|
||||
import com.velocitypowered.api.util.title.Title;
|
||||
import com.velocitypowered.api.util.title.Titles;
|
||||
@ -32,7 +33,6 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.connection.forge.ForgeConstants;
|
||||
import com.velocitypowered.proxy.connection.util.ConnectionMessages;
|
||||
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.packet.Chat;
|
||||
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
|
||||
import com.velocitypowered.proxy.protocol.packet.Disconnect;
|
||||
@ -164,7 +164,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProtocolVersion() {
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
return connection.getProtocolVersion();
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
byte pos = (byte) position.ordinal();
|
||||
String json;
|
||||
if (position == MessagePosition.ACTION_BAR) {
|
||||
if (getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_11) {
|
||||
if (getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) {
|
||||
// We can use the title packet instead.
|
||||
TitlePacket pkt = new TitlePacket();
|
||||
pkt.setAction(TitlePacket.SET_ACTION_BAR);
|
||||
|
@ -6,13 +6,13 @@ import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.packet.Disconnect;
|
||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||
@ -40,11 +40,11 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(LegacyPing packet) {
|
||||
connection.setProtocolVersion(ProtocolConstants.LEGACY);
|
||||
connection.setProtocolVersion(ProtocolVersion.LEGACY);
|
||||
VelocityConfiguration configuration = server.getConfiguration();
|
||||
ServerPing ping = new ServerPing(
|
||||
new ServerPing.Version(ProtocolConstants.MAXIMUM_GENERIC_VERSION,
|
||||
"Velocity " + ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING),
|
||||
new ServerPing.Version(ProtocolVersion.MAXIMUM_VERSION.getProtocol(),
|
||||
"Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING),
|
||||
new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(),
|
||||
ImmutableList.of()),
|
||||
configuration.getMotdComponent(),
|
||||
@ -82,7 +82,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
connection.setState(StateRegistry.LOGIN);
|
||||
connection.setProtocolVersion(handshake.getProtocolVersion());
|
||||
|
||||
if (!ProtocolConstants.isSupported(handshake.getProtocolVersion())) {
|
||||
if (!ProtocolVersion.isSupported(handshake.getProtocolVersion())) {
|
||||
connection.closeWith(Disconnect
|
||||
.create(TranslatableComponent.of("multiplayer.disconnect.outdated_client")));
|
||||
return true;
|
||||
@ -110,7 +110,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2
|
||||
// and lower, otherwise IP information will never get forwarded.
|
||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
||||
&& handshake.getProtocolVersion() < ProtocolConstants.MINECRAFT_1_13) {
|
||||
&& handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) {
|
||||
connection.closeWith(Disconnect
|
||||
.create(TextComponent.of("This server is only compatible with 1.13 and above.")));
|
||||
return true;
|
||||
@ -165,8 +165,8 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProtocolVersion() {
|
||||
return 0;
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
return ProtocolVersion.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.velocitypowered.proxy.connection.client;
|
||||
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -35,7 +36,7 @@ class InitialInboundConnection implements InboundConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProtocolVersion() {
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
return connection.getProtocolVersion();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.velocitypowered.proxy.connection.client;
|
||||
import static com.velocitypowered.proxy.VelocityServer.GSON;
|
||||
import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY;
|
||||
import static com.velocitypowered.proxy.connection.VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.*;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.*;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||
@ -15,10 +15,12 @@ import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.packet.Disconnect;
|
||||
import com.velocitypowered.proxy.protocol.packet.EncryptionRequest;
|
||||
@ -73,7 +75,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
@Override
|
||||
public boolean handle(ServerLogin packet) {
|
||||
this.login = packet;
|
||||
if (inbound.getProtocolVersion() >= MINECRAFT_1_13) {
|
||||
if (inbound.getProtocolVersion().compareTo(MINECRAFT_1_13) >= 0) {
|
||||
playerInfoId = ThreadLocalRandom.current().nextInt();
|
||||
inbound.write(new LoginPluginMessage(playerInfoId, VELOCITY_IP_FORWARDING_CHANNEL,
|
||||
Unpooled.EMPTY_BUFFER));
|
||||
|
@ -5,11 +5,11 @@ import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.api.util.ModInfo;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.packet.StatusPing;
|
||||
import com.velocitypowered.proxy.protocol.packet.StatusRequest;
|
||||
import com.velocitypowered.proxy.protocol.packet.StatusResponse;
|
||||
@ -38,11 +38,12 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
public boolean handle(StatusRequest packet) {
|
||||
VelocityConfiguration configuration = server.getConfiguration();
|
||||
|
||||
int shownVersion = ProtocolConstants.isSupported(connection.getProtocolVersion())
|
||||
? connection.getProtocolVersion() : ProtocolConstants.MAXIMUM_GENERIC_VERSION;
|
||||
ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion()) ? connection
|
||||
.getProtocolVersion() :
|
||||
ProtocolVersion.MAXIMUM_VERSION;
|
||||
ServerPing initialPing = new ServerPing(
|
||||
new ServerPing.Version(shownVersion,
|
||||
"Velocity " + ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING),
|
||||
new ServerPing.Version(shownVersion.getProtocol(),
|
||||
"Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING),
|
||||
new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(),
|
||||
ImmutableList.of()),
|
||||
configuration.getMotdComponent(),
|
||||
|
@ -11,7 +11,7 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.netty.LegacyPingDecoder;
|
||||
import com.velocitypowered.proxy.protocol.netty.LegacyPingEncoder;
|
||||
@ -44,8 +44,8 @@ public class ServerChannelInitializer extends ChannelInitializer<Channel> {
|
||||
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
||||
.addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE)
|
||||
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
|
||||
.addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolConstants.Direction.SERVERBOUND))
|
||||
.addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolConstants.Direction.CLIENTBOUND));
|
||||
.addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.SERVERBOUND))
|
||||
.addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolUtils.Direction.CLIENTBOUND));
|
||||
|
||||
final MinecraftConnection connection = new MinecraftConnection(ch, this.server);
|
||||
connection.setState(StateRegistry.HANDSHAKE);
|
||||
|
@ -1,13 +1,14 @@
|
||||
package com.velocitypowered.proxy.protocol;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public interface MinecraftPacket {
|
||||
|
||||
void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion);
|
||||
void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion);
|
||||
|
||||
void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion);
|
||||
void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion);
|
||||
|
||||
boolean handle(MinecraftSessionHandler handler);
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
package com.velocitypowered.proxy.protocol;
|
||||
|
||||
import com.google.common.primitives.ImmutableIntArray;
|
||||
|
||||
public enum ProtocolConstants {
|
||||
;
|
||||
public static final int LEGACY = -1;
|
||||
|
||||
public static final int MINECRAFT_1_8 = 47;
|
||||
public static final int MINECRAFT_1_9 = 107;
|
||||
public static final int MINECRAFT_1_9_1 = 108;
|
||||
public static final int MINECRAFT_1_9_2 = 109;
|
||||
public static final int MINECRAFT_1_9_4 = 110;
|
||||
public static final int MINECRAFT_1_10 = 210;
|
||||
public static final int MINECRAFT_1_11 = 315;
|
||||
public static final int MINECRAFT_1_11_1 = 316;
|
||||
public static final int MINECRAFT_1_12 = 335;
|
||||
public static final int MINECRAFT_1_12_1 = 338;
|
||||
public static final int MINECRAFT_1_12_2 = 340;
|
||||
public static final int MINECRAFT_1_13 = 393;
|
||||
public static final int MINECRAFT_1_13_1 = 401;
|
||||
public static final int MINECRAFT_1_13_2 = 404;
|
||||
|
||||
public static final int MINIMUM_GENERIC_VERSION = MINECRAFT_1_8;
|
||||
public static final int MAXIMUM_GENERIC_VERSION = MINECRAFT_1_13_2;
|
||||
|
||||
public static final String SUPPORTED_GENERIC_VERSION_STRING = "1.8-1.13.2";
|
||||
|
||||
public static final ImmutableIntArray SUPPORTED_VERSIONS = ImmutableIntArray.of(
|
||||
MINECRAFT_1_8,
|
||||
MINECRAFT_1_9,
|
||||
MINECRAFT_1_9_1,
|
||||
MINECRAFT_1_9_2,
|
||||
MINECRAFT_1_9_4,
|
||||
MINECRAFT_1_10,
|
||||
MINECRAFT_1_11,
|
||||
MINECRAFT_1_11_1,
|
||||
MINECRAFT_1_12,
|
||||
MINECRAFT_1_12_1,
|
||||
MINECRAFT_1_12_2,
|
||||
MINECRAFT_1_13,
|
||||
MINECRAFT_1_13_1,
|
||||
MINECRAFT_1_13_2
|
||||
);
|
||||
|
||||
public static boolean isSupported(int version) {
|
||||
return SUPPORTED_VERSIONS.contains(version);
|
||||
}
|
||||
|
||||
public enum Direction {
|
||||
SERVERBOUND,
|
||||
CLIENTBOUND;
|
||||
|
||||
public StateRegistry.PacketRegistry.ProtocolVersion getProtocol(StateRegistry state,
|
||||
int protocolVersion) {
|
||||
return (this == SERVERBOUND ? state.SERVERBOUND : state.CLIENTBOUND)
|
||||
.getVersion(protocolVersion);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,8 +2,10 @@ package com.velocitypowered.proxy.protocol;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -119,4 +121,15 @@ public enum ProtocolUtils {
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
public enum Direction {
|
||||
SERVERBOUND,
|
||||
CLIENTBOUND;
|
||||
|
||||
public StateRegistry.PacketRegistry.ProtocolRegistry getProtocolRegistry(StateRegistry state,
|
||||
ProtocolVersion protocolVersion) {
|
||||
return (this == SERVERBOUND ? state.SERVERBOUND : state.CLIENTBOUND)
|
||||
.getProtocolRegistry(protocolVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,26 @@
|
||||
package com.velocitypowered.proxy.protocol;
|
||||
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.Direction;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_10;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_11;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_11_1;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12_1;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12_2;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_13;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_13_1;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_13_2;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_8;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_9;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_9_1;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_9_2;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_9_4;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINIMUM_GENERIC_VERSION;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolUtils.Direction;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_10;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_11;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_11_1;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12_1;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12_2;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13_1;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13_2;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_8;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_1;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_2;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_4;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION;
|
||||
|
||||
import com.google.common.primitives.ImmutableIntArray;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.protocol.packet.BossBar;
|
||||
import com.velocitypowered.proxy.protocol.packet.Chat;
|
||||
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
|
||||
@ -46,8 +49,10 @@ import io.netty.util.collection.IntObjectHashMap;
|
||||
import io.netty.util.collection.IntObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public enum StateRegistry {
|
||||
@ -195,38 +200,40 @@ public enum StateRegistry {
|
||||
|
||||
public static class PacketRegistry {
|
||||
|
||||
private static final IntObjectMap<ImmutableIntArray> LINKED_PROTOCOL_VERSIONS = new IntObjectHashMap<>();
|
||||
private static final EnumMap<ProtocolVersion, ImmutableList<ProtocolVersion>> LINKED_PROTOCOL_VERSIONS = new EnumMap(ProtocolVersion.class);
|
||||
|
||||
static {
|
||||
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9,
|
||||
ImmutableIntArray.of(MINECRAFT_1_9_1, MINECRAFT_1_9_2, MINECRAFT_1_9_4));
|
||||
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9_4,
|
||||
ImmutableIntArray.of(MINECRAFT_1_10, MINECRAFT_1_11, MINECRAFT_1_11_1));
|
||||
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12, ImmutableIntArray.of(MINECRAFT_1_12_1));
|
||||
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12_1, ImmutableIntArray.of(MINECRAFT_1_12_2));
|
||||
LINKED_PROTOCOL_VERSIONS
|
||||
.put(MINECRAFT_1_13, ImmutableIntArray.of(MINECRAFT_1_13_1, MINECRAFT_1_13_2));
|
||||
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9, ImmutableList.of(MINECRAFT_1_9_1, MINECRAFT_1_9_2, MINECRAFT_1_9_4));
|
||||
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9_4, ImmutableList.of(MINECRAFT_1_10, MINECRAFT_1_11, MINECRAFT_1_11_1));
|
||||
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12, ImmutableList.of(MINECRAFT_1_12_1));
|
||||
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12_1, ImmutableList.of(MINECRAFT_1_12_2));
|
||||
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_13, ImmutableList.of(MINECRAFT_1_13_1, MINECRAFT_1_13_2));
|
||||
}
|
||||
|
||||
private final Direction direction;
|
||||
private final IntObjectMap<ProtocolVersion> versions = new IntObjectHashMap<>(16);
|
||||
private final Map<ProtocolVersion, ProtocolRegistry> versions;
|
||||
private boolean fallback = true;
|
||||
|
||||
PacketRegistry(Direction direction) {
|
||||
this.direction = direction;
|
||||
ProtocolConstants.SUPPORTED_VERSIONS
|
||||
.forEach(version -> versions.put(version, new ProtocolVersion(version)));
|
||||
|
||||
EnumMap<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap(ProtocolVersion.class);
|
||||
for (ProtocolVersion version : ProtocolVersion.values()) {
|
||||
mutableVersions.put(version, new ProtocolRegistry(version));
|
||||
}
|
||||
|
||||
this.versions = Collections.unmodifiableMap(mutableVersions);
|
||||
}
|
||||
|
||||
public ProtocolVersion getVersion(final int version) {
|
||||
ProtocolVersion result = versions.get(version);
|
||||
if (result == null) {
|
||||
public ProtocolRegistry getProtocolRegistry(final ProtocolVersion version) {
|
||||
ProtocolRegistry registry = versions.get(version);
|
||||
if (registry == null) {
|
||||
if (fallback) {
|
||||
return getVersion(MINIMUM_GENERIC_VERSION);
|
||||
return getProtocolRegistry(MINIMUM_VERSION);
|
||||
}
|
||||
throw new IllegalArgumentException("Could not find data for protocol version " + version);
|
||||
}
|
||||
return result;
|
||||
return registry;
|
||||
}
|
||||
|
||||
public <P extends MinecraftPacket> void register(Class<P> clazz, Supplier<P> packetSupplier,
|
||||
@ -236,20 +243,20 @@ public enum StateRegistry {
|
||||
}
|
||||
|
||||
for (final PacketMapping mapping : mappings) {
|
||||
ProtocolVersion version = this.versions.get(mapping.protocolVersion);
|
||||
if (version == null) {
|
||||
ProtocolRegistry registry = this.versions.get(mapping.protocolVersion);
|
||||
if (registry == null) {
|
||||
throw new IllegalArgumentException("Unknown protocol version " + mapping.protocolVersion);
|
||||
}
|
||||
if (!mapping.encodeOnly) {
|
||||
version.packetIdToSupplier.put(mapping.id, packetSupplier);
|
||||
registry.packetIdToSupplier.put(mapping.id, packetSupplier);
|
||||
}
|
||||
version.packetClassToId.put(clazz, mapping.id);
|
||||
registry.packetClassToId.put(clazz, mapping.id);
|
||||
|
||||
ImmutableIntArray linked = LINKED_PROTOCOL_VERSIONS.get(mapping.protocolVersion);
|
||||
ImmutableList<ProtocolVersion> linked = LINKED_PROTOCOL_VERSIONS.get(mapping.protocolVersion);
|
||||
if (linked != null) {
|
||||
links:
|
||||
for (int i = 0; i < linked.length(); i++) {
|
||||
int linkedVersion = linked.get(i);
|
||||
for (int i = 0; i < linked.size(); i++) {
|
||||
ProtocolVersion linkedVersion = linked.get(i);
|
||||
// Make sure that later mappings override this one.
|
||||
for (PacketMapping m : mappings) {
|
||||
if (linkedVersion == m.protocolVersion) {
|
||||
@ -262,15 +269,15 @@ public enum StateRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public class ProtocolVersion {
|
||||
public class ProtocolRegistry {
|
||||
|
||||
public final int version;
|
||||
public final ProtocolVersion version;
|
||||
final IntObjectMap<Supplier<? extends MinecraftPacket>> packetIdToSupplier =
|
||||
new IntObjectHashMap<>(16, 0.5f);
|
||||
final Object2IntMap<Class<? extends MinecraftPacket>> packetClassToId =
|
||||
new Object2IntOpenHashMap<>(16, 0.5f);
|
||||
|
||||
ProtocolVersion(final int version) {
|
||||
ProtocolRegistry(final ProtocolVersion version) {
|
||||
this.version = version;
|
||||
this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE);
|
||||
}
|
||||
@ -299,10 +306,10 @@ public enum StateRegistry {
|
||||
public static class PacketMapping {
|
||||
|
||||
private final int id;
|
||||
private final int protocolVersion;
|
||||
private final ProtocolVersion protocolVersion;
|
||||
private final boolean encodeOnly;
|
||||
|
||||
public PacketMapping(int id, int protocolVersion, boolean packetDecoding) {
|
||||
public PacketMapping(int id, ProtocolVersion protocolVersion, boolean packetDecoding) {
|
||||
this.id = id;
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.encodeOnly = packetDecoding;
|
||||
@ -345,7 +352,7 @@ public enum StateRegistry {
|
||||
* @param encodeOnly When true packet decoding will be disabled
|
||||
* @return PacketMapping with the provided arguments
|
||||
*/
|
||||
private static PacketMapping map(int id, int version, boolean encodeOnly) {
|
||||
private static PacketMapping map(int id, ProtocolVersion version, boolean encodeOnly) {
|
||||
return new PacketMapping(id, version, encodeOnly);
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,8 @@ import com.velocitypowered.api.event.query.ProxyQueryEvent;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.QueryResponse;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
@ -73,7 +73,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
return QueryResponse.builder()
|
||||
.hostname(ComponentSerializers.PLAIN
|
||||
.serialize(server.getConfiguration().getMotdComponent()))
|
||||
.gameVersion(ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING)
|
||||
.gameVersion(ProtocolVersion.SUPPORTED_VERSION_STRING)
|
||||
.map(server.getConfiguration().getQueryMap())
|
||||
.currentPlayers(server.getPlayerCount())
|
||||
.maxPlayers(server.getConfiguration().getShowMaxPlayers())
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.netty;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@ -13,14 +13,14 @@ import java.util.List;
|
||||
|
||||
public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
|
||||
private final ProtocolConstants.Direction direction;
|
||||
private final ProtocolUtils.Direction direction;
|
||||
private StateRegistry state;
|
||||
private StateRegistry.PacketRegistry.ProtocolVersion protocolVersion;
|
||||
private StateRegistry.PacketRegistry.ProtocolRegistry registry;
|
||||
|
||||
public MinecraftDecoder(ProtocolConstants.Direction direction) {
|
||||
public MinecraftDecoder(ProtocolUtils.Direction direction) {
|
||||
this.direction = Preconditions.checkNotNull(direction, "direction");
|
||||
this.protocolVersion = direction
|
||||
.getProtocol(StateRegistry.HANDSHAKE, ProtocolConstants.MINIMUM_GENERIC_VERSION);
|
||||
this.registry = direction
|
||||
.getProtocolRegistry(StateRegistry.HANDSHAKE, ProtocolVersion.MINIMUM_VERSION);
|
||||
this.state = StateRegistry.HANDSHAKE;
|
||||
}
|
||||
|
||||
@ -33,35 +33,35 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
ByteBuf slice = msg.slice();
|
||||
|
||||
int packetId = ProtocolUtils.readVarInt(msg);
|
||||
MinecraftPacket packet = this.protocolVersion.createPacket(packetId);
|
||||
MinecraftPacket packet = this.registry.createPacket(packetId);
|
||||
if (packet == null) {
|
||||
msg.skipBytes(msg.readableBytes());
|
||||
out.add(slice.retain());
|
||||
} else {
|
||||
try {
|
||||
packet.decode(msg, direction, protocolVersion.version);
|
||||
packet.decode(msg, direction, registry.version);
|
||||
} catch (Exception e) {
|
||||
throw new CorruptedFrameException(
|
||||
"Error decoding " + packet.getClass() + " Direction " + direction
|
||||
+ " Protocol " + protocolVersion.version + " State " + state + " ID " + Integer
|
||||
+ " Protocol " + registry.version + " State " + state + " ID " + Integer
|
||||
.toHexString(packetId), e);
|
||||
}
|
||||
if (msg.isReadable()) {
|
||||
throw new CorruptedFrameException(
|
||||
"Did not read full packet for " + packet.getClass() + " Direction " + direction
|
||||
+ " Protocol " + protocolVersion.version + " State " + state + " ID " + Integer
|
||||
+ " Protocol " + registry.version + " State " + state + " ID " + Integer
|
||||
.toHexString(packetId));
|
||||
}
|
||||
out.add(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void setProtocolVersion(int protocolVersion) {
|
||||
this.protocolVersion = direction.getProtocol(state, protocolVersion);
|
||||
public void setProtocolVersion(ProtocolVersion protocolVersion) {
|
||||
this.registry = direction.getProtocolRegistry(state, protocolVersion);
|
||||
}
|
||||
|
||||
public void setState(StateRegistry state) {
|
||||
this.state = state;
|
||||
this.setProtocolVersion(protocolVersion.version);
|
||||
this.setProtocolVersion(registry.version);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.netty;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@ -11,30 +11,30 @@ import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
public class MinecraftEncoder extends MessageToByteEncoder<MinecraftPacket> {
|
||||
|
||||
private final ProtocolConstants.Direction direction;
|
||||
private final ProtocolUtils.Direction direction;
|
||||
private StateRegistry state;
|
||||
private StateRegistry.PacketRegistry.ProtocolVersion protocolVersion;
|
||||
private StateRegistry.PacketRegistry.ProtocolRegistry registry;
|
||||
|
||||
public MinecraftEncoder(ProtocolConstants.Direction direction) {
|
||||
public MinecraftEncoder(ProtocolUtils.Direction direction) {
|
||||
this.direction = Preconditions.checkNotNull(direction, "direction");
|
||||
this.protocolVersion = direction
|
||||
.getProtocol(StateRegistry.HANDSHAKE, ProtocolConstants.MINIMUM_GENERIC_VERSION);
|
||||
this.registry = direction
|
||||
.getProtocolRegistry(StateRegistry.HANDSHAKE, ProtocolVersion.MINIMUM_VERSION);
|
||||
this.state = StateRegistry.HANDSHAKE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, MinecraftPacket msg, ByteBuf out) {
|
||||
int packetId = this.protocolVersion.getPacketId(msg);
|
||||
int packetId = this.registry.getPacketId(msg);
|
||||
ProtocolUtils.writeVarInt(out, packetId);
|
||||
msg.encode(out, direction, protocolVersion.version);
|
||||
msg.encode(out, direction, registry.version);
|
||||
}
|
||||
|
||||
public void setProtocolVersion(final int protocolVersion) {
|
||||
this.protocolVersion = direction.getProtocol(state, protocolVersion);
|
||||
public void setProtocolVersion(final ProtocolVersion protocolVersion) {
|
||||
this.registry = direction.getProtocolRegistry(state, protocolVersion);
|
||||
}
|
||||
|
||||
public void setState(StateRegistry state) {
|
||||
this.state = state;
|
||||
this.setProtocolVersion(protocolVersion.version);
|
||||
this.setProtocolVersion(registry.version);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
@ -97,7 +97,7 @@ public class BossBar implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.uuid = ProtocolUtils.readUuid(buf);
|
||||
this.action = ProtocolUtils.readVarInt(buf);
|
||||
switch (action) {
|
||||
@ -129,7 +129,7 @@ public class BossBar implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (uuid == null) {
|
||||
throw new IllegalStateException("No boss bar UUID specified");
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.text.Component;
|
||||
@ -54,20 +54,20 @@ public class Chat implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
message = ProtocolUtils.readString(buf);
|
||||
if (direction == ProtocolConstants.Direction.CLIENTBOUND) {
|
||||
if (direction == ProtocolUtils.Direction.CLIENTBOUND) {
|
||||
type = buf.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (message == null) {
|
||||
throw new IllegalStateException("Message is not specified");
|
||||
}
|
||||
ProtocolUtils.writeString(buf, message);
|
||||
if (direction == ProtocolConstants.Direction.CLIENTBOUND) {
|
||||
if (direction == ProtocolUtils.Direction.CLIENTBOUND) {
|
||||
buf.writeByte(type);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -93,20 +93,20 @@ public class ClientSettings implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.locale = ProtocolUtils.readString(buf, 16);
|
||||
this.viewDistance = buf.readByte();
|
||||
this.chatVisibility = ProtocolUtils.readVarInt(buf);
|
||||
this.chatColors = buf.readBoolean();
|
||||
this.skinParts = buf.readUnsignedByte();
|
||||
|
||||
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
this.mainHand = ProtocolUtils.readVarInt(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (locale == null) {
|
||||
throw new IllegalStateException("No locale specified");
|
||||
}
|
||||
@ -116,7 +116,7 @@ public class ClientSettings implements MinecraftPacket {
|
||||
buf.writeBoolean(chatColors);
|
||||
buf.writeByte(skinParts);
|
||||
|
||||
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
ProtocolUtils.writeVarInt(buf, mainHand);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.text.Component;
|
||||
@ -40,12 +40,12 @@ public class Disconnect implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
reason = ProtocolUtils.readString(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (reason == null) {
|
||||
throw new IllegalStateException("No reason specified.");
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Arrays;
|
||||
@ -40,14 +40,14 @@ public class EncryptionRequest implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.serverId = ProtocolUtils.readString(buf, 20);
|
||||
publicKey = ProtocolUtils.readByteArray(buf, 256);
|
||||
verifyToken = ProtocolUtils.readByteArray(buf, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeString(buf, this.serverId);
|
||||
ProtocolUtils.writeByteArray(buf, publicKey);
|
||||
ProtocolUtils.writeByteArray(buf, verifyToken);
|
||||
|
@ -2,9 +2,9 @@ package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Arrays;
|
||||
@ -39,13 +39,13 @@ public class EncryptionResponse implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.sharedSecret = ProtocolUtils.readByteArray(buf, 256);
|
||||
this.verifyToken = ProtocolUtils.readByteArray(buf, 128);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeByteArray(buf, sharedSecret);
|
||||
ProtocolUtils.writeByteArray(buf, verifyToken);
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class Handshake implements MinecraftPacket {
|
||||
|
||||
private int protocolVersion;
|
||||
private ProtocolVersion protocolVersion;
|
||||
private String serverAddress = "";
|
||||
private int port;
|
||||
private int nextStatus;
|
||||
|
||||
public int getProtocolVersion() {
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
public void setProtocolVersion(int protocolVersion) {
|
||||
public void setProtocolVersion(ProtocolVersion protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
@ -56,16 +56,16 @@ public class Handshake implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
this.protocolVersion = ProtocolUtils.readVarInt(buf);
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.protocolVersion = ProtocolVersion.getProtocolVersion(ProtocolUtils.readVarInt(buf));
|
||||
this.serverAddress = ProtocolUtils.readString(buf);
|
||||
this.port = buf.readUnsignedShort();
|
||||
this.nextStatus = ProtocolUtils.readVarInt(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
ProtocolUtils.writeVarInt(buf, this.protocolVersion);
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol());
|
||||
ProtocolUtils.writeString(buf, this.serverAddress);
|
||||
buf.writeShort(this.port);
|
||||
ProtocolUtils.writeVarInt(buf, this.nextStatus);
|
||||
|
@ -3,9 +3,10 @@ package com.velocitypowered.proxy.protocol.packet;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolUtils.writeString;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants.Direction;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.serializer.ComponentSerializer;
|
||||
@ -37,12 +38,12 @@ public class HeaderAndFooter implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
throw new UnsupportedOperationException("Decode is not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
writeString(buf, header);
|
||||
writeString(buf, footer);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -90,10 +90,10 @@ public class JoinGame implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.entityId = buf.readInt();
|
||||
this.gamemode = buf.readUnsignedByte();
|
||||
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9_1) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
||||
this.dimension = buf.readInt();
|
||||
} else {
|
||||
this.dimension = buf.readByte();
|
||||
@ -105,10 +105,10 @@ public class JoinGame implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
buf.writeInt(entityId);
|
||||
buf.writeByte(gamemode);
|
||||
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9_1) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
||||
buf.writeInt(dimension);
|
||||
} else {
|
||||
buf.writeByte(dimension);
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12_2;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@ -28,17 +26,17 @@ public class KeepAlive implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
if (protocolVersion >= MINECRAFT_1_12_2) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) {
|
||||
randomId = buf.readLong();
|
||||
} else {
|
||||
randomId = ProtocolUtils.readVarInt(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
if (protocolVersion >= MINECRAFT_1_12_2) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) {
|
||||
buf.writeLong(randomId);
|
||||
} else {
|
||||
ProtocolUtils.writeVarInt(buf, (int) randomId);
|
||||
|
@ -1,19 +1,20 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class LegacyHandshake implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,20 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class LegacyPing implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import net.kyori.text.serializer.ComponentSerializers;
|
||||
|
||||
public class LegacyPingResponse {
|
||||
@ -15,7 +16,7 @@ public class LegacyPingResponse {
|
||||
private final int playersMax;
|
||||
|
||||
public LegacyPingResponse(int protocolVersion, String serverVersion, String motd,
|
||||
int playersOnline, int playersMax) {
|
||||
int playersOnline, int playersMax) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.serverVersion = serverVersion;
|
||||
this.motd = motd;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@ -49,7 +49,7 @@ public class LoginPluginMessage implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.id = ProtocolUtils.readVarInt(buf);
|
||||
this.channel = ProtocolUtils.readString(buf);
|
||||
if (buf.isReadable()) {
|
||||
@ -60,7 +60,7 @@ public class LoginPluginMessage implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeVarInt(buf, id);
|
||||
if (channel == null) {
|
||||
throw new IllegalStateException("Channel is not specified!");
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@ -47,7 +47,7 @@ public class LoginPluginResponse implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.id = ProtocolUtils.readVarInt(buf);
|
||||
this.success = buf.readBoolean();
|
||||
if (buf.isReadable()) {
|
||||
@ -58,7 +58,7 @@ public class LoginPluginResponse implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeVarInt(buf, id);
|
||||
buf.writeBoolean(success);
|
||||
buf.writeBytes(data);
|
||||
|
@ -3,9 +3,9 @@ package com.velocitypowered.proxy.protocol.packet;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
@ -42,7 +42,7 @@ public class PlayerListItem implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
action = ProtocolUtils.readVarInt(buf);
|
||||
int length = ProtocolUtils.readVarInt(buf);
|
||||
|
||||
@ -84,7 +84,7 @@ public class PlayerListItem implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeVarInt(buf, action);
|
||||
ProtocolUtils.writeVarInt(buf, items.size());
|
||||
for (Item item : items) {
|
||||
|
@ -2,9 +2,9 @@ package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
@ -43,14 +43,14 @@ public class PluginMessage implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.channel = ProtocolUtils.readString(buf);
|
||||
this.data = new byte[buf.readableBytes()];
|
||||
buf.readBytes(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (channel == null) {
|
||||
throw new IllegalStateException("Channel is not specified.");
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@ -66,7 +66,7 @@ public class Respawn implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.dimension = buf.readInt();
|
||||
this.difficulty = buf.readUnsignedByte();
|
||||
this.gamemode = buf.readUnsignedByte();
|
||||
@ -74,7 +74,7 @@ public class Respawn implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
buf.writeInt(dimension);
|
||||
buf.writeByte(difficulty);
|
||||
buf.writeByte(gamemode);
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -34,12 +34,12 @@ public class ServerLogin implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
username = ProtocolUtils.readString(buf, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (username == null) {
|
||||
throw new IllegalStateException("No username found!");
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
@ -44,13 +44,13 @@ public class ServerLoginSuccess implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
uuid = UUID.fromString(ProtocolUtils.readString(buf, 36));
|
||||
username = ProtocolUtils.readString(buf, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (uuid == null) {
|
||||
throw new IllegalStateException("No UUID specified!");
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@ -33,12 +33,12 @@ public class SetCompression implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.threshold = ProtocolUtils.readVarInt(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeVarInt(buf, threshold);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class StatusPing implements MinecraftPacket {
|
||||
@ -10,12 +11,12 @@ public class StatusPing implements MinecraftPacket {
|
||||
private long randomId;
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
randomId = buf.readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
buf.writeLong(randomId);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class StatusRequest implements MinecraftPacket {
|
||||
@ -14,12 +15,12 @@ public class StatusRequest implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
// There is no additional data to decode.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
// There is no data to decode.
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -33,12 +33,12 @@ public class StatusResponse implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
status = ProtocolUtils.readString(buf, Short.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (status == null) {
|
||||
throw new IllegalStateException("Status is not specified");
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_9;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -62,9 +60,9 @@ public class TabCompleteRequest implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
this.command = ProtocolUtils.readString(buf);
|
||||
if (protocolVersion >= MINECRAFT_1_9) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
this.assumeCommand = buf.readBoolean();
|
||||
}
|
||||
this.hasPosition = buf.readBoolean();
|
||||
@ -74,12 +72,12 @@ public class TabCompleteRequest implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
if (command == null) {
|
||||
throw new IllegalStateException("Command is not specified");
|
||||
}
|
||||
ProtocolUtils.writeString(buf, command);
|
||||
if (protocolVersion >= MINECRAFT_1_9) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
buf.writeBoolean(assumeCommand);
|
||||
}
|
||||
buf.writeBoolean(hasPosition);
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
@ -24,7 +24,7 @@ public class TabCompleteResponse implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
int offersAvailable = ProtocolUtils.readVarInt(buf);
|
||||
for (int i = 0; i < offersAvailable; i++) {
|
||||
offers.add(ProtocolUtils.readString(buf));
|
||||
@ -32,7 +32,7 @@ public class TabCompleteResponse implements MinecraftPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeVarInt(buf, offers.size());
|
||||
for (String offer : offers) {
|
||||
ProtocolUtils.writeString(buf, offer);
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -26,14 +26,14 @@ public class TitlePacket implements MinecraftPacket {
|
||||
private int fadeOut;
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
throw new UnsupportedOperationException(); // encode only
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeVarInt(buf, action);
|
||||
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_11) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) {
|
||||
// 1.11+ shifted the action enum by 1 to handle the action bar
|
||||
switch (action) {
|
||||
case SET_TITLE:
|
||||
@ -118,23 +118,23 @@ public class TitlePacket implements MinecraftPacket {
|
||||
this.fadeOut = fadeOut;
|
||||
}
|
||||
|
||||
public static TitlePacket hideForProtocolVersion(int protocolVersion) {
|
||||
public static TitlePacket hideForProtocolVersion(ProtocolVersion protocolVersion) {
|
||||
TitlePacket packet = new TitlePacket();
|
||||
packet.setAction(protocolVersion >= ProtocolConstants.MINECRAFT_1_11 ? TitlePacket.HIDE
|
||||
packet.setAction(protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0 ? TitlePacket.HIDE
|
||||
: TitlePacket.HIDE_OLD);
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static TitlePacket resetForProtocolVersion(int protocolVersion) {
|
||||
public static TitlePacket resetForProtocolVersion(ProtocolVersion protocolVersion) {
|
||||
TitlePacket packet = new TitlePacket();
|
||||
packet.setAction(protocolVersion >= ProtocolConstants.MINECRAFT_1_11 ? TitlePacket.RESET
|
||||
packet.setAction(protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0 ? TitlePacket.RESET
|
||||
: TitlePacket.RESET_OLD);
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static TitlePacket timesForProtocolVersion(int protocolVersion) {
|
||||
public static TitlePacket timesForProtocolVersion(ProtocolVersion protocolVersion) {
|
||||
TitlePacket packet = new TitlePacket();
|
||||
packet.setAction(protocolVersion >= ProtocolConstants.MINECRAFT_1_11 ? TitlePacket.SET_TIMES
|
||||
packet.setAction(protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0 ? TitlePacket.SET_TIMES
|
||||
: TitlePacket.SET_TIMES_OLD);
|
||||
return packet;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.util.ProxyVersion;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@ -80,10 +80,11 @@ public class PluginMessageUtil {
|
||||
* @param channels the channels to register
|
||||
* @return the plugin message to send
|
||||
*/
|
||||
public static PluginMessage constructChannelsPacket(int protocolVersion,
|
||||
Collection<String> channels) {
|
||||
checkNotNull(channels, "channels");
|
||||
String channelName = protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ? REGISTER_CHANNEL
|
||||
|
||||
public static PluginMessage constructChannelsPacket(ProtocolVersion protocolVersion,
|
||||
Collection<String> channels) {
|
||||
Preconditions.checkNotNull(channels, "channels");
|
||||
String channelName = protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? REGISTER_CHANNEL
|
||||
: REGISTER_CHANNEL_LEGACY;
|
||||
PluginMessage message = new PluginMessage();
|
||||
message.setChannel(channelName);
|
||||
|
@ -2,10 +2,10 @@ package com.velocitypowered.proxy.server;
|
||||
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||
import com.velocitypowered.proxy.protocol.packet.StatusRequest;
|
||||
@ -33,7 +33,7 @@ public class PingSessionHandler implements MinecraftSessionHandler {
|
||||
handshake.setNextStatus(StateRegistry.STATUS_ID);
|
||||
handshake.setServerAddress(server.getServerInfo().getAddress().getHostString());
|
||||
handshake.setPort(server.getServerInfo().getAddress().getPort());
|
||||
handshake.setProtocolVersion(ProtocolConstants.MINIMUM_GENERIC_VERSION);
|
||||
handshake.setProtocolVersion(ProtocolVersion.MINIMUM_VERSION);
|
||||
connection.write(handshake);
|
||||
|
||||
connection.setState(StateRegistry.STATUS);
|
||||
|
@ -18,7 +18,7 @@ import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
|
||||
@ -74,9 +74,9 @@ public class VelocityRegisteredServer implements RegisteredServer {
|
||||
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
||||
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
|
||||
.addLast(MINECRAFT_DECODER,
|
||||
new MinecraftDecoder(ProtocolConstants.Direction.CLIENTBOUND))
|
||||
new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND))
|
||||
.addLast(MINECRAFT_ENCODER,
|
||||
new MinecraftEncoder(ProtocolConstants.Direction.SERVERBOUND));
|
||||
new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND));
|
||||
|
||||
MinecraftConnection connection = new MinecraftConnection(ch, server);
|
||||
connection.setState(StateRegistry.HANDSHAKE);
|
||||
|
@ -6,11 +6,13 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelRegistrar;
|
||||
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class VelocityChannelRegistrar implements ChannelRegistrar {
|
||||
@ -70,8 +72,8 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
|
||||
return identifierMap.get(id);
|
||||
}
|
||||
|
||||
public Collection<String> getChannelsForProtocol(int protocolVersion) {
|
||||
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_13) {
|
||||
public Collection<String> getChannelsForProtocol(ProtocolVersion protocolVersion) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) {
|
||||
return getModernChannelIds();
|
||||
}
|
||||
return getIdsForLegacyConnections();
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.velocitypowered.proxy.protocol;
|
||||
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12_1;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12_2;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12_1;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12_2;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -14,7 +15,7 @@ class PacketRegistryTest {
|
||||
|
||||
private StateRegistry.PacketRegistry setupRegistry() {
|
||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
||||
ProtocolConstants.Direction.CLIENTBOUND);
|
||||
ProtocolUtils.Direction.CLIENTBOUND);
|
||||
registry.register(Handshake.class, Handshake::new,
|
||||
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false));
|
||||
return registry;
|
||||
@ -23,46 +24,46 @@ class PacketRegistryTest {
|
||||
@Test
|
||||
void packetRegistryWorks() {
|
||||
StateRegistry.PacketRegistry registry = setupRegistry();
|
||||
MinecraftPacket packet = registry.getVersion(MINECRAFT_1_12).createPacket(0);
|
||||
MinecraftPacket packet = registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0);
|
||||
assertNotNull(packet, "Packet was not found in registry");
|
||||
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class");
|
||||
|
||||
assertEquals(0, registry.getVersion(MINECRAFT_1_12).getPacketId(packet),
|
||||
assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12).getPacketId(packet),
|
||||
"Registry did not return the correct packet ID");
|
||||
}
|
||||
|
||||
@Test
|
||||
void packetRegistryLinkingWorks() {
|
||||
StateRegistry.PacketRegistry registry = setupRegistry();
|
||||
MinecraftPacket packet = registry.getVersion(MINECRAFT_1_12_1).createPacket(0);
|
||||
MinecraftPacket packet = registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0);
|
||||
assertNotNull(packet, "Packet was not found in registry");
|
||||
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class");
|
||||
assertEquals(0, registry.getVersion(MINECRAFT_1_12_1).getPacketId(packet),
|
||||
assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12_1).getPacketId(packet),
|
||||
"Registry did not return the correct packet ID");
|
||||
}
|
||||
|
||||
@Test
|
||||
void failOnNoMappings() {
|
||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
||||
ProtocolConstants.Direction.CLIENTBOUND);
|
||||
ProtocolUtils.Direction.CLIENTBOUND);
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> registry.register(Handshake.class, Handshake::new));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> registry.getVersion(0).getPacketId(new Handshake()));
|
||||
() -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN).getPacketId(new Handshake()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void registrySuppliesCorrectPacketsByProtocol() {
|
||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
||||
ProtocolConstants.Direction.CLIENTBOUND);
|
||||
ProtocolUtils.Direction.CLIENTBOUND);
|
||||
registry.register(Handshake.class, Handshake::new,
|
||||
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false),
|
||||
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false));
|
||||
assertEquals(Handshake.class,
|
||||
registry.getVersion(MINECRAFT_1_12).createPacket(0x00).getClass());
|
||||
registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0x00).getClass());
|
||||
assertEquals(Handshake.class,
|
||||
registry.getVersion(MINECRAFT_1_12_1).createPacket(0x01).getClass());
|
||||
registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0x01).getClass());
|
||||
assertEquals(Handshake.class,
|
||||
registry.getVersion(MINECRAFT_1_12_2).createPacket(0x01).getClass());
|
||||
registry.getProtocolRegistry(MINECRAFT_1_12_2).createPacket(0x01).getClass());
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren