3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Rework and expose ProtocolVersion to the API

Dieser Commit ist enthalten in:
Crypnotic 2018-11-15 02:29:58 -06:00
Ursprung 74ee716480
Commit 6b4c809c39
52 geänderte Dateien mit 423 neuen und 309 gelöschten Zeilen

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -1,5 +1,7 @@
package com.velocitypowered.api.proxy; package com.velocitypowered.api.proxy;
import com.velocitypowered.api.network.ProtocolVersion;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Optional; import java.util.Optional;
@ -34,5 +36,5 @@ public interface InboundConnection {
* *
* @return the protocol version the connection uses * @return the protocol version the connection uses
*/ */
int getProtocolVersion(); ProtocolVersion getProtocolVersion();
} }

Datei anzeigen

@ -10,6 +10,8 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import com.velocitypowered.api.network.ProtocolVersion;
import net.kyori.text.Component; import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;

Datei anzeigen

@ -10,13 +10,13 @@ import static com.velocitypowered.proxy.network.Connections.MINECRAFT_DECODER;
import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER; import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.natives.compression.VelocityCompressor; import com.velocitypowered.natives.compression.VelocityCompressor;
import com.velocitypowered.natives.encryption.VelocityCipher; import com.velocitypowered.natives.encryption.VelocityCipher;
import com.velocitypowered.natives.encryption.VelocityCipherFactory; import com.velocitypowered.natives.encryption.VelocityCipherFactory;
import com.velocitypowered.natives.util.Natives; import com.velocitypowered.natives.util.Natives;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder;
@ -53,8 +53,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
private SocketAddress remoteAddress; private SocketAddress remoteAddress;
private StateRegistry state; private StateRegistry state;
private @Nullable MinecraftSessionHandler sessionHandler; private @Nullable MinecraftSessionHandler sessionHandler;
private int protocolVersion; private ProtocolVersion protocolVersion;
private int nextProtocolVersion; private ProtocolVersion nextProtocolVersion;
private @Nullable MinecraftConnectionAssociation association; private @Nullable MinecraftConnectionAssociation association;
private boolean isLegacyForge; private boolean isLegacyForge;
private final VelocityServer server; private final VelocityServer server;
@ -204,14 +204,14 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
this.channel.pipeline().get(MinecraftDecoder.class).setState(state); this.channel.pipeline().get(MinecraftDecoder.class).setState(state);
} }
public int getProtocolVersion() { public ProtocolVersion getProtocolVersion() {
return protocolVersion; return protocolVersion;
} }
public void setProtocolVersion(int protocolVersion) { public void setProtocolVersion(ProtocolVersion protocolVersion) {
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
this.nextProtocolVersion = protocolVersion; this.nextProtocolVersion = protocolVersion;
if (protocolVersion != ProtocolConstants.LEGACY) { if (protocolVersion != ProtocolVersion.LEGACY) {
this.channel.pipeline().get(MinecraftEncoder.class).setProtocolVersion(protocolVersion); this.channel.pipeline().get(MinecraftEncoder.class).setProtocolVersion(protocolVersion);
this.channel.pipeline().get(MinecraftDecoder.class).setProtocolVersion(protocolVersion); this.channel.pipeline().get(MinecraftDecoder.class).setProtocolVersion(protocolVersion);
} else { } else {
@ -295,11 +295,11 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
this.canSendLegacyFmlResetPacket = isLegacyForge && canSendLegacyFMLResetPacket; this.canSendLegacyFmlResetPacket = isLegacyForge && canSendLegacyFMLResetPacket;
} }
public int getNextProtocolVersion() { public ProtocolVersion getNextProtocolVersion() {
return this.nextProtocolVersion; return this.nextProtocolVersion;
} }
public void setNextProtocolVersion(int nextProtocolVersion) { public void setNextProtocolVersion(ProtocolVersion nextProtocolVersion) {
this.nextProtocolVersion = nextProtocolVersion; this.nextProtocolVersion = nextProtocolVersion;
} }
} }

Datei anzeigen

@ -2,6 +2,7 @@ package com.velocitypowered.proxy.connection.backend;
import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; 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.forge.ForgeConstants;
import com.velocitypowered.proxy.connection.util.ConnectionMessages; import com.velocitypowered.proxy.connection.util.ConnectionMessages;
import com.velocitypowered.proxy.protocol.MinecraftPacket; 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.BossBar;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.Disconnect;
import com.velocitypowered.proxy.protocol.packet.JoinGame; import com.velocitypowered.proxy.protocol.packet.JoinGame;
@ -171,7 +171,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
return false; return false;
} }
boolean minecraftOrFmlMessage; boolean minecraftOrFmlMessage;
if (mc.getProtocolVersion() <= ProtocolConstants.MINECRAFT_1_12_2) { if (mc.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_12_2) <= 0) {
String channel = message.getChannel(); String channel = message.getChannel();
minecraftOrFmlMessage = channel.startsWith("MC|") || channel minecraftOrFmlMessage = channel.startsWith("MC|") || channel
.startsWith(ForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL); .startsWith(ForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL);

Datei anzeigen

@ -14,12 +14,13 @@ import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.proxy.server.ServerInfo;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.config.PlayerInfoForwarding;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; 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.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
@ -69,9 +70,9 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
.addLast(MINECRAFT_DECODER, .addLast(MINECRAFT_DECODER,
new MinecraftDecoder(ProtocolConstants.Direction.CLIENTBOUND)) new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND))
.addLast(MINECRAFT_ENCODER, .addLast(MINECRAFT_ENCODER,
new MinecraftEncoder(ProtocolConstants.Direction.SERVERBOUND)); new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND));
MinecraftConnection mc = new MinecraftConnection(ch, server); MinecraftConnection mc = new MinecraftConnection(ch, server);
mc.setState(StateRegistry.HANDSHAKE); mc.setState(StateRegistry.HANDSHAKE);
@ -137,7 +138,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
handshake.setPort(registeredServer.getServerInfo().getAddress().getPort()); handshake.setPort(registeredServer.getServerInfo().getAddress().getPort());
mc.write(handshake); mc.write(handshake);
int protocolVersion = proxyPlayer.getConnection().getNextProtocolVersion(); ProtocolVersion protocolVersion = proxyPlayer.getConnection().getNextProtocolVersion();
mc.setProtocolVersion(protocolVersion); mc.setProtocolVersion(protocolVersion);
mc.setState(StateRegistry.LOGIN); mc.setState(StateRegistry.LOGIN);
mc.write(new ServerLogin(proxyPlayer.getUsername())); mc.write(new ServerLogin(proxyPlayer.getUsername()));

