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

Merge branch '2/new-registry' into dev/2.0.0

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-05-11 03:22:04 -04:00
Commit 3d459bcc28
22 geänderte Dateien mit 767 neuen und 193 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,14 +91,11 @@ 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));
break; } else if (nextState == ProtocolStates.LOGIN) {
case LOGIN:
this.handleLogin(handshake, ic); this.handleLogin(handshake, ic);
break; } else {
default:
// If you get this, it's a bug in Velocity. // If you get this, it's a bug in Velocity.
throw new AssertionError("getStateForProtocol provided invalid state!"); throw new AssertionError("getStateForProtocol provided invalid state!");
} }
@ -106,12 +104,12 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
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

@ -0,0 +1,122 @@
/*
* 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;
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.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryBuilder.PacketMapping;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Provides a packet registry map that is "dense", ideal for registries that are tightly packed
* together by ID. Lookups for readers are very fast (O(1)) and for writers uses an embedded
* open-addressing, probing hash map to conserve memory.
*/
public class DensePacketRegistryMap implements PacketRegistryMap {
private final PacketReader<?>[] readersById;
private final PacketWriter[] writersByClass;
private final Class<?>[] classesById;
private final int[] idsByKey;
public DensePacketRegistryMap(Int2ObjectMap<PacketMapping<?>> mappings) {
int size = mappings.keySet().stream().mapToInt(x -> x).max().orElse(0) + 1;
this.readersById = new PacketReader[size];
this.writersByClass = new PacketWriter[size * 2];
this.classesById = new Class[size * 2];
this.idsByKey = new int[size * 2];
for (PacketMapping<?> value : mappings.values()) {
this.readersById[value.id] = value.reader;
this.place(value.id, value.packetClass, value.writer);
}
}
private void place(int packetId, Class<?> key, PacketWriter<?> value) {
int bucket = findEmpty(key);
this.writersByClass[bucket] = value;
this.classesById[bucket] = key;
this.idsByKey[bucket] = packetId;
}
private int findEmpty(Class<?> key) {
int start = key.hashCode() % this.classesById.length;
int index = start;
for (;;) {
if (this.classesById[index] == null || this.classesById[index].equals(key)) {
// It's available, so no chance that this value exists anywhere in the map.
return index;
}
if ((index = (index + 1) % this.classesById.length) == start) {
return -1;
}
}
}
private int index(Class<?> key) {
int start = key.hashCode() % this.classesById.length;
int index = start;
for (;;) {
if (this.classesById[index] == null) {
// It's available, so no chance that this value exists anywhere in the map.
return -1;
}
if (key.equals(this.classesById[index])) {
return index;
}
// Conflict, keep probing ...
if ((index = (index + 1) % this.classesById.length) == start) {
return -1;
}
}
}
@Override
public @Nullable Packet readPacket(int id, ByteBuf buf, ProtocolVersion version) {
if (id < 0 || id >= this.readersById.length) {
return null;
}
return this.readersById[id].read(buf, version);
}
@Override
public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) {
int bucket = this.index(packet.getClass());
if (bucket != -1) {
ProtocolUtils.writeVarInt(buf, this.idsByKey[bucket]);
this.writersByClass[bucket].write(buf, packet, version);
} else {
throw new IllegalArgumentException(String.format(
"Unable to find id for packet of type %s in protocol %s",
packet.getClass().getName(), version
));
}
}
}

Datei anzeigen

