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

Finish overhaul of packet state/registry system

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-05-11 03:21:08 -04:00
Ursprung af38e19a26
Commit b239a91388
24 geänderte Dateien mit 376 neuen und 262 gelöschten Zeilen

Datei anzeigen

@ -36,7 +36,6 @@ import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
import com.velocitypowered.proxy.connection.client.LoginSessionHandler; import com.velocitypowered.proxy.connection.client.LoginSessionHandler;
import com.velocitypowered.proxy.connection.client.StatusSessionHandler; import com.velocitypowered.proxy.connection.client.StatusSessionHandler;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
import com.velocitypowered.proxy.network.pipeline.MinecraftCipherDecoder; import com.velocitypowered.proxy.network.pipeline.MinecraftCipherDecoder;
@ -45,6 +44,8 @@ import com.velocitypowered.proxy.network.pipeline.MinecraftCompressDecoder;
import com.velocitypowered.proxy.network.pipeline.MinecraftCompressorAndLengthEncoder; import com.velocitypowered.proxy.network.pipeline.MinecraftCompressorAndLengthEncoder;
import com.velocitypowered.proxy.network.pipeline.MinecraftDecoder; import com.velocitypowered.proxy.network.pipeline.MinecraftDecoder;
import com.velocitypowered.proxy.network.pipeline.MinecraftEncoder; import com.velocitypowered.proxy.network.pipeline.MinecraftEncoder;
import com.velocitypowered.proxy.network.registry.protocol.ProtocolRegistry;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import com.velocitypowered.proxy.util.except.QuietDecoderException; import com.velocitypowered.proxy.util.except.QuietDecoderException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
@ -75,7 +76,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
private final Channel channel; private final Channel channel;
private SocketAddress remoteAddress; private SocketAddress remoteAddress;
private StateRegistry state; private ProtocolRegistry state;
private @Nullable MinecraftSessionHandler sessionHandler; private @Nullable MinecraftSessionHandler sessionHandler;
private ProtocolVersion protocolVersion; private ProtocolVersion protocolVersion;
private @Nullable MinecraftConnectionAssociation association; private @Nullable MinecraftConnectionAssociation association;
@ -92,7 +93,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
this.channel = channel; this.channel = channel;
this.remoteAddress = channel.remoteAddress(); this.remoteAddress = channel.remoteAddress();
this.server = server; this.server = server;
this.state = StateRegistry.HANDSHAKE; this.state = ProtocolStates.HANDSHAKE;
} }
@Override @Override
@ -247,7 +248,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
if (channel.isActive()) { if (channel.isActive()) {
boolean is17 = this.getProtocolVersion().lt(ProtocolVersion.MINECRAFT_1_8) boolean is17 = this.getProtocolVersion().lt(ProtocolVersion.MINECRAFT_1_8)
&& this.getProtocolVersion().gte(ProtocolVersion.MINECRAFT_1_7_2); && this.getProtocolVersion().gte(ProtocolVersion.MINECRAFT_1_7_2);
if (is17 && this.getState() != StateRegistry.STATUS) { if (is17 && this.getState() != ProtocolStates.STATUS) {
channel.eventLoop().execute(() -> { channel.eventLoop().execute(() -> {
// 1.7.x versions have a race condition with switching protocol states, so just explicitly // 1.7.x versions have a race condition with switching protocol states, so just explicitly
// close the connection after a short while. // close the connection after a short while.
@ -307,7 +308,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
return remoteAddress; return remoteAddress;
} }
public StateRegistry getState() { public ProtocolRegistry getState() {
return state; return state;
} }
@ -341,7 +342,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
* Changes the state of the Minecraft connection. * Changes the state of the Minecraft connection.
* @param state the new state * @param state the new state
*/ */
public void setState(StateRegistry state) { public void setState(ProtocolRegistry state) {
ensureInEventLoop(); ensureInEventLoop();
this.state = state; this.state = state;

Datei anzeigen

@ -27,13 +27,13 @@ import com.velocitypowered.proxy.connection.VelocityConstants;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import com.velocitypowered.proxy.util.except.QuietRuntimeException; import com.velocitypowered.proxy.util.except.QuietRuntimeException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -46,7 +46,6 @@ import javax.crypto.Mac;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
public class LoginSessionHandler implements MinecraftSessionHandler { public class LoginSessionHandler implements MinecraftSessionHandler {
@ -119,7 +118,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
// Move into the PLAY phase. // Move into the PLAY phase.
MinecraftConnection smc = serverConn.ensureConnected(); MinecraftConnection smc = serverConn.ensureConnected();
smc.setState(StateRegistry.PLAY); smc.setState(ProtocolStates.PLAY);
// Switch to the transition handler. // Switch to the transition handler.
smc.setSessionHandler(new TransitionSessionHandler(server, serverConn, resultFuture)); smc.setSessionHandler(new TransitionSessionHandler(server, serverConn, resultFuture));

Datei anzeigen

@ -38,11 +38,11 @@ import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.connection.registry.DimensionRegistry; import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.server.VelocityRegisteredServer;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -167,11 +167,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
int port = destinationAddr instanceof InetSocketAddress int port = destinationAddr instanceof InetSocketAddress
? ((InetSocketAddress) destinationAddr).getPort() : 0; ? ((InetSocketAddress) destinationAddr).getPort() : 0;
ServerboundHandshakePacket handshake = new ServerboundHandshakePacket(protocolVersion, ServerboundHandshakePacket handshake = new ServerboundHandshakePacket(protocolVersion,
address, port, StateRegistry.LOGIN_ID); address, port, ServerboundHandshakePacket.LOGIN_ID);
mc.delayedWrite(handshake); mc.delayedWrite(handshake);
mc.setProtocolVersion(protocolVersion); mc.setProtocolVersion(protocolVersion);
mc.setState(StateRegistry.LOGIN); mc.setState(ProtocolStates.LOGIN);
mc.delayedWrite(new ServerboundServerLoginPacket(proxyPlayer.username())); mc.delayedWrite(new ServerboundServerLoginPacket(proxyPlayer.username()));
mc.flush(); mc.flush();
} }

Datei anzeigen

@ -41,7 +41,6 @@ import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases;
import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder; import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.network.PluginMessageUtil; import com.velocitypowered.proxy.network.PluginMessageUtil;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket;
@ -57,6 +56,7 @@ import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlive
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -69,7 +69,6 @@ import java.util.Optional;
import java.util.Queue; import java.util.Queue;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
@ -210,7 +209,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
VelocityServerConnection serverConn = player.getConnectedServer(); VelocityServerConnection serverConn = player.getConnectedServer();
MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null; MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null;
if (serverConn != null && backendConn != null) { if (serverConn != null && backendConn != null) {
if (backendConn.getState() != StateRegistry.PLAY) { if (backendConn.getState() != ProtocolStates.PLAY) {
logger.warn("A plugin message was received while the backend server was not " logger.warn("A plugin message was received while the backend server was not "
+ "ready. Channel: {}. Packet discarded.", packet.getChannel()); + "ready. Channel: {}. Packet discarded.", packet.getChannel());
} else if (PluginMessageUtil.isRegister(packet)) { } else if (PluginMessageUtil.isRegister(packet)) {

Datei anzeigen

@ -58,7 +58,6 @@ import com.velocitypowered.proxy.connection.util.ConnectionMessages;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.network.PluginMessageUtil; import com.velocitypowered.proxy.network.PluginMessageUtil;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
@ -68,6 +67,7 @@ import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourceP
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTitlePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTitlePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.server.VelocityRegisteredServer;
import com.velocitypowered.proxy.tablist.VelocityTabList; import com.velocitypowered.proxy.tablist.VelocityTabList;
import com.velocitypowered.proxy.tablist.VelocityTabListLegacy; import com.velocitypowered.proxy.tablist.VelocityTabListLegacy;
@ -769,7 +769,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
* ID last sent by the server. * ID last sent by the server.
*/ */
public void sendKeepAlive() { public void sendKeepAlive() {
if (connection.getState() == StateRegistry.PLAY) { if (connection.getState() == ProtocolStates.PLAY) {
connection.write(new ClientboundKeepAlivePacket(ThreadLocalRandom.current().nextLong())); connection.write(new ClientboundKeepAlivePacket(ThreadLocalRandom.current().nextLong()));
} }
} }

Datei anzeigen

@ -29,12 +29,13 @@ import com.velocitypowered.proxy.connection.ConnectionTypes;
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.connection.forge.legacy.LegacyForgeConstants; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.legacy.LegacyDisconnectPacket; import com.velocitypowered.proxy.network.packet.legacy.LegacyDisconnectPacket;
import com.velocitypowered.proxy.network.packet.legacy.LegacyHandshakePacket; import com.velocitypowered.proxy.network.packet.legacy.LegacyHandshakePacket;
import com.velocitypowered.proxy.network.packet.legacy.LegacyPingPacket; import com.velocitypowered.proxy.network.packet.legacy.LegacyPingPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.registry.protocol.ProtocolRegistry;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -81,7 +82,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
public boolean handle(ServerboundHandshakePacket handshake) { public boolean handle(ServerboundHandshakePacket handshake) {
InitialInboundConnection ic = new InitialInboundConnection(connection, InitialInboundConnection ic = new InitialInboundConnection(connection,
cleanVhost(handshake.getServerAddress()), handshake); cleanVhost(handshake.getServerAddress()), handshake);
StateRegistry nextState = getStateForProtocol(handshake.getNextStatus()); ProtocolRegistry nextState = getStateForProtocol(handshake.getNextStatus());
if (nextState == null) { if (nextState == null) {
LOGGER.error("{} provided invalid protocol {}", ic, handshake.getNextStatus()); LOGGER.error("{} provided invalid protocol {}", ic, handshake.getNextStatus());
connection.close(true); connection.close(true);
@ -90,28 +91,25 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
connection.setProtocolVersion(handshake.getProtocolVersion()); connection.setProtocolVersion(handshake.getProtocolVersion());
connection.setAssociation(ic); connection.setAssociation(ic);
switch (nextState) { if (nextState == ProtocolStates.STATUS) {
case STATUS: connection.setSessionHandler(new StatusSessionHandler(server, connection, ic));
connection.setSessionHandler(new StatusSessionHandler(server, connection, ic)); } else if (nextState == ProtocolStates.LOGIN) {
break; this.handleLogin(handshake, ic);
case LOGIN: } else {
this.handleLogin(handshake, ic); // If you get this, it's a bug in Velocity.
break; throw new AssertionError("getStateForProtocol provided invalid state!");
default:
// If you get this, it's a bug in Velocity.
throw new AssertionError("getStateForProtocol provided invalid state!");
} }
} }
return true; return true;
} }
private static @Nullable StateRegistry getStateForProtocol(int status) { private static @Nullable ProtocolRegistry getStateForProtocol(int status) {
switch (status) { switch (status) {
case StateRegistry.STATUS_ID: case ServerboundHandshakePacket.STATUS_ID:
return StateRegistry.STATUS; return ProtocolStates.STATUS;
case StateRegistry.LOGIN_ID: case ServerboundHandshakePacket.LOGIN_ID:
return StateRegistry.LOGIN; return ProtocolStates.LOGIN;
default: default:
return null; return null;
} }

Datei anzeigen

@ -46,12 +46,12 @@ 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.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptionResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptionResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
@ -287,7 +287,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
mcConnection.write(new ClientboundServerLoginSuccessPacket(playerUniqueId, player.username())); mcConnection.write(new ClientboundServerLoginSuccessPacket(playerUniqueId, player.username()));
mcConnection.setAssociation(player); mcConnection.setAssociation(player);
mcConnection.setState(StateRegistry.PLAY); mcConnection.setState(ProtocolStates.PLAY);
server.eventManager().fire(new LoginEventImpl(player)) server.eventManager().fire(new LoginEventImpl(player))
.thenAcceptAsync(event -> { .thenAcceptAsync(event -> {

Datei anzeigen

@ -41,6 +41,8 @@ public class ServerboundHandshakePacket implements Packet {
out.writeShort(packet.port); out.writeShort(packet.port);
ProtocolUtils.writeVarInt(out, packet.nextStatus); ProtocolUtils.writeVarInt(out, packet.nextStatus);
}; };
public static final int STATUS_ID = 1;
public static final int LOGIN_ID = 2;
private final ProtocolVersion protocolVersion; private final ProtocolVersion protocolVersion;
private final String serverAddress; private final String serverAddress;

Datei anzeigen

@ -20,9 +20,11 @@ package com.velocitypowered.proxy.network.pipeline;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryMap;
import com.velocitypowered.proxy.network.registry.protocol.ProtocolRegistry;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import com.velocitypowered.proxy.util.except.QuietRuntimeException; import com.velocitypowered.proxy.util.except.QuietRuntimeException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -37,8 +39,9 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
+ "developer, launch Velocity with -Dvelocity.packet-decode-logging=true to see more."); + "developer, launch Velocity with -Dvelocity.packet-decode-logging=true to see more.");
private final PacketDirection direction; private final PacketDirection direction;
private StateRegistry state; private ProtocolVersion version;
private StateRegistry.PacketRegistry.ProtocolRegistry registry; private ProtocolRegistry state;
private PacketRegistryMap registry;
/** /**
* Creates a new {@code MinecraftDecoder} decoding packets from the specified {@code direction}. * Creates a new {@code MinecraftDecoder} decoding packets from the specified {@code direction}.
@ -47,9 +50,9 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
*/ */
public MinecraftDecoder(PacketDirection direction) { public MinecraftDecoder(PacketDirection direction) {
this.direction = Preconditions.checkNotNull(direction, "direction"); this.direction = Preconditions.checkNotNull(direction, "direction");
this.registry = StateRegistry.HANDSHAKE.getProtocolRegistry(direction, this.state = ProtocolStates.HANDSHAKE;
ProtocolVersion.MINIMUM_VERSION); this.version = ProtocolVersion.MINIMUM_VERSION;
this.state = StateRegistry.HANDSHAKE; this.registry = this.state.lookup(direction, ProtocolVersion.MINIMUM_VERSION);
} }
@Override @Override
@ -72,7 +75,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
int packetId = ProtocolUtils.readVarInt(buf); int packetId = ProtocolUtils.readVarInt(buf);
Packet packet = null; Packet packet = null;
try { try {
packet = this.registry.readPacket(packetId, buf, registry.version); packet = this.registry.readPacket(packetId, buf, this.version);
} catch (Exception e) { } catch (Exception e) {
throw handleDecodeFailure(e, packet, packetId); // TODO: packet is always null throw handleDecodeFailure(e, packet, packetId); // TODO: packet is always null
} }
@ -92,8 +95,8 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
} }
private void doLengthSanityChecks(ByteBuf buf, Packet packet) throws Exception { private void doLengthSanityChecks(ByteBuf buf, Packet packet) throws Exception {
int expectedMinLen = packet.expectedMinLength(buf, direction, registry.version); int expectedMinLen = packet.expectedMinLength(buf, direction, version);
int expectedMaxLen = packet.expectedMaxLength(buf, direction, registry.version); int expectedMaxLen = packet.expectedMaxLength(buf, direction, version);
if (expectedMaxLen != -1 && buf.readableBytes() > expectedMaxLen) { if (expectedMaxLen != -1 && buf.readableBytes() > expectedMaxLen) {
throw handleOverflow(packet, expectedMaxLen, buf.readableBytes()); throw handleOverflow(packet, expectedMaxLen, buf.readableBytes());
} }
@ -130,16 +133,17 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
} }
private String getExtraConnectionDetail(int packetId) { private String getExtraConnectionDetail(int packetId) {
return "Direction " + direction + " Protocol " + registry.version + " State " + state return "Direction " + direction + " Protocol " + version + " State " + state
+ " ID " + Integer.toHexString(packetId); + " ID " + Integer.toHexString(packetId);
} }
public void setProtocolVersion(ProtocolVersion protocolVersion) { public void setProtocolVersion(ProtocolVersion protocolVersion) {
this.registry = state.getProtocolRegistry(direction, protocolVersion); this.version = protocolVersion;
this.registry = state.lookup(direction, protocolVersion);
} }
public void setState(StateRegistry state) { public void setState(ProtocolRegistry state) {
this.state = state; this.state = state;
this.setProtocolVersion(registry.version); this.setProtocolVersion(this.version);
} }
} }

Datei anzeigen

@ -19,10 +19,11 @@ package com.velocitypowered.proxy.network.pipeline;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryMap;
import com.velocitypowered.proxy.network.registry.protocol.ProtocolRegistry;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
@ -30,8 +31,9 @@ import io.netty.handler.codec.MessageToByteEncoder;
public class MinecraftEncoder extends MessageToByteEncoder<Packet> { public class MinecraftEncoder extends MessageToByteEncoder<Packet> {
private final PacketDirection direction; private final PacketDirection direction;
private StateRegistry state; private ProtocolRegistry state;
private StateRegistry.PacketRegistry.ProtocolRegistry registry; private PacketRegistryMap registry;
private ProtocolVersion version;
/** /**
* Creates a new {@code MinecraftEncoder} encoding packets for the specified {@code direction}. * Creates a new {@code MinecraftEncoder} encoding packets for the specified {@code direction}.
@ -40,22 +42,23 @@ public class MinecraftEncoder extends MessageToByteEncoder<Packet> {
*/ */
public MinecraftEncoder(PacketDirection direction) { public MinecraftEncoder(PacketDirection direction) {
this.direction = Preconditions.checkNotNull(direction, "direction"); this.direction = Preconditions.checkNotNull(direction, "direction");
this.registry = StateRegistry.HANDSHAKE this.state = ProtocolStates.HANDSHAKE;
.getProtocolRegistry(direction, ProtocolVersion.MINIMUM_VERSION); this.version = ProtocolVersion.MINIMUM_VERSION;
this.state = StateRegistry.HANDSHAKE; this.registry = this.state.lookup(direction, ProtocolVersion.MINIMUM_VERSION);
} }
@Override @Override
protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) { protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) {
this.registry.writePacket(msg, out, registry.version); this.registry.writePacket(msg, out, this.version);
} }
public void setProtocolVersion(final ProtocolVersion protocolVersion) { public void setProtocolVersion(final ProtocolVersion protocolVersion) {
this.registry = state.getProtocolRegistry(direction, protocolVersion); this.version = protocolVersion;
this.registry = this.state.lookup(direction, protocolVersion);
} }
public void setState(StateRegistry state) { public void setState(ProtocolRegistry state) {
this.state = state; this.state = state;
this.setProtocolVersion(registry.version); this.setProtocolVersion(version);
} }
} }

Datei anzeigen

@ -1,6 +1,24 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.packet; package com.velocitypowered.proxy.network.registry.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter; import com.velocitypowered.proxy.network.packet.PacketWriter;
@ -19,6 +37,7 @@ public class DensePacketRegistryMap implements PacketRegistryMap {
private final PacketReader<?>[] readersById; private final PacketReader<?>[] readersById;
private final PacketWriter[] writersByClass; private final PacketWriter[] writersByClass;
private final Class<?>[] classesById; private final Class<?>[] classesById;
private final int[] idsByKey;
public DensePacketRegistryMap(Int2ObjectMap<PacketMapping<?>> mappings) { public DensePacketRegistryMap(Int2ObjectMap<PacketMapping<?>> mappings) {
int size = mappings.keySet().stream().mapToInt(x -> x).max().orElse(0) + 1; int size = mappings.keySet().stream().mapToInt(x -> x).max().orElse(0) + 1;
@ -26,17 +45,19 @@ public class DensePacketRegistryMap implements PacketRegistryMap {
this.readersById = new PacketReader[size]; this.readersById = new PacketReader[size];
this.writersByClass = new PacketWriter[size * 2]; this.writersByClass = new PacketWriter[size * 2];
this.classesById = new Class[size * 2]; this.classesById = new Class[size * 2];
this.idsByKey = new int[size * 2];
for (PacketMapping<?> value : mappings.values()) { for (PacketMapping<?> value : mappings.values()) {
this.readersById[value.id] = value.reader; this.readersById[value.id] = value.reader;
this.place(value.packetClass, value.writer); this.place(value.id, value.packetClass, value.writer);
} }
} }
private void place(Class<?> key, PacketWriter<?> value) { private void place(int packetId, Class<?> key, PacketWriter<?> value) {
int bucket = findEmpty(key); int bucket = findEmpty(key);
this.writersByClass[bucket] = value; this.writersByClass[bucket] = value;
this.classesById[bucket] = key; this.classesById[bucket] = key;
this.idsByKey[bucket] = packetId;
} }
private int findEmpty(Class<?> key) { private int findEmpty(Class<?> key) {
@ -86,9 +107,10 @@ public class DensePacketRegistryMap implements PacketRegistryMap {
@Override @Override
public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) { public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) {
int id = this.index(packet.getClass()); int bucket = this.index(packet.getClass());
if (id != -1) { if (bucket != -1) {
this.writersByClass[id].write(buf, packet, version); ProtocolUtils.writeVarInt(buf, this.idsByKey[bucket]);
this.writersByClass[bucket].write(buf, packet, version);
} else { } else {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Unable to find id for packet of type %s in protocol %s", "Unable to find id for packet of type %s in protocol %s",

Datei anzeigen

@ -1,3 +1,20 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.packet; package com.velocitypowered.proxy.network.registry.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
@ -21,7 +38,7 @@ public class EmptyPacketRegistryMap implements PacketRegistryMap {
@Override @Override
public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) { public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Unable to find id for packet of type %s in protocol %s", "Unable to find id for packet of type %s for version %s",
packet.getClass().getName(), version packet.getClass().getName(), version
)); ));
} }

Datei anzeigen

@ -1,3 +1,20 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.packet; package com.velocitypowered.proxy.network.registry.packet;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
@ -16,8 +33,7 @@ public class PacketRegistryBuilder {
this.mappings = new Int2ObjectOpenHashMap<>(); this.mappings = new Int2ObjectOpenHashMap<>();
} }
public PacketRegistryBuilder( public PacketRegistryBuilder(Int2ObjectMap<PacketMapping<?>> mappings, boolean dense) {
Int2ObjectMap<PacketMapping<?>> mappings, boolean dense) {
this.mappings = new Int2ObjectOpenHashMap<>(mappings); this.mappings = new Int2ObjectOpenHashMap<>(mappings);
this.dense = dense; this.dense = dense;
} }
@ -29,7 +45,7 @@ public class PacketRegistryBuilder {
} }
public <P extends Packet> PacketRegistryBuilder register(int id, Class<P> packetClass, public <P extends Packet> PacketRegistryBuilder register(int id, Class<P> packetClass,
PacketWriter<P> writer, PacketReader<P> reader) { PacketReader<P> reader, PacketWriter<P> writer) {
mappings.put(id, new PacketMapping(id, packetClass, writer, reader)); mappings.put(id, new PacketMapping(id, packetClass, writer, reader));
return this; return this;
} }

Datei anzeigen

@ -1,3 +1,20 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.packet; package com.velocitypowered.proxy.network.registry.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;

Datei anzeigen

@ -1,6 +1,24 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.packet; package com.velocitypowered.proxy.network.registry.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter; import com.velocitypowered.proxy.network.packet.PacketWriter;
@ -60,7 +78,7 @@ public class RegularPacketRegistryMap implements PacketRegistryMap {
PacketWriter writer = this.writersById.get(packetId); PacketWriter writer = this.writersById.get(packetId);
assert writer != null; assert writer != null;
ProtocolUtils.writeVarInt(buf, packetId);
writer.write(buf, packet, version); writer.write(buf, packet, version);
} }
} }

Datei anzeigen

@ -1,3 +1,20 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.protocol; package com.velocitypowered.proxy.network.registry.protocol;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;

Datei anzeigen

@ -1,3 +1,20 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.protocol; package com.velocitypowered.proxy.network.registry.protocol;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;

Datei anzeigen

@ -1,3 +1,20 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.protocol; package com.velocitypowered.proxy.network.registry.protocol;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;

Datei anzeigen

@ -0,0 +1,84 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.state;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptionResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryBuilder;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryMap;
public class LoginPacketRegistry {
private LoginPacketRegistry() {
throw new AssertionError();
}
public static final PacketRegistryMap SERVERBOUND_LOGIN_1_7 = baseProtocolServerbound().build();
public static final PacketRegistryMap CLIENTBOUND_LOGIN_1_7 = baseProtocolClientbound().build();
public static final PacketRegistryMap CLIENTBOUND_LOGIN_1_8 = baseProtocolClientbound()
.register(0x03, ClientboundSetCompressionPacket.class,
ClientboundSetCompressionPacket.DECODER,
ClientboundSetCompressionPacket.ENCODER)
.build();
public static final PacketRegistryMap CLIENTBOUND_LOGIN_1_13 = baseProtocolClientbound()
.register(0x03, ClientboundSetCompressionPacket.class,
ClientboundSetCompressionPacket.DECODER,
ClientboundSetCompressionPacket.ENCODER)
.register(0x04, ClientboundLoginPluginMessagePacket.class,
ClientboundLoginPluginMessagePacket.DECODER,
ClientboundLoginPluginMessagePacket.ENCODER)
.build();
public static final PacketRegistryMap SERVERBOUND_LOGIN_1_13 = baseProtocolServerbound()
.register(0x02, ServerboundLoginPluginResponsePacket.class,
ServerboundLoginPluginResponsePacket.DECODER,
ServerboundLoginPluginResponsePacket.ENCODER)
.build();
private static PacketRegistryBuilder baseProtocolServerbound() {
return new PacketRegistryBuilder()
.dense()
.register(0x00, ServerboundServerLoginPacket.class, ServerboundServerLoginPacket.DECODER,
ServerboundServerLoginPacket.ENCODER
)
.register(0x01, ServerboundEncryptionResponsePacket.class,
ServerboundEncryptionResponsePacket.DECODER,
ServerboundEncryptionResponsePacket.ENCODER);
}
private static PacketRegistryBuilder baseProtocolClientbound() {
return new PacketRegistryBuilder()
.dense()
.register(0x00, ClientboundDisconnectPacket.class, ClientboundDisconnectPacket.DECODER,
ClientboundDisconnectPacket.ENCODER)
.register(0x01, ClientboundEncryptionRequestPacket.class,
ClientboundEncryptionRequestPacket.DECODER, ClientboundEncryptionRequestPacket.ENCODER)
.register(0x02, ClientboundServerLoginSuccessPacket.class,
ClientboundServerLoginSuccessPacket.DECODER,
ClientboundServerLoginSuccessPacket.ENCODER);
}
}

Datei anzeigen

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.velocitypowered.proxy.network; package com.velocitypowered.proxy.network.registry.state;
import static com.google.common.collect.Iterables.getLast; import static com.google.common.collect.Iterables.getLast;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12;
@ -33,6 +33,7 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION;
import static com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS; import static com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
@ -41,88 +42,44 @@ import com.velocitypowered.proxy.network.packet.clientbound.ClientboundAvailable
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundHeaderAndFooterPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundHeaderAndFooterPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundRespawnPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundRespawnPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundStatusPingPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundStatusResponsePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTitlePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTitlePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptionResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryMap;
import com.velocitypowered.proxy.network.registry.protocol.ProtocolRegistry;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.collection.IntObjectHashMap; 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.Collections;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects; import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public enum StateRegistry { class PlayPacketRegistry implements ProtocolRegistry {
HANDSHAKE(true) { static final ProtocolRegistry PLAY = new PlayPacketRegistry();
{
serverbound.register( private PlayPacketRegistry() {
ServerboundHandshakePacket.class, this.clientbound = new PacketRegistry(PacketDirection.CLIENTBOUND);
ServerboundHandshakePacket.DECODER, this.serverbound = new PacketRegistry(PacketDirection.SERVERBOUND);
ServerboundHandshakePacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false)
);
}
},
STATUS(true) {
{
serverbound.register(
ServerboundStatusRequestPacket.class,
ServerboundStatusRequestPacket.DECODER,
ServerboundStatusRequestPacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false)
);
serverbound.register(
ServerboundStatusPingPacket.class,
ServerboundStatusPingPacket.DECODER,
ServerboundStatusPingPacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false)
);
clientbound.register(
ClientboundStatusResponsePacket.class,
ClientboundStatusResponsePacket.DECODER,
ClientboundStatusResponsePacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false)
);
clientbound.register(
ClientboundStatusPingPacket.class,
ClientboundStatusPingPacket.DECODER,
ClientboundStatusPingPacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false)
);
}
},
PLAY(false) {
{ {
serverbound.register( serverbound.register(
ServerboundTabCompleteRequestPacket.class, ServerboundTabCompleteRequestPacket.class,
@ -346,73 +303,16 @@ public enum StateRegistry {
map(0x32, MINECRAFT_1_16_2, false) map(0x32, MINECRAFT_1_16_2, false)
); );
} }
},
LOGIN(true) {
{
serverbound.register(
ServerboundServerLoginPacket.class,
ServerboundServerLoginPacket.DECODER,
ServerboundServerLoginPacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false)
);
serverbound.register(
ServerboundEncryptionResponsePacket.class,
ServerboundEncryptionResponsePacket.DECODER,
ServerboundEncryptionResponsePacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false)
);
serverbound.register(
ServerboundLoginPluginResponsePacket.class,
ServerboundLoginPluginResponsePacket.DECODER,
ServerboundLoginPluginResponsePacket.ENCODER,
map(0x02, MINECRAFT_1_13, false)
);
clientbound.register( serverbound.compact();
ClientboundDisconnectPacket.class, clientbound.compact();
ClientboundDisconnectPacket.DECODER, }
ClientboundDisconnectPacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false)
);
clientbound.register(
ClientboundEncryptionRequestPacket.class,
ClientboundEncryptionRequestPacket.DECODER,
ClientboundEncryptionRequestPacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false)
);
clientbound.register(
ClientboundServerLoginSuccessPacket.class,
ClientboundServerLoginSuccessPacket.DECODER,
ClientboundServerLoginSuccessPacket.ENCODER,
map(0x02, MINECRAFT_1_7_2, false)
);
clientbound.register(
ClientboundSetCompressionPacket.class,
ClientboundSetCompressionPacket.DECODER,
ClientboundSetCompressionPacket.ENCODER,
map(0x03, MINECRAFT_1_8, false)
);
clientbound.register(
ClientboundLoginPluginMessagePacket.class,
ClientboundLoginPluginMessagePacket.DECODER,
ClientboundLoginPluginMessagePacket.ENCODER,
map(0x04, MINECRAFT_1_13, false)
);
}
};
public static final int STATUS_ID = 1;
public static final int LOGIN_ID = 2;
public final PacketRegistry clientbound; public final PacketRegistry clientbound;
public final PacketRegistry serverbound; public final PacketRegistry serverbound;
StateRegistry(boolean useMinimumIfVersionNotFound) { public PacketRegistryMap lookup(PacketDirection direction,
this.clientbound = new PacketRegistry(PacketDirection.CLIENTBOUND, useMinimumIfVersionNotFound); ProtocolVersion version) {
this.serverbound = new PacketRegistry(PacketDirection.SERVERBOUND, useMinimumIfVersionNotFound);
}
public PacketRegistry.ProtocolRegistry getProtocolRegistry(PacketDirection direction,
ProtocolVersion version) {
return (direction == PacketDirection.SERVERBOUND ? this.serverbound : this.clientbound) return (direction == PacketDirection.SERVERBOUND ? this.serverbound : this.clientbound)
.getProtocolRegistry(version); .getProtocolRegistry(version);
} }
@ -421,15 +321,9 @@ public enum StateRegistry {
private final PacketDirection direction; private final PacketDirection direction;
private final Map<ProtocolVersion, ProtocolRegistry> versions; private final Map<ProtocolVersion, ProtocolRegistry> versions;
private final boolean useMinimumIfVersionNotFound;
PacketRegistry(PacketDirection direction) { PacketRegistry(PacketDirection direction) {
this(direction, true);
}
PacketRegistry(PacketDirection direction, boolean useMinimumIfVersionNotFound) {
this.direction = direction; this.direction = direction;
this.useMinimumIfVersionNotFound = useMinimumIfVersionNotFound;
Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class); Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class);
for (ProtocolVersion version : ProtocolVersion.values()) { for (ProtocolVersion version : ProtocolVersion.values()) {
@ -438,15 +332,12 @@ public enum StateRegistry {
} }
} }
this.versions = Collections.unmodifiableMap(mutableVersions); this.versions = mutableVersions;
} }
ProtocolRegistry getProtocolRegistry(final ProtocolVersion version) { ProtocolRegistry getProtocolRegistry(final ProtocolVersion version) {
ProtocolRegistry registry = versions.get(version); ProtocolRegistry registry = versions.get(version);
if (registry == null) { if (registry == null) {
if (useMinimumIfVersionNotFound) {
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 registry; return registry;
@ -499,9 +390,26 @@ public enum StateRegistry {
} }
} }
public class ProtocolRegistry { public void compact() {
ProtocolRegistry last = this.versions.get(MINIMUM_VERSION);
for (Entry<ProtocolVersion, ProtocolRegistry> entry : this.versions
.entrySet()) {
if (entry.getValue() == last) {
continue;
}
public final ProtocolVersion version; if (entry.getValue().packetClassToId.equals(last.packetClassToId)
&& entry.getValue().packetClassToWriter.equals(last.packetClassToWriter)) {
entry.setValue(last);
} else {
last = entry.getValue();
}
}
}
public class ProtocolRegistry implements PacketRegistryMap {
private final ProtocolVersion version;
final IntObjectMap<PacketReader<? extends Packet>> packetIdToReader = final IntObjectMap<PacketReader<? extends Packet>> packetIdToReader =
new IntObjectHashMap<>(16, 0.5f); new IntObjectHashMap<>(16, 0.5f);
final Object2IntMap<Class<? extends Packet>> packetClassToId = final Object2IntMap<Class<? extends Packet>> packetClassToId =
@ -519,7 +427,6 @@ public enum StateRegistry {
* *
* @param id the packet ID * @param id the packet ID
* @param buf the bytebuf * @param buf the bytebuf
* @param version the protocol version
* @return the packet instance, or {@code null} if the ID is not registered * @return the packet instance, or {@code null} if the ID is not registered
*/ */
public @Nullable Packet readPacket(final int id, ByteBuf buf, ProtocolVersion version) { public @Nullable Packet readPacket(final int id, ByteBuf buf, ProtocolVersion version) {
@ -535,7 +442,6 @@ public enum StateRegistry {
* *
* @param packet the packet * @param packet the packet
* @param buf the bytebuf * @param buf the bytebuf
* @param version the protocol version
*/ */
public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) { public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) {
final int id = this.packetClassToId.getInt(packet.getClass()); final int id = this.packetClassToId.getInt(packet.getClass());

Datei anzeigen

@ -1,3 +1,20 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.network.registry.state; package com.velocitypowered.proxy.network.registry.state;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
@ -16,39 +33,43 @@ public class ProtocolStates {
public static final ProtocolRegistry HANDSHAKE; public static final ProtocolRegistry HANDSHAKE;
public static final ProtocolRegistry STATUS; public static final ProtocolRegistry STATUS;
public static final ProtocolRegistry LOGIN; public static final ProtocolRegistry LOGIN;
public static final ProtocolRegistry PLAY;
static { static {
HANDSHAKE = new SimpleProtocolRegistry( HANDSHAKE = new SimpleProtocolRegistry(
new PacketRegistryBuilder() new PacketRegistryBuilder()
.dense() .register(0x00, ServerboundHandshakePacket.class, ServerboundHandshakePacket.DECODER,
.register(0x00, ServerboundHandshakePacket.class, ServerboundHandshakePacket.ENCODER, ServerboundHandshakePacket.ENCODER)
ServerboundHandshakePacket.DECODER)
.build(), .build(),
EmptyPacketRegistryMap.INSTANCE); EmptyPacketRegistryMap.INSTANCE);
STATUS = new SimpleProtocolRegistry( STATUS = new SimpleProtocolRegistry(
new PacketRegistryBuilder() new PacketRegistryBuilder()
.dense()
.register(0x00, ServerboundStatusRequestPacket.class, .register(0x00, ServerboundStatusRequestPacket.class,
ServerboundStatusRequestPacket.ENCODER, ServerboundStatusRequestPacket.DECODER, ServerboundStatusRequestPacket.ENCODER
ServerboundStatusRequestPacket.DECODER) )
.register(0x01, ServerboundStatusPingPacket.class, .register(0x01, ServerboundStatusPingPacket.class,
ServerboundStatusPingPacket.ENCODER, ServerboundStatusPingPacket.DECODER, ServerboundStatusPingPacket.ENCODER
ServerboundStatusPingPacket.DECODER) )
.build(), .build(),
new PacketRegistryBuilder() new PacketRegistryBuilder()
.dense()
.register(0x00, ClientboundStatusResponsePacket.class, .register(0x00, ClientboundStatusResponsePacket.class,
ClientboundStatusResponsePacket.ENCODER, ClientboundStatusResponsePacket.DECODER, ClientboundStatusResponsePacket.ENCODER
ClientboundStatusResponsePacket.DECODER) )
.register(0x01, ClientboundStatusPingPacket.class, .register(0x01, ClientboundStatusPingPacket.class,
ClientboundStatusPingPacket.ENCODER, ClientboundStatusPingPacket.DECODER, ClientboundStatusPingPacket.ENCODER
ClientboundStatusPingPacket.DECODER) )
.build()); .build());
LOGIN = new VersionSpecificProtocolRegistry() LOGIN = new VersionSpecificProtocolRegistry()
.register(ProtocolVersion.MINECRAFT_1_7_2, ProtocolVersion.MINECRAFT_1_8, .register(ProtocolVersion.MINECRAFT_1_7_2, ProtocolVersion.MINECRAFT_1_7_6,
Version172To176.SERVERBOUND_LOGIN, Version172To176.CLIENTBOUND_LOGIN); LoginPacketRegistry.SERVERBOUND_LOGIN_1_7, LoginPacketRegistry.CLIENTBOUND_LOGIN_1_7)
.register(ProtocolVersion.MINECRAFT_1_8, ProtocolVersion.MINECRAFT_1_12_2,
LoginPacketRegistry.SERVERBOUND_LOGIN_1_7, LoginPacketRegistry.CLIENTBOUND_LOGIN_1_8)
.register(ProtocolVersion.MINECRAFT_1_13, ProtocolVersion.MAXIMUM_VERSION,
LoginPacketRegistry.SERVERBOUND_LOGIN_1_13, LoginPacketRegistry.CLIENTBOUND_LOGIN_1_13);
PLAY = PlayPacketRegistry.PLAY;
} }
private ProtocolStates() { private ProtocolStates() {

Datei anzeigen

@ -1,39 +0,0 @@
package com.velocitypowered.proxy.network.registry.state;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptionResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryBuilder;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryMap;
public class Version172To176 {
private Version172To176() {
throw new AssertionError();
}
public static final PacketRegistryMap SERVERBOUND_LOGIN = new PacketRegistryBuilder()
.dense()
.register(0x00, ServerboundServerLoginPacket.class, ServerboundServerLoginPacket.ENCODER,
ServerboundServerLoginPacket.DECODER)
.register(0x01, ServerboundEncryptionResponsePacket.class,
ServerboundEncryptionResponsePacket.ENCODER, ServerboundEncryptionResponsePacket.DECODER)
.build();
public static final PacketRegistryMap CLIENTBOUND_LOGIN = new PacketRegistryBuilder()
.dense()
.register(0x00, ClientboundDisconnectPacket.class, ClientboundDisconnectPacket.ENCODER,
ClientboundDisconnectPacket.DECODER)
.register(0x01, ClientboundEncryptionRequestPacket.class,
ClientboundEncryptionRequestPacket.ENCODER, ClientboundEncryptionRequestPacket.DECODER)
.register(0x02, ClientboundServerLoginSuccessPacket.class,
ClientboundServerLoginSuccessPacket.ENCODER, ClientboundServerLoginSuccessPacket.DECODER)
.build();
public static final PacketRegistryMap SERVERBOUND_PLAY = new PacketRegistryBuilder()
.register(0x14, ServerboundTabCompleteRequestPacket.class,
ServerboundTabCompleteRequestPacket.ENCODER, ServerboundTabCompleteRequestPacket.DECODER)
.build();
}

Datei anzeigen

@ -1,5 +0,0 @@
package com.velocitypowered.proxy.network.registry.version;
public class GenericVersions {
}

Datei anzeigen

@ -23,10 +23,10 @@ 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.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundStatusResponsePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundStatusResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket;
import com.velocitypowered.proxy.network.registry.state.ProtocolStates;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
@ -67,10 +67,10 @@ public class PingSessionHandler implements MinecraftSessionHandler {
version, version,
hostname, hostname,
port, port,
StateRegistry.STATUS_ID ServerboundHandshakePacket.STATUS_ID
)); ));
connection.setState(StateRegistry.STATUS); connection.setState(ProtocolStates.STATUS);
connection.delayedWrite(ServerboundStatusRequestPacket.INSTANCE); connection.delayedWrite(ServerboundStatusRequestPacket.INSTANCE);
connection.flush(); connection.flush();