Datei anzeigen

@ -4,6 +4,7 @@ import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; 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.ForgeConstants;
import com.velocitypowered.proxy.connection.forge.ForgeUtil; import com.velocitypowered.proxy.connection.forge.ForgeUtil;
import com.velocitypowered.proxy.protocol.MinecraftPacket; 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.BossBar;
import com.velocitypowered.proxy.protocol.packet.Chat; import com.velocitypowered.proxy.protocol.packet.Chat;
import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.ClientSettings;
@ -335,9 +335,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
serverBossBars.clear(); serverBossBars.clear();
// Tell the server about this client's plugin message channels. // Tell the server about this client's plugin message channels.
int serverVersion = serverMc.getProtocolVersion(); ProtocolVersion serverVersion = serverMc.getProtocolVersion();
Collection<String> toRegister = new HashSet<>(knownChannels); 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()); toRegister.addAll(server.getChannelRegistrar().getModernChannelIds());
} else { } else {
toRegister.addAll(server.getChannelRegistrar().getIdsForLegacyConnections()); toRegister.addAll(server.getChannelRegistrar().getIdsForLegacyConnections());

Datei anzeigen

@ -22,6 +22,7 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.MessagePosition; import com.velocitypowered.api.util.MessagePosition;
import com.velocitypowered.api.util.ModInfo; 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.TextTitle;
import com.velocitypowered.api.util.title.Title; import com.velocitypowered.api.util.title.Title;
import com.velocitypowered.api.util.title.Titles; 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.forge.ForgeConstants;
import com.velocitypowered.proxy.connection.util.ConnectionMessages; import com.velocitypowered.proxy.connection.util.ConnectionMessages;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults; 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.Chat;
import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.ClientSettings;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.Disconnect;
@ -164,7 +164,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
@Override @Override
public int getProtocolVersion() { public ProtocolVersion getProtocolVersion() {
return connection.getProtocolVersion(); return connection.getProtocolVersion();
} }
@ -176,7 +176,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
byte pos = (byte) position.ordinal(); byte pos = (byte) position.ordinal();
String json; String json;
if (position == MessagePosition.ACTION_BAR) { 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. // We can use the title packet instead.
TitlePacket pkt = new TitlePacket(); TitlePacket pkt = new TitlePacket();
pkt.setAction(TitlePacket.SET_ACTION_BAR); pkt.setAction(TitlePacket.SET_ACTION_BAR);

Datei anzeigen

@ -6,13 +6,13 @@ import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent;
import com.velocitypowered.api.event.proxy.ProxyPingEvent; import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.config.PlayerInfoForwarding;
import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.config.VelocityConfiguration;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.Disconnect;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.Handshake;
@ -40,11 +40,11 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
@Override @Override
public boolean handle(LegacyPing packet) { public boolean handle(LegacyPing packet) {
connection.setProtocolVersion(ProtocolConstants.LEGACY); connection.setProtocolVersion(ProtocolVersion.LEGACY);
VelocityConfiguration configuration = server.getConfiguration(); VelocityConfiguration configuration = server.getConfiguration();
ServerPing ping = new ServerPing( ServerPing ping = new ServerPing(
new ServerPing.Version(ProtocolConstants.MAXIMUM_GENERIC_VERSION, new ServerPing.Version(ProtocolVersion.MAXIMUM_VERSION.getProtocol(),
"Velocity " + ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING), "Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING),
new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(), new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(),
ImmutableList.of()), ImmutableList.of()),
configuration.getMotdComponent(), configuration.getMotdComponent(),
@ -82,7 +82,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
connection.setState(StateRegistry.LOGIN); connection.setState(StateRegistry.LOGIN);
connection.setProtocolVersion(handshake.getProtocolVersion()); connection.setProtocolVersion(handshake.getProtocolVersion());
if (!ProtocolConstants.isSupported(handshake.getProtocolVersion())) { if (!ProtocolVersion.isSupported(handshake.getProtocolVersion())) {
connection.closeWith(Disconnect connection.closeWith(Disconnect
.create(TranslatableComponent.of("multiplayer.disconnect.outdated_client"))); .create(TranslatableComponent.of("multiplayer.disconnect.outdated_client")));
return true; 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 // 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. // and lower, otherwise IP information will never get forwarded.
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
&& handshake.getProtocolVersion() < ProtocolConstants.MINECRAFT_1_13) { && handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) {
connection.closeWith(Disconnect connection.closeWith(Disconnect
.create(TextComponent.of("This server is only compatible with 1.13 and above."))); .create(TextComponent.of("This server is only compatible with 1.13 and above.")));
return true; return true;
@ -165,8 +165,8 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public int getProtocolVersion() { public ProtocolVersion getProtocolVersion() {
return 0; return ProtocolVersion.UNKNOWN;
} }
} }
} }

Datei anzeigen

@ -1,6 +1,7 @@
package com.velocitypowered.proxy.connection.client; package com.velocitypowered.proxy.connection.client;
import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.Handshake;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -35,7 +36,7 @@ class InitialInboundConnection implements InboundConnection {
} }
@Override @Override
public int getProtocolVersion() { public ProtocolVersion getProtocolVersion() {
return connection.getProtocolVersion(); return connection.getProtocolVersion();
} }
} }

Datei anzeigen