@ -0,0 +1,45 @@
/*
* 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;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.Packet;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public class EmptyPacketRegistryMap implements PacketRegistryMap {
public static final EmptyPacketRegistryMap INSTANCE = new EmptyPacketRegistryMap();
private EmptyPacketRegistryMap() {
}
@Override
public @Nullable Packet readPacket(int id, ByteBuf buf, ProtocolVersion version) {
return null;
}
@Override
public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) {
throw new IllegalArgumentException(String.format(
"Unable to find id for packet of type %s for version %s",
packet.getClass().getName(), version
));
}
}

Datei anzeigen

@ -0,0 +1,86 @@
/*
* 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;
import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;
public class PacketRegistryBuilder {
private final Int2ObjectMap<PacketMapping<?>> mappings;
private boolean dense = false;
public PacketRegistryBuilder() {
this.mappings = new Int2ObjectOpenHashMap<>();
}
public PacketRegistryBuilder(Int2ObjectMap<PacketMapping<?>> mappings, boolean dense) {
this.mappings = new Int2ObjectOpenHashMap<>(mappings);
this.dense = dense;
}
public <P extends Packet> PacketRegistryBuilder register(int id, Class<P> packetClass,
PacketWriter<P> writer) {
mappings.put(id, new PacketMapping(id, packetClass, writer, null));
return this;
}
public <P extends Packet> PacketRegistryBuilder register(int id, Class<P> packetClass,
PacketReader<P> reader, PacketWriter<P> writer) {
mappings.put(id, new PacketMapping(id, packetClass, writer, reader));
return this;
}
public PacketRegistryBuilder dense() {
this.dense = true;
return this;
}
public PacketRegistryBuilder copy() {
return new PacketRegistryBuilder(this.mappings, this.dense);
}
public PacketRegistryMap build() {
if (this.dense) {
return new DensePacketRegistryMap(mappings);
} else {
return new RegularPacketRegistryMap(mappings);
}
}
static final class PacketMapping<P extends Packet> {
int id;
final Class<P> packetClass;
final PacketWriter<P> writer;
final @Nullable PacketReader<P> reader;
PacketMapping(int id, Class<P> packetClass,
PacketWriter<P> writer,
@Nullable PacketReader<P> reader) {
this.id = id;
this.packetClass = packetClass;
this.writer = writer;
this.reader = reader;
}
}
}

Datei anzeigen

@ -0,0 +1,29 @@
/*
* 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;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.Packet;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface PacketRegistryMap {
@Nullable Packet readPacket(final int id, ByteBuf buf, ProtocolVersion version);
<P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version);
}

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.packet;
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.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryBuilder.PacketMapping;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* The canonical implementation of the packet registry map.
*/
public class RegularPacketRegistryMap implements PacketRegistryMap {
private final Int2ObjectMap<PacketReader<?>> readersById;
private final Int2ObjectMap<PacketWriter<?>> writersById;
private final Object2IntMap<Class<?>> classesById;
public RegularPacketRegistryMap(Int2ObjectMap<PacketMapping<?>> mappings) {
int size = mappings.size();
this.readersById = new Int2ObjectOpenHashMap<>(size);
this.writersById = new Int2ObjectOpenHashMap<>(size);
this.classesById = new Object2IntOpenHashMap<>(size);
this.classesById.defaultReturnValue(Integer.MIN_VALUE);
for (PacketMapping<?> value : mappings.values()) {
if (value.reader != null) {
this.readersById.put(value.id, value.reader);
}
this.writersById.put(value.id, value.writer);
this.classesById.put(value.packetClass, value.id);
}
}
@Override
public @Nullable Packet readPacket(int id, ByteBuf buf, ProtocolVersion version) {
PacketReader<?> reader = this.readersById.get(id);
if (reader == null) {
return null;
}
return reader.read(buf, version);
}
@Override
public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) {
int packetId = this.classesById.getInt(packet.getClass());
if (packetId == Integer.MIN_VALUE) {
throw new IllegalArgumentException(String.format(
"Unable to find id for packet of type %s in protocol %s",
packet.getClass().getName(), version
));
}
PacketWriter writer = this.writersById.get(packetId);
assert writer != null;
ProtocolUtils.writeVarInt(buf, packetId);
writer.write(buf, packet, version);
}
}

Datei anzeigen

@ -0,0 +1,26 @@
/*
* 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;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryMap;
public interface ProtocolRegistry {
PacketRegistryMap lookup(PacketDirection direction, ProtocolVersion version);
}

Datei anzeigen

@ -0,0 +1,49 @@
/*
* 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;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryMap;
/**
* A flat protocol registry that does not care about the protocol version.
*/
public class SimpleProtocolRegistry implements ProtocolRegistry {
private final PacketRegistryMap serverbound;
private final PacketRegistryMap clientbound;
public SimpleProtocolRegistry(
PacketRegistryMap serverbound,
PacketRegistryMap clientbound) {
this.serverbound = serverbound;
this.clientbound = clientbound;
}
@Override
public PacketRegistryMap lookup(PacketDirection direction, ProtocolVersion version) {
if (direction == PacketDirection.SERVERBOUND) {
return this.serverbound;
} else if (direction == PacketDirection.CLIENTBOUND) {
return this.clientbound;
} else {
throw new NullPointerException("direction");
}
}
}