@ -3,7 +3,7 @@ package com.velocitypowered.proxy.connection.client;
import static com.velocitypowered.proxy.VelocityServer.GSON; import static com.velocitypowered.proxy.VelocityServer.GSON;
import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY; 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.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.google.common.base.Preconditions;
import com.velocitypowered.api.event.connection.LoginEvent; 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.InboundConnection;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.config.PlayerInfoForwarding;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.Disconnect;
import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; import com.velocitypowered.proxy.protocol.packet.EncryptionRequest;
@ -73,7 +75,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
@Override @Override
public boolean handle(ServerLogin packet) { public boolean handle(ServerLogin packet) {
this.login = packet; this.login = packet;
if (inbound.getProtocolVersion() >= MINECRAFT_1_13) { if (inbound.getProtocolVersion().compareTo(MINECRAFT_1_13) >= 0) {
playerInfoId = ThreadLocalRandom.current().nextInt(); playerInfoId = ThreadLocalRandom.current().nextInt();
inbound.write(new LoginPluginMessage(playerInfoId, VELOCITY_IP_FORWARDING_CHANNEL, inbound.write(new LoginPluginMessage(playerInfoId, VELOCITY_IP_FORWARDING_CHANNEL,
Unpooled.EMPTY_BUFFER)); Unpooled.EMPTY_BUFFER));

Datei anzeigen

@ -5,11 +5,11 @@ import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.config.VelocityConfiguration;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; 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.StatusPing;
import com.velocitypowered.proxy.protocol.packet.StatusRequest; import com.velocitypowered.proxy.protocol.packet.StatusRequest;
import com.velocitypowered.proxy.protocol.packet.StatusResponse; import com.velocitypowered.proxy.protocol.packet.StatusResponse;
@ -38,11 +38,12 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
public boolean handle(StatusRequest packet) { public boolean handle(StatusRequest packet) {
VelocityConfiguration configuration = server.getConfiguration(); VelocityConfiguration configuration = server.getConfiguration();
int shownVersion = ProtocolConstants.isSupported(connection.getProtocolVersion()) ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion()) ? connection
? connection.getProtocolVersion() : ProtocolConstants.MAXIMUM_GENERIC_VERSION; .getProtocolVersion() :
ProtocolVersion.MAXIMUM_VERSION;
ServerPing initialPing = new ServerPing( ServerPing initialPing = new ServerPing(
new ServerPing.Version(shownVersion, new ServerPing.Version(shownVersion.getProtocol(),
"Velocity " + ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING), "Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING),
new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(), new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(),
ImmutableList.of()), ImmutableList.of()),
configuration.getMotdComponent(), configuration.getMotdComponent(),

Datei anzeigen

@ -11,7 +11,7 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; 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.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.LegacyPingDecoder; import com.velocitypowered.proxy.protocol.netty.LegacyPingDecoder;
import com.velocitypowered.proxy.protocol.netty.LegacyPingEncoder; import com.velocitypowered.proxy.protocol.netty.LegacyPingEncoder;
@ -44,8 +44,8 @@ public class ServerChannelInitializer extends ChannelInitializer<Channel> {
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
.addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE) .addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE)
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
.addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolConstants.Direction.SERVERBOUND)) .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.SERVERBOUND))
.addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolConstants.Direction.CLIENTBOUND)); .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolUtils.Direction.CLIENTBOUND));
final MinecraftConnection connection = new MinecraftConnection(ch, this.server); final MinecraftConnection connection = new MinecraftConnection(ch, this.server);
connection.setState(StateRegistry.HANDSHAKE); connection.setState(StateRegistry.HANDSHAKE);

Datei anzeigen

@ -1,13 +1,14 @@
package com.velocitypowered.proxy.protocol; package com.velocitypowered.proxy.protocol;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public interface MinecraftPacket { 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); boolean handle(MinecraftSessionHandler handler);
} }

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

@ -2,8 +2,10 @@ package com.velocitypowered.proxy.protocol;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.network.ProtocolVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -119,4 +121,15 @@ public enum ProtocolUtils {
} }
return properties; 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);
}
}
} }

Datei anzeigen

@ -1,23 +1,26 @@
package com.velocitypowered.proxy.protocol; package com.velocitypowered.proxy.protocol;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.Direction; import static com.velocitypowered.proxy.protocol.ProtocolUtils.Direction;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_10; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_10;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_11; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_11;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_11_1; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_11_1;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12_1; import static com.velocitypowered.api.network.ProtocolVersion.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_2;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_13; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_13_1; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13_1;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_13_2; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13_2;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_8; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_8;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_9; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_9_1; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_1;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_9_2; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_2;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_9_4; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_4;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINIMUM_GENERIC_VERSION; 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.BossBar;
import com.velocitypowered.proxy.protocol.packet.Chat; import com.velocitypowered.proxy.protocol.packet.Chat;
import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.ClientSettings;
@ -46,8 +49,10 @@ import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap; import io.netty.util.collection.IntObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.util.Objects;
import java.util.*;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public enum StateRegistry { public enum StateRegistry {
@ -195,38 +200,40 @@ public enum StateRegistry {
public static class PacketRegistry { 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 { static {
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9, LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9, ImmutableList.of(MINECRAFT_1_9_1, MINECRAFT_1_9_2, MINECRAFT_1_9_4));
ImmutableIntArray.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_9_4, LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12, ImmutableList.of(MINECRAFT_1_12_1));
ImmutableIntArray.of(MINECRAFT_1_10, MINECRAFT_1_11, MINECRAFT_1_11_1)); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12_1, ImmutableList.of(MINECRAFT_1_12_2));
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12, ImmutableIntArray.of(MINECRAFT_1_12_1)); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_13, ImmutableList.of(MINECRAFT_1_13_1, MINECRAFT_1_13_2));
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));
} }
private final Direction direction; private final Direction direction;
private final IntObjectMap<ProtocolVersion> versions = new IntObjectHashMap<>(16); private final Map<ProtocolVersion, ProtocolRegistry> versions;
private boolean fallback = true; private boolean fallback = true;
PacketRegistry(Direction direction) { PacketRegistry(Direction direction) {
this.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) { public ProtocolRegistry getProtocolRegistry(final ProtocolVersion version) {
ProtocolVersion result = versions.get(version); ProtocolRegistry registry = versions.get(version);
if (result == null) { if (registry == null) {
if (fallback) { if (fallback) {
return getVersion(MINIMUM_GENERIC_VERSION); return getProtocolRegistry(MINIMUM_VERSION);
} }
throw new IllegalArgumentException("Could not find data for protocol version " + 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, public <P extends MinecraftPacket> void register(Class<P> clazz, Supplier<P> packetSupplier,
@ -236,20 +243,20 @@ public enum StateRegistry {
} }
for (final PacketMapping mapping : mappings) { for (final PacketMapping mapping : mappings) {
ProtocolVersion version = this.versions.get(mapping.protocolVersion); ProtocolRegistry registry = this.versions.get(mapping.protocolVersion);
if (version == null) { if (registry == null) {
throw new IllegalArgumentException("Unknown protocol version " + mapping.protocolVersion); throw new IllegalArgumentException("Unknown protocol version " + mapping.protocolVersion);
} }
if (!mapping.encodeOnly) { 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) { if (linked != null) {
links: links:
for (int i = 0; i < linked.length(); i++) { for (int i = 0; i < linked.size(); i++) {
int linkedVersion = linked.get(i); ProtocolVersion linkedVersion = linked.get(i);
// Make sure that later mappings override this one. // Make sure that later mappings override this one.
for (PacketMapping m : mappings) { for (PacketMapping m : mappings) {
if (linkedVersion == m.protocolVersion) { 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 = final IntObjectMap<Supplier<? extends MinecraftPacket>> packetIdToSupplier =
new IntObjectHashMap<>(16, 0.5f); new IntObjectHashMap<>(16, 0.5f);
final Object2IntMap<Class<? extends MinecraftPacket>> packetClassToId = final Object2IntMap<Class<? extends MinecraftPacket>> packetClassToId =
new Object2IntOpenHashMap<>(16, 0.5f); new Object2IntOpenHashMap<>(16, 0.5f);
ProtocolVersion(final int version) { ProtocolRegistry(final ProtocolVersion version) {
this.version = version; this.version = version;
this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE); this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE);
} }
@ -299,10 +306,10 @@ public enum StateRegistry {
public static class PacketMapping { public static class PacketMapping {
private final int id; private final int id;
private final int protocolVersion; private final ProtocolVersion protocolVersion;
private final boolean encodeOnly; private final boolean encodeOnly;
public PacketMapping(int id, int protocolVersion, boolean packetDecoding) { public PacketMapping(int id, ProtocolVersion protocolVersion, boolean packetDecoding) {
this.id = id; this.id = id;
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
this.encodeOnly = packetDecoding; this.encodeOnly = packetDecoding;
@ -345,7 +352,7 @@ public enum StateRegistry {
* @param encodeOnly When true packet decoding will be disabled * @param encodeOnly When true packet decoding will be disabled
* @return PacketMapping with the provided arguments * @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); return new PacketMapping(id, version, encodeOnly);
} }

Datei anzeigen

@ -10,8 +10,8 @@ import com.velocitypowered.api.event.query.ProxyQueryEvent;
import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.QueryResponse; import com.velocitypowered.api.proxy.server.QueryResponse;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
@ -73,7 +73,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
return QueryResponse.builder() return QueryResponse.builder()
.hostname(ComponentSerializers.PLAIN .hostname(ComponentSerializers.PLAIN
.serialize(server.getConfiguration().getMotdComponent())) .serialize(server.getConfiguration().getMotdComponent()))
.gameVersion(ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING) .gameVersion(ProtocolVersion.SUPPORTED_VERSION_STRING)
.map(server.getConfiguration().getQueryMap()) .map(server.getConfiguration().getQueryMap())
.currentPlayers(server.getPlayerCount()) .currentPlayers(server.getPlayerCount())
.maxPlayers(server.getConfiguration().getShowMaxPlayers()) .maxPlayers(server.getConfiguration().getShowMaxPlayers())

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.netty; package com.velocitypowered.proxy.protocol.netty;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -13,14 +13,14 @@ import java.util.List;
public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf> { public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf> {
private final ProtocolConstants.Direction direction; private final ProtocolUtils.Direction direction;
private StateRegistry state; 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.direction = Preconditions.checkNotNull(direction, "direction");
this.protocolVersion = direction this.registry = direction
.getProtocol(StateRegistry.HANDSHAKE, ProtocolConstants.MINIMUM_GENERIC_VERSION); .getProtocolRegistry(StateRegistry.HANDSHAKE, ProtocolVersion.MINIMUM_VERSION);
this.state = StateRegistry.HANDSHAKE; this.state = StateRegistry.HANDSHAKE;
} }
@ -33,35 +33,35 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf> {
ByteBuf slice = msg.slice(); ByteBuf slice = msg.slice();
int packetId = ProtocolUtils.readVarInt(msg); int packetId = ProtocolUtils.readVarInt(msg);
MinecraftPacket packet = this.protocolVersion.createPacket(packetId); MinecraftPacket packet = this.registry.createPacket(packetId);
if (packet == null) { if (packet == null) {
msg.skipBytes(msg.readableBytes()); msg.skipBytes(msg.readableBytes());
out.add(slice.retain()); out.add(slice.retain());
} else { } else {
try { try {
packet.decode(msg, direction, protocolVersion.version); packet.decode(msg, direction, registry.version);
} catch (Exception e) { } catch (Exception e) {
throw new CorruptedFrameException( throw new CorruptedFrameException(
"Error decoding " + packet.getClass() + " Direction " + direction "Error decoding " + packet.getClass() + " Direction " + direction
+ " Protocol " + protocolVersion.version + " State " + state + " ID " + Integer + " Protocol " + registry.version + " State " + state + " ID " + Integer
.toHexString(packetId), e); .toHexString(packetId), e);
} }
if (msg.isReadable()) { if (msg.isReadable()) {
throw new CorruptedFrameException( throw new CorruptedFrameException(
"Did not read full packet for " + packet.getClass() + " Direction " + direction "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)); .toHexString(packetId));
} }
out.add(packet); out.add(packet);
} }
} }
public void setProtocolVersion(int protocolVersion) { public void setProtocolVersion(ProtocolVersion protocolVersion) {
this.protocolVersion = direction.getProtocol(state, protocolVersion); this.registry = direction.getProtocolRegistry(state, protocolVersion);
} }
public void setState(StateRegistry state) { public void setState(StateRegistry state) {
this.state = state; this.state = state;
this.setProtocolVersion(protocolVersion.version); this.setProtocolVersion(registry.version);
} }
} }

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.netty; package com.velocitypowered.proxy.protocol.netty;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -11,30 +11,30 @@ import io.netty.handler.codec.MessageToByteEncoder;
public class MinecraftEncoder extends MessageToByteEncoder<MinecraftPacket> { public class MinecraftEncoder extends MessageToByteEncoder<MinecraftPacket> {
private final ProtocolConstants.Direction direction; private final ProtocolUtils.Direction direction;
private StateRegistry state; 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.direction = Preconditions.checkNotNull(direction, "direction");
this.protocolVersion = direction this.registry = direction
.getProtocol(StateRegistry.HANDSHAKE, ProtocolConstants.MINIMUM_GENERIC_VERSION); .getProtocolRegistry(StateRegistry.HANDSHAKE, ProtocolVersion.MINIMUM_VERSION);
this.state = StateRegistry.HANDSHAKE; this.state = StateRegistry.HANDSHAKE;
} }
@Override @Override
protected void encode(ChannelHandlerContext ctx, MinecraftPacket msg, ByteBuf out) { 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); ProtocolUtils.writeVarInt(out, packetId);
msg.encode(out, direction, protocolVersion.version); msg.encode(out, direction, registry.version);
} }
public void setProtocolVersion(final int protocolVersion) { public void setProtocolVersion(final ProtocolVersion protocolVersion) {
this.protocolVersion = direction.getProtocol(state, protocolVersion); this.registry = direction.getProtocolRegistry(state, protocolVersion);
} }
public void setState(StateRegistry state) { public void setState(StateRegistry state) {
this.state = state; this.state = state;
this.setProtocolVersion(protocolVersion.version); this.setProtocolVersion(registry.version);
} }
} }

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.UUID; import java.util.UUID;
@ -97,7 +97,7 @@ public class BossBar implements MinecraftPacket {
} }
@Override @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.uuid = ProtocolUtils.readUuid(buf);
this.action = ProtocolUtils.readVarInt(buf); this.action = ProtocolUtils.readVarInt(buf);
switch (action) { switch (action) {
@ -129,7 +129,7 @@ public class BossBar implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (uuid == null) { if (uuid == null) {
throw new IllegalStateException("No boss bar UUID specified"); throw new IllegalStateException("No boss bar UUID specified");
} }

Datei anzeigen

@ -1,9 +1,9 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.text.Component; import net.kyori.text.Component;
@ -54,20 +54,20 @@ public class Chat implements MinecraftPacket {
} }
@Override @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); message = ProtocolUtils.readString(buf);
if (direction == ProtocolConstants.Direction.CLIENTBOUND) { if (direction == ProtocolUtils.Direction.CLIENTBOUND) {
type = buf.readByte(); type = buf.readByte();
} }
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (message == null) { if (message == null) {
throw new IllegalStateException("Message is not specified"); throw new IllegalStateException("Message is not specified");
} }
ProtocolUtils.writeString(buf, message); ProtocolUtils.writeString(buf, message);
if (direction == ProtocolConstants.Direction.CLIENTBOUND) { if (direction == ProtocolUtils.Direction.CLIENTBOUND) {
buf.writeByte(type); buf.writeByte(type);
} }
} }

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -93,20 +93,20 @@ public class ClientSettings implements MinecraftPacket {
} }
@Override @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.locale = ProtocolUtils.readString(buf, 16);
this.viewDistance = buf.readByte(); this.viewDistance = buf.readByte();
this.chatVisibility = ProtocolUtils.readVarInt(buf); this.chatVisibility = ProtocolUtils.readVarInt(buf);
this.chatColors = buf.readBoolean(); this.chatColors = buf.readBoolean();
this.skinParts = buf.readUnsignedByte(); this.skinParts = buf.readUnsignedByte();
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
this.mainHand = ProtocolUtils.readVarInt(buf); this.mainHand = ProtocolUtils.readVarInt(buf);
} }
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (locale == null) { if (locale == null) {
throw new IllegalStateException("No locale specified"); throw new IllegalStateException("No locale specified");
} }
@ -116,7 +116,7 @@ public class ClientSettings implements MinecraftPacket {
buf.writeBoolean(chatColors); buf.writeBoolean(chatColors);
buf.writeByte(skinParts); buf.writeByte(skinParts);
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
ProtocolUtils.writeVarInt(buf, mainHand); ProtocolUtils.writeVarInt(buf, mainHand);
} }
} }

Datei anzeigen

@ -1,9 +1,9 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.text.Component; import net.kyori.text.Component;
@ -40,12 +40,12 @@ public class Disconnect implements MinecraftPacket {
} }
@Override @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); reason = ProtocolUtils.readString(buf);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (reason == null) { if (reason == null) {
throw new IllegalStateException("No reason specified."); throw new IllegalStateException("No reason specified.");
} }