Datei anzeigen

@ -0,0 +1,59 @@
/*
* 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;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryMap;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
/**
* A version-aware protocol registry.
*/
public class VersionSpecificProtocolRegistry implements ProtocolRegistry {
private final Map<ProtocolVersion, PacketRegistryMap> serverboundByVersion;
private final Map<ProtocolVersion, PacketRegistryMap> clientboundByVersion;
public VersionSpecificProtocolRegistry() {
this.serverboundByVersion = new EnumMap<>(ProtocolVersion.class);
this.clientboundByVersion = new EnumMap<>(ProtocolVersion.class);
}
public VersionSpecificProtocolRegistry register(ProtocolVersion min, ProtocolVersion max,
PacketRegistryMap serverbound, PacketRegistryMap clientbound) {
for (ProtocolVersion version : EnumSet.range(min, max)) {
this.serverboundByVersion.put(version, serverbound);
this.clientboundByVersion.put(version, clientbound);
}
return this;
}
@Override
public PacketRegistryMap lookup(PacketDirection direction, ProtocolVersion version) {
if (direction == PacketDirection.SERVERBOUND) {
return this.serverboundByVersion.get(version);
} else if (direction == PacketDirection.CLIENTBOUND) {
return this.clientboundByVersion.get(version);
} else {
throw new NullPointerException("direction");
}
}
}

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,72 +303,15 @@ 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);
this.serverbound = new PacketRegistry(PacketDirection.SERVERBOUND, useMinimumIfVersionNotFound);
}
public PacketRegistry.ProtocolRegistry getProtocolRegistry(PacketDirection direction,
ProtocolVersion version) { 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

@ -0,0 +1,78 @@
/*
* 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.ClientboundStatusPingPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundStatusResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket;
import com.velocitypowered.proxy.network.registry.packet.EmptyPacketRegistryMap;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryBuilder;
import com.velocitypowered.proxy.network.registry.protocol.ProtocolRegistry;
import com.velocitypowered.proxy.network.registry.protocol.SimpleProtocolRegistry;
import com.velocitypowered.proxy.network.registry.protocol.VersionSpecificProtocolRegistry;
public class ProtocolStates {
public static final ProtocolRegistry HANDSHAKE;
public static final ProtocolRegistry STATUS;
public static final ProtocolRegistry LOGIN;
public static final ProtocolRegistry PLAY;
static {
HANDSHAKE = new SimpleProtocolRegistry(
new PacketRegistryBuilder()
.register(0x00, ServerboundHandshakePacket.class, ServerboundHandshakePacket.DECODER,
ServerboundHandshakePacket.ENCODER)
.build(),
EmptyPacketRegistryMap.INSTANCE);
STATUS = new SimpleProtocolRegistry(
new PacketRegistryBuilder()
.register(0x00, ServerboundStatusRequestPacket.class,
ServerboundStatusRequestPacket.DECODER, ServerboundStatusRequestPacket.ENCODER
)
.register(0x01, ServerboundStatusPingPacket.class,
ServerboundStatusPingPacket.DECODER, ServerboundStatusPingPacket.ENCODER
)
.build(),
new PacketRegistryBuilder()
.register(0x00, ClientboundStatusResponsePacket.class,
ClientboundStatusResponsePacket.DECODER, ClientboundStatusResponsePacket.ENCODER
)
.register(0x01, ClientboundStatusPingPacket.class,
ClientboundStatusPingPacket.DECODER, ClientboundStatusPingPacket.ENCODER
)
.build());
LOGIN = new VersionSpecificProtocolRegistry()
.register(ProtocolVersion.MINECRAFT_1_7_2, ProtocolVersion.MINECRAFT_1_7_6,
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() {
throw new AssertionError();
}
}

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();