Datei anzeigen

@ -2,9 +2,9 @@ package com.velocitypowered.proxy.protocol.packet;
import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY; 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.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.Arrays; import java.util.Arrays;
@ -40,14 +40,14 @@ public class EncryptionRequest implements MinecraftPacket {
} }
@Override @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); this.serverId = ProtocolUtils.readString(buf, 20);
publicKey = ProtocolUtils.readByteArray(buf, 256); publicKey = ProtocolUtils.readByteArray(buf, 256);
verifyToken = ProtocolUtils.readByteArray(buf, 16); verifyToken = ProtocolUtils.readByteArray(buf, 16);
} }
@Override @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.writeString(buf, this.serverId);
ProtocolUtils.writeByteArray(buf, publicKey); ProtocolUtils.writeByteArray(buf, publicKey);
ProtocolUtils.writeByteArray(buf, verifyToken); ProtocolUtils.writeByteArray(buf, verifyToken);

Datei anzeigen

@ -2,9 +2,9 @@ package com.velocitypowered.proxy.protocol.packet;
import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY; 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.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.Arrays; import java.util.Arrays;
@ -39,13 +39,13 @@ public class EncryptionResponse implements MinecraftPacket {
} }
@Override @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.sharedSecret = ProtocolUtils.readByteArray(buf, 256);
this.verifyToken = ProtocolUtils.readByteArray(buf, 128); this.verifyToken = ProtocolUtils.readByteArray(buf, 128);
} }
@Override @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, sharedSecret);
ProtocolUtils.writeByteArray(buf, verifyToken); ProtocolUtils.writeByteArray(buf, verifyToken);
} }

Datei anzeigen

@ -1,23 +1,23 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class Handshake implements MinecraftPacket { public class Handshake implements MinecraftPacket {
private int protocolVersion; private ProtocolVersion protocolVersion;
private String serverAddress = ""; private String serverAddress = "";
private int port; private int port;
private int nextStatus; private int nextStatus;
public int getProtocolVersion() { public ProtocolVersion getProtocolVersion() {
return protocolVersion; return protocolVersion;
} }
public void setProtocolVersion(int protocolVersion) { public void setProtocolVersion(ProtocolVersion protocolVersion) {
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
} }
@ -56,16 +56,16 @@ public class Handshake implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
this.protocolVersion = ProtocolUtils.readVarInt(buf); this.protocolVersion = ProtocolVersion.getProtocolVersion(ProtocolUtils.readVarInt(buf));
this.serverAddress = ProtocolUtils.readString(buf); this.serverAddress = ProtocolUtils.readString(buf);
this.port = buf.readUnsignedShort(); this.port = buf.readUnsignedShort();
this.nextStatus = ProtocolUtils.readVarInt(buf); this.nextStatus = ProtocolUtils.readVarInt(buf);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
ProtocolUtils.writeVarInt(buf, this.protocolVersion); ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol());
ProtocolUtils.writeString(buf, this.serverAddress); ProtocolUtils.writeString(buf, this.serverAddress);
buf.writeShort(this.port); buf.writeShort(this.port);
ProtocolUtils.writeVarInt(buf, this.nextStatus); ProtocolUtils.writeVarInt(buf, this.nextStatus);

Datei anzeigen

@ -3,9 +3,10 @@ package com.velocitypowered.proxy.protocol.packet;
import static com.velocitypowered.proxy.protocol.ProtocolUtils.writeString; import static com.velocitypowered.proxy.protocol.ProtocolUtils.writeString;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; 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 io.netty.buffer.ByteBuf;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializer; import net.kyori.text.serializer.ComponentSerializer;
@ -37,12 +38,12 @@ public class HeaderAndFooter implements MinecraftPacket {
} }
@Override @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"); throw new UnsupportedOperationException("Decode is not implemented");
} }
@Override @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, header);
writeString(buf, footer); writeString(buf, footer);
} }

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -90,10 +90,10 @@ public class JoinGame implements MinecraftPacket {
} }
@Override @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.entityId = buf.readInt();
this.gamemode = buf.readUnsignedByte(); this.gamemode = buf.readUnsignedByte();
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9_1) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
this.dimension = buf.readInt(); this.dimension = buf.readInt();
} else { } else {
this.dimension = buf.readByte(); this.dimension = buf.readByte();
@ -105,10 +105,10 @@ public class JoinGame implements MinecraftPacket {
} }
@Override @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.writeInt(entityId);
buf.writeByte(gamemode); buf.writeByte(gamemode);
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_9_1) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
buf.writeInt(dimension); buf.writeInt(dimension);
} else { } else {
buf.writeByte(dimension); buf.writeByte(dimension);

Datei anzeigen

@ -1,10 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; 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.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -28,17 +26,17 @@ public class KeepAlive implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (protocolVersion >= MINECRAFT_1_12_2) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) {
randomId = buf.readLong(); randomId = buf.readLong();
} else { } else {
randomId = ProtocolUtils.readVarInt(buf); randomId = ProtocolUtils.readVarInt(buf);
} }
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (protocolVersion >= MINECRAFT_1_12_2) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) {
buf.writeLong(randomId); buf.writeLong(randomId);
} else { } else {
ProtocolUtils.writeVarInt(buf, (int) randomId); ProtocolUtils.writeVarInt(buf, (int) randomId);

Datei anzeigen

@ -1,19 +1,20 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; 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.ByteBuf;
public class LegacyHandshake implements MinecraftPacket { public class LegacyHandshake implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

Datei anzeigen

@ -1,19 +1,20 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; 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.ByteBuf;
public class LegacyPing implements MinecraftPacket { public class LegacyPing implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

Datei anzeigen

@ -2,6 +2,7 @@ package com.velocitypowered.proxy.protocol.packet;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.network.ProtocolVersion;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.ComponentSerializers;
public class LegacyPingResponse { public class LegacyPingResponse {
@ -15,7 +16,7 @@ public class LegacyPingResponse {
private final int playersMax; private final int playersMax;
public LegacyPingResponse(int protocolVersion, String serverVersion, String motd, public LegacyPingResponse(int protocolVersion, String serverVersion, String motd,
int playersOnline, int playersMax) { int playersOnline, int playersMax) {
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
this.serverVersion = serverVersion; this.serverVersion = serverVersion;
this.motd = motd; this.motd = motd;

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -49,7 +49,7 @@ public class LoginPluginMessage implements MinecraftPacket {
} }
@Override @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.id = ProtocolUtils.readVarInt(buf);
this.channel = ProtocolUtils.readString(buf); this.channel = ProtocolUtils.readString(buf);
if (buf.isReadable()) { if (buf.isReadable()) {
@ -60,7 +60,7 @@ public class LoginPluginMessage implements MinecraftPacket {
} }
@Override @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); ProtocolUtils.writeVarInt(buf, id);
if (channel == null) { if (channel == null) {
throw new IllegalStateException("Channel is not specified!"); throw new IllegalStateException("Channel is not specified!");

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -47,7 +47,7 @@ public class LoginPluginResponse implements MinecraftPacket {
} }
@Override @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.id = ProtocolUtils.readVarInt(buf);
this.success = buf.readBoolean(); this.success = buf.readBoolean();
if (buf.isReadable()) { if (buf.isReadable()) {
@ -58,7 +58,7 @@ public class LoginPluginResponse implements MinecraftPacket {
} }
@Override @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); ProtocolUtils.writeVarInt(buf, id);
buf.writeBoolean(success); buf.writeBoolean(success);
buf.writeBytes(data); buf.writeBytes(data);

Datei anzeigen

@ -3,9 +3,9 @@ package com.velocitypowered.proxy.protocol.packet;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -42,7 +42,7 @@ public class PlayerListItem implements MinecraftPacket {
} }
@Override @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); action = ProtocolUtils.readVarInt(buf);
int length = ProtocolUtils.readVarInt(buf); int length = ProtocolUtils.readVarInt(buf);
@ -84,7 +84,7 @@ public class PlayerListItem implements MinecraftPacket {
} }
@Override @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, action);
ProtocolUtils.writeVarInt(buf, items.size()); ProtocolUtils.writeVarInt(buf, items.size());
for (Item item : items) { for (Item item : items) {

Datei anzeigen

@ -2,9 +2,9 @@ package com.velocitypowered.proxy.protocol.packet;
import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY; 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.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
@ -43,14 +43,14 @@ public class PluginMessage implements MinecraftPacket {
} }
@Override @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.channel = ProtocolUtils.readString(buf);
this.data = new byte[buf.readableBytes()]; this.data = new byte[buf.readableBytes()];
buf.readBytes(data); buf.readBytes(data);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (channel == null) { if (channel == null) {
throw new IllegalStateException("Channel is not specified."); throw new IllegalStateException("Channel is not specified.");
} }

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -66,7 +66,7 @@ public class Respawn implements MinecraftPacket {
} }
@Override @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.dimension = buf.readInt();
this.difficulty = buf.readUnsignedByte(); this.difficulty = buf.readUnsignedByte();
this.gamemode = buf.readUnsignedByte(); this.gamemode = buf.readUnsignedByte();
@ -74,7 +74,7 @@ public class Respawn implements MinecraftPacket {
} }
@Override @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.writeInt(dimension);
buf.writeByte(difficulty); buf.writeByte(difficulty);
buf.writeByte(gamemode); buf.writeByte(gamemode);

Datei anzeigen

@ -1,9 +1,9 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -34,12 +34,12 @@ public class ServerLogin implements MinecraftPacket {
} }
@Override @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); username = ProtocolUtils.readString(buf, 16);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (username == null) { if (username == null) {
throw new IllegalStateException("No username found!"); throw new IllegalStateException("No username found!");
} }

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.UUID; import java.util.UUID;
@ -44,13 +44,13 @@ public class ServerLoginSuccess implements MinecraftPacket {
} }
@Override @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)); uuid = UUID.fromString(ProtocolUtils.readString(buf, 36));
username = ProtocolUtils.readString(buf, 16); username = ProtocolUtils.readString(buf, 16);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (uuid == null) { if (uuid == null) {
throw new IllegalStateException("No UUID specified!"); throw new IllegalStateException("No UUID specified!");
} }

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -33,12 +33,12 @@ public class SetCompression implements MinecraftPacket {
} }
@Override @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); this.threshold = ProtocolUtils.readVarInt(buf);
} }
@Override @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); ProtocolUtils.writeVarInt(buf, threshold);
} }

Datei anzeigen

@ -1,8 +1,9 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; 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.ByteBuf;
public class StatusPing implements MinecraftPacket { public class StatusPing implements MinecraftPacket {
@ -10,12 +11,12 @@ public class StatusPing implements MinecraftPacket {
private long randomId; private long randomId;
@Override @Override
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
randomId = buf.readLong(); randomId = buf.readLong();
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
buf.writeLong(randomId); buf.writeLong(randomId);
} }

Datei anzeigen

@ -1,8 +1,9 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; 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.ByteBuf;
public class StatusRequest implements MinecraftPacket { public class StatusRequest implements MinecraftPacket {
@ -14,12 +15,12 @@ public class StatusRequest implements MinecraftPacket {
} }
@Override @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. // There is no additional data to decode.
} }
@Override @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. // There is no data to decode.
} }

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -33,12 +33,12 @@ public class StatusResponse implements MinecraftPacket {
} }
@Override @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); status = ProtocolUtils.readString(buf, Short.MAX_VALUE);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (status == null) { if (status == null) {
throw new IllegalStateException("Status is not specified"); throw new IllegalStateException("Status is not specified");
} }

Datei anzeigen

@ -1,10 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; 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.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -62,9 +60,9 @@ public class TabCompleteRequest implements MinecraftPacket {
} }
@Override @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); this.command = ProtocolUtils.readString(buf);
if (protocolVersion >= MINECRAFT_1_9) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
this.assumeCommand = buf.readBoolean(); this.assumeCommand = buf.readBoolean();
} }
this.hasPosition = buf.readBoolean(); this.hasPosition = buf.readBoolean();
@ -74,12 +72,12 @@ public class TabCompleteRequest implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
if (command == null) { if (command == null) {
throw new IllegalStateException("Command is not specified"); throw new IllegalStateException("Command is not specified");
} }
ProtocolUtils.writeString(buf, command); ProtocolUtils.writeString(buf, command);
if (protocolVersion >= MINECRAFT_1_9) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
buf.writeBoolean(assumeCommand); buf.writeBoolean(assumeCommand);
} }
buf.writeBoolean(hasPosition); buf.writeBoolean(hasPosition);

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,7 +24,7 @@ public class TabCompleteResponse implements MinecraftPacket {
} }
@Override @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); int offersAvailable = ProtocolUtils.readVarInt(buf);
for (int i = 0; i < offersAvailable; i++) { for (int i = 0; i < offersAvailable; i++) {
offers.add(ProtocolUtils.readString(buf)); offers.add(ProtocolUtils.readString(buf));
@ -32,7 +32,7 @@ public class TabCompleteResponse implements MinecraftPacket {
} }
@Override @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()); ProtocolUtils.writeVarInt(buf, offers.size());
for (String offer : offers) { for (String offer : offers) {
ProtocolUtils.writeString(buf, offer); ProtocolUtils.writeString(buf, offer);

Datei anzeigen

@ -1,8 +1,8 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -26,14 +26,14 @@ public class TitlePacket implements MinecraftPacket {
private int fadeOut; private int fadeOut;
@Override @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 throw new UnsupportedOperationException(); // encode only
} }
@Override @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, 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 // 1.11+ shifted the action enum by 1 to handle the action bar
switch (action) { switch (action) {
case SET_TITLE: case SET_TITLE:
@ -118,23 +118,23 @@ public class TitlePacket implements MinecraftPacket {
this.fadeOut = fadeOut; this.fadeOut = fadeOut;
} }
public static TitlePacket hideForProtocolVersion(int protocolVersion) { public static TitlePacket hideForProtocolVersion(ProtocolVersion protocolVersion) {
TitlePacket packet = new TitlePacket(); 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); : TitlePacket.HIDE_OLD);
return packet; return packet;
} }
public static TitlePacket resetForProtocolVersion(int protocolVersion) { public static TitlePacket resetForProtocolVersion(ProtocolVersion protocolVersion) {
TitlePacket packet = new TitlePacket(); 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); : TitlePacket.RESET_OLD);
return packet; return packet;
} }
public static TitlePacket timesForProtocolVersion(int protocolVersion) { public static TitlePacket timesForProtocolVersion(ProtocolVersion protocolVersion) {
TitlePacket packet = new TitlePacket(); 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); : TitlePacket.SET_TIMES_OLD);
return packet; return packet;
} }

Datei anzeigen

@ -6,7 +6,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.util.ProxyVersion; 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.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -80,10 +80,11 @@ public class PluginMessageUtil {
* @param channels the channels to register * @param channels the channels to register
* @return the plugin message to send * @return the plugin message to send
*/ */
public static PluginMessage constructChannelsPacket(int protocolVersion,
Collection<String> channels) { public static PluginMessage constructChannelsPacket(ProtocolVersion protocolVersion,
checkNotNull(channels, "channels"); Collection<String> channels) {
String channelName = protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ? REGISTER_CHANNEL Preconditions.checkNotNull(channels, "channels");
String channelName = protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? REGISTER_CHANNEL
: REGISTER_CHANNEL_LEGACY; : REGISTER_CHANNEL_LEGACY;
PluginMessage message = new PluginMessage(); PluginMessage message = new PluginMessage();
message.setChannel(channelName); message.setChannel(channelName);

Datei anzeigen

@ -2,10 +2,10 @@ package com.velocitypowered.proxy.server;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.Handshake;
import com.velocitypowered.proxy.protocol.packet.StatusRequest; import com.velocitypowered.proxy.protocol.packet.StatusRequest;
@ -33,7 +33,7 @@ public class PingSessionHandler implements MinecraftSessionHandler {
handshake.setNextStatus(StateRegistry.STATUS_ID); handshake.setNextStatus(StateRegistry.STATUS_ID);
handshake.setServerAddress(server.getServerInfo().getAddress().getHostString()); handshake.setServerAddress(server.getServerInfo().getAddress().getHostString());
handshake.setPort(server.getServerInfo().getAddress().getPort()); handshake.setPort(server.getServerInfo().getAddress().getPort());
handshake.setProtocolVersion(ProtocolConstants.MINIMUM_GENERIC_VERSION); handshake.setProtocolVersion(ProtocolVersion.MINIMUM_VERSION);
connection.write(handshake); connection.write(handshake);
connection.setState(StateRegistry.STATUS); connection.setState(StateRegistry.STATUS);

Datei anzeigen

@ -18,7 +18,7 @@ import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; 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.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
@ -74,9 +74,9 @@ public class VelocityRegisteredServer implements RegisteredServer {
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
.addLast(MINECRAFT_DECODER, .addLast(MINECRAFT_DECODER,
new MinecraftDecoder(ProtocolConstants.Direction.CLIENTBOUND)) new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND))
.addLast(MINECRAFT_ENCODER, .addLast(MINECRAFT_ENCODER,
new MinecraftEncoder(ProtocolConstants.Direction.SERVERBOUND)); new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND));
MinecraftConnection connection = new MinecraftConnection(ch, server); MinecraftConnection connection = new MinecraftConnection(ch, server);
connection.setState(StateRegistry.HANDSHAKE); connection.setState(StateRegistry.HANDSHAKE);

Datei anzeigen

@ -6,11 +6,13 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.messages.ChannelRegistrar; import com.velocitypowered.api.proxy.messages.ChannelRegistrar;
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import com.velocitypowered.api.network.ProtocolVersion;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class VelocityChannelRegistrar implements ChannelRegistrar { public class VelocityChannelRegistrar implements ChannelRegistrar {
@ -70,8 +72,8 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
return identifierMap.get(id); return identifierMap.get(id);
} }
public Collection<String> getChannelsForProtocol(int protocolVersion) { public Collection<String> getChannelsForProtocol(ProtocolVersion protocolVersion) {
if (protocolVersion >= ProtocolConstants.MINECRAFT_1_13) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) {
return getModernChannelIds(); return getModernChannelIds();
} }
return getIdsForLegacyConnections(); return getIdsForLegacyConnections();

Datei anzeigen

@ -1,12 +1,13 @@
package com.velocitypowered.proxy.protocol; package com.velocitypowered.proxy.protocol;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12;
import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12_1; import static com.velocitypowered.api.network.ProtocolVersion.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_2;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.Handshake;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -14,7 +15,7 @@ class PacketRegistryTest {
private StateRegistry.PacketRegistry setupRegistry() { private StateRegistry.PacketRegistry setupRegistry() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolConstants.Direction.CLIENTBOUND); ProtocolUtils.Direction.CLIENTBOUND);
registry.register(Handshake.class, Handshake::new, registry.register(Handshake.class, Handshake::new,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false)); new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false));
return registry; return registry;
@ -23,46 +24,46 @@ class PacketRegistryTest {
@Test @Test
void packetRegistryWorks() { void packetRegistryWorks() {
StateRegistry.PacketRegistry registry = setupRegistry(); 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"); assertNotNull(packet, "Packet was not found in registry");
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class"); 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"); "Registry did not return the correct packet ID");
} }
@Test @Test
void packetRegistryLinkingWorks() { void packetRegistryLinkingWorks() {
StateRegistry.PacketRegistry registry = setupRegistry(); 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"); assertNotNull(packet, "Packet was not found in registry");
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class"); 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"); "Registry did not return the correct packet ID");
} }
@Test @Test
void failOnNoMappings() { void failOnNoMappings() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolConstants.Direction.CLIENTBOUND); ProtocolUtils.Direction.CLIENTBOUND);
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(Handshake.class, Handshake::new)); () -> registry.register(Handshake.class, Handshake::new));
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.getVersion(0).getPacketId(new Handshake())); () -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN).getPacketId(new Handshake()));
} }
@Test @Test
void registrySuppliesCorrectPacketsByProtocol() { void registrySuppliesCorrectPacketsByProtocol() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolConstants.Direction.CLIENTBOUND); ProtocolUtils.Direction.CLIENTBOUND);
registry.register(Handshake.class, Handshake::new, registry.register(Handshake.class, Handshake::new,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false), new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false),
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false)); new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false));
assertEquals(Handshake.class, assertEquals(Handshake.class,
registry.getVersion(MINECRAFT_1_12).createPacket(0x00).getClass()); registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0x00).getClass());
assertEquals(Handshake.class, assertEquals(Handshake.class,
registry.getVersion(MINECRAFT_1_12_1).createPacket(0x01).getClass()); registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0x01).getClass());
assertEquals(Handshake.class, assertEquals(Handshake.class,
registry.getVersion(MINECRAFT_1_12_2).createPacket(0x01).getClass()); registry.getProtocolRegistry(MINECRAFT_1_12_2).createPacket(0x01).getClass());
} }
} }