diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 08a2b3736..31cc2ea7c 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -27,6 +27,10 @@ + + + + + + diff --git a/gradle/checkstyle.gradle b/gradle/checkstyle.gradle index 3a193db55..9a5e44243 100644 --- a/gradle/checkstyle.gradle +++ b/gradle/checkstyle.gradle @@ -1,8 +1,11 @@ checkstyle { + def configDirectory = new File(project.rootDir, ["config", "checkstyle"].join(File.separator)) + toolVersion '8.14' - configFile new File(project.rootDir, ['config', 'checkstyle', 'checkstyle.xml'].join(File.separator)) + configFile new File(configDirectory, "checkstyle.xml") + configProperties = [configDirectory: configDirectory.getAbsolutePath()] // The build should immediately fail if we have errors. maxErrors = 0 maxWarnings = 0 -} \ No newline at end of file +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 4053640ba..e4af1869f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -27,11 +27,11 @@ import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.console.VelocityConsole; import com.velocitypowered.proxy.network.ConnectionManager; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.serialization.FaviconSerializer; +import com.velocitypowered.proxy.network.serialization.GameProfileSerializer; import com.velocitypowered.proxy.plugin.VelocityEventManager; import com.velocitypowered.proxy.plugin.VelocityPluginManager; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.util.FaviconSerializer; -import com.velocitypowered.proxy.protocol.util.GameProfileSerializer; import com.velocitypowered.proxy.scheduler.VelocityScheduler; import com.velocitypowered.proxy.server.ServerMap; import com.velocitypowered.proxy.util.AddressUtil; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index 4363b6cc9..0935631a5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -19,15 +19,15 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; import com.velocitypowered.proxy.connection.client.LoginSessionHandler; import com.velocitypowered.proxy.connection.client.StatusSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; -import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; +import com.velocitypowered.proxy.network.StateRegistry; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket; +import com.velocitypowered.proxy.network.pipeline.MinecraftCipherDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftCipherEncoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftCompressDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftCompressEncoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftEncoder; import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; @@ -369,7 +369,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { /** * Sets the compression threshold on the connection. You are responsible for sending - * {@link SetCompressionPacket} beforehand. + * {@link ClientboundSetCompressionPacket} beforehand. * @param threshold the compression threshold to use */ public void setCompressionThreshold(int threshold) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java index a576f8b15..d7ced717f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java @@ -1,39 +1,10 @@ package com.velocitypowered.proxy.connection; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket; -import com.velocitypowered.proxy.protocol.packet.BossBarPacket; -import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; -import com.velocitypowered.proxy.protocol.packet.ClientboundChatPacket; -import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket; -import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket; -import com.velocitypowered.proxy.protocol.packet.HandshakePacket; -import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket; -import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; -import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; -import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket; -import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket; -import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; -import com.velocitypowered.proxy.protocol.packet.ResourcePackRequestPacket; -import com.velocitypowered.proxy.protocol.packet.ResourcePackResponsePacket; -import com.velocitypowered.proxy.protocol.packet.RespawnPacket; -import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket; -import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; -import com.velocitypowered.proxy.protocol.packet.ServerboundChatPacket; -import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; -import com.velocitypowered.proxy.protocol.packet.StatusPingPacket; -import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket; -import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket; -import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; -import com.velocitypowered.proxy.protocol.packet.TitlePacket; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyHandshakePacket; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; -public interface MinecraftSessionHandler { +public interface MinecraftSessionHandler extends PacketHandler { default boolean beforeHandle() { return false; @@ -65,126 +36,4 @@ public interface MinecraftSessionHandler { default void readCompleted() { } - - default boolean handle(AvailableCommandsPacket commands) { - return false; - } - - default boolean handle(BossBarPacket packet) { - return false; - } - - default boolean handle(ClientboundChatPacket packet) { - return false; - } - - default boolean handle(ServerboundChatPacket packet) { - return false; - } - - default boolean handle(ClientSettingsPacket packet) { - return false; - } - - default boolean handle(DisconnectPacket packet) { - return false; - } - - default boolean handle(EncryptionRequestPacket packet) { - return false; - } - - default boolean handle(EncryptionResponsePacket packet) { - return false; - } - - default boolean handle(HandshakePacket packet) { - return false; - } - - default boolean handle(HeaderAndFooterPacket packet) { - return false; - } - - default boolean handle(JoinGamePacket packet) { - return false; - } - - default boolean handle(KeepAlivePacket packet) { - return false; - } - - default boolean handle(LoginPluginMessagePacket packet) { - return false; - } - - default boolean handle(LoginPluginResponsePacket packet) { - return false; - } - - default boolean handle(PluginMessagePacket packet) { - return false; - } - - default boolean handle(RespawnPacket packet) { - return false; - } - - default boolean handle(ServerLoginPacket packet) { - return false; - } - - default boolean handle(ServerLoginSuccessPacket packet) { - return false; - } - - default boolean handle(SetCompressionPacket packet) { - return false; - } - - default boolean handle(StatusPingPacket packet) { - return false; - } - - default boolean handle(StatusRequestPacket packet) { - return false; - } - - default boolean handle(StatusResponsePacket packet) { - return false; - } - - default boolean handle(TabCompleteRequestPacket packet) { - return false; - } - - default boolean handle(TabCompleteResponsePacket packet) { - return false; - } - - default boolean handle(TitlePacket packet) { - return false; - } - - default boolean handle(PlayerListItemPacket packet) { - return false; - } - - default boolean handle(ResourcePackRequestPacket packet) { - return false; - } - - default boolean handle(ResourcePackResponsePacket packet) { - return false; - } - - // Legacy - - default boolean handle(LegacyHandshakePacket packet) { - return false; - } - - default boolean handle(LegacyPingPacket packet) { - return false; - } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhase.java index 216190fec..a051dcb1b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhase.java @@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.backend; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; /** * Provides connection phase specific actions. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhases.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhases.java index d185c0f48..b8a630020 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhases.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhases.java @@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.backend; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; /** * Contains Vanilla {@link BackendConnectionPhase}s. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index 81cec86e1..951e4e6b0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -16,15 +16,15 @@ import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler; import com.velocitypowered.proxy.connection.util.ConnectionMessages; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket; -import com.velocitypowered.proxy.protocol.packet.BossBarPacket; -import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; -import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; -import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; +import com.velocitypowered.proxy.network.PluginMessageUtil; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundAvailableCommandsPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; @@ -79,23 +79,23 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(KeepAlivePacket packet) { + public boolean handle(ClientboundKeepAlivePacket packet) { serverConn.setLastPingId(packet.getRandomId()); return false; // forwards on } @Override - public boolean handle(DisconnectPacket packet) { + public boolean handle(ClientboundDisconnectPacket packet) { serverConn.disconnect(); serverConn.getPlayer().handleConnectionException(serverConn.getServer(), packet, true); return true; } @Override - public boolean handle(BossBarPacket packet) { - if (packet.getAction() == BossBarPacket.ADD) { + public boolean handle(ClientboundBossBarPacket packet) { + if (packet.getAction() == ClientboundBossBarPacket.ADD) { playerSessionHandler.getServerBossBars().add(packet.getUuid()); - } else if (packet.getAction() == BossBarPacket.REMOVE) { + } else if (packet.getAction() == ClientboundBossBarPacket.REMOVE) { playerSessionHandler.getServerBossBars().remove(packet.getUuid()); } return false; // forward @@ -158,19 +158,19 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(TabCompleteResponsePacket packet) { + public boolean handle(ClientboundTabCompleteResponsePacket packet) { playerSessionHandler.handleTabCompleteResponse(packet); return true; } @Override - public boolean handle(PlayerListItemPacket packet) { + public boolean handle(ClientboundPlayerListItemPacket packet) { serverConn.getPlayer().getTabList().processBackendPacket(packet); return false; //Forward packet to player } @Override - public boolean handle(AvailableCommandsPacket commands) { + public boolean handle(ClientboundAvailableCommandsPacket commands) { RootCommandNode rootNode = commands.getRootNode(); if (server.getConfiguration().isAnnounceProxyCommands()) { // Inject commands from the proxy. @@ -277,7 +277,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { if (!serverConn.isGracefulDisconnect() && !exceptionTriggered) { if (server.getConfiguration().isFailoverOnUnexpectedServerDisconnect()) { serverConn.getPlayer().handleConnectionException(serverConn.getServer(), - DisconnectPacket.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR, + ClientboundDisconnectPacket.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR, ProtocolVersion.MINECRAFT_1_16), true); } else { serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java index 855943a76..b74083ddd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java @@ -9,9 +9,9 @@ import com.velocitypowered.api.util.UuidUtils; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; -import com.velocitypowered.proxy.protocol.util.ByteBufDataInput; -import com.velocitypowered.proxy.protocol.util.ByteBufDataOutput; +import com.velocitypowered.proxy.network.buffer.ByteBufDataInput; +import com.velocitypowered.proxy.network.buffer.ByteBufDataOutput; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java index 7f0032922..a4ac585f3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java @@ -9,14 +9,14 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.VelocityConstants; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket; -import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket; -import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket; -import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; -import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.StateRegistry; +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.ServerboundLoginPluginResponsePacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import com.velocitypowered.proxy.util.except.QuietRuntimeException; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -49,12 +49,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(EncryptionRequestPacket packet) { + public boolean handle(ClientboundEncryptionRequestPacket packet) { throw new IllegalStateException("Backend server is online-mode!"); } @Override - public boolean handle(LoginPluginMessagePacket packet) { + public boolean handle(ClientboundLoginPluginMessagePacket packet) { MinecraftConnection mc = serverConn.ensureConnected(); VelocityConfiguration configuration = server.getConfiguration(); if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && packet @@ -62,32 +62,33 @@ public class LoginSessionHandler implements MinecraftSessionHandler { ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(), cleanRemoteAddress(serverConn.getPlayer().getRemoteAddress()), serverConn.getPlayer().getGameProfile()); - LoginPluginResponsePacket response = new LoginPluginResponsePacket(packet.getId(), true, - forwardingData); + ServerboundLoginPluginResponsePacket response = new ServerboundLoginPluginResponsePacket( + packet.getId(), true, forwardingData); mc.write(response); informationForwarded = true; } else { // Don't understand - mc.write(new LoginPluginResponsePacket(packet.getId(), false, Unpooled.EMPTY_BUFFER)); + mc.write(new ServerboundLoginPluginResponsePacket(packet.getId(), false, + Unpooled.EMPTY_BUFFER)); } return true; } @Override - public boolean handle(DisconnectPacket packet) { + public boolean handle(ClientboundDisconnectPacket packet) { resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer())); serverConn.disconnect(); return true; } @Override - public boolean handle(SetCompressionPacket packet) { + public boolean handle(ClientboundSetCompressionPacket packet) { serverConn.ensureConnected().setCompressionThreshold(packet.getThreshold()); return true; } @Override - public boolean handle(ServerLoginSuccessPacket packet) { + public boolean handle(ClientboundServerLoginSuccessPacket packet) { if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && !informationForwarded) { resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java index 301fd19f2..c358ebdbe 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java @@ -14,11 +14,11 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.util.ConnectionMessages; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; -import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; -import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; -import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; +import com.velocitypowered.proxy.network.PluginMessageUtil; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import java.io.IOException; import java.util.concurrent.CompletableFuture; import org.apache.logging.log4j.LogManager; @@ -60,13 +60,13 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(KeepAlivePacket packet) { + public boolean handle(ClientboundKeepAlivePacket packet) { serverConn.ensureConnected().write(packet); return true; } @Override - public boolean handle(JoinGamePacket packet) { + public boolean handle(ClientboundJoinGamePacket packet) { MinecraftConnection smc = serverConn.ensureConnected(); VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer(); @@ -132,7 +132,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(DisconnectPacket packet) { + public boolean handle(ClientboundDisconnectPacket packet) { final MinecraftConnection connection = serverConn.ensureConnected(); serverConn.disconnect(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 5ae3eb769..2f3e624c7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -20,11 +20,11 @@ import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.registry.DimensionRegistry; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; -import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.HandshakePacket; -import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; -import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket; +import com.velocitypowered.proxy.network.StateRegistry; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -143,7 +143,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, // Initiate the handshake. ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion(); - HandshakePacket handshake = new HandshakePacket(); + ServerboundHandshakePacket handshake = new ServerboundHandshakePacket(); handshake.setNextStatus(StateRegistry.LOGIN_ID); handshake.setProtocolVersion(protocolVersion); if (forwardingMode == PlayerInfoForwarding.LEGACY) { @@ -165,7 +165,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, mc.setProtocolVersion(protocolVersion); mc.setState(StateRegistry.LOGIN); - mc.delayedWrite(new ServerLoginPacket(proxyPlayer.getUsername())); + mc.delayedWrite(new ServerboundServerLoginPacket(proxyPlayer.getUsername())); mc.flush(); } @@ -308,7 +308,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, } /** - * Gets whether the {@link JoinGamePacket} + * Gets whether the {@link ClientboundJoinGamePacket} * packet has been sent by this server. * * @return Whether the join has been completed. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConnectionPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConnectionPhase.java index 75ccabf8f..6f1052187 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConnectionPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConnectionPhase.java @@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.client; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeClientPhase; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; /** * Provides connection phase specific actions. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 307a81870..015be6785 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -3,7 +3,7 @@ package com.velocitypowered.proxy.connection.client; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_16; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_8; -import static com.velocitypowered.proxy.protocol.util.PluginMessageUtil.constructChannelsPacket; +import static com.velocitypowered.proxy.network.PluginMessageUtil.constructChannelsPacket; import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult; import com.velocitypowered.api.event.connection.PluginMessageEvent; @@ -19,22 +19,21 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases; import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.BossBarPacket; -import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; -import com.velocitypowered.proxy.protocol.packet.ClientboundChatPacket; -import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; -import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; -import com.velocitypowered.proxy.protocol.packet.ResourcePackResponsePacket; -import com.velocitypowered.proxy.protocol.packet.RespawnPacket; -import com.velocitypowered.proxy.protocol.packet.ServerboundChatPacket; -import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket.Offer; -import com.velocitypowered.proxy.protocol.packet.TitlePacket; -import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; +import com.velocitypowered.proxy.network.PluginMessageUtil; +import com.velocitypowered.proxy.network.StateRegistry; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundRespawnPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket.Offer; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTitlePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlivePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; @@ -67,7 +66,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { private final List serverBossBars = new ArrayList<>(); private final Queue loginPluginMessages = new ArrayDeque<>(); private final VelocityServer server; - private @Nullable TabCompleteRequestPacket outstandingTabComplete; + private @Nullable ServerboundTabCompleteRequestPacket outstandingTabComplete; /** * Constructs a client play session handler. @@ -98,7 +97,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(KeepAlivePacket packet) { + public boolean handle(ServerboundKeepAlivePacket packet) { VelocityServerConnection serverConnection = player.getConnectedServer(); if (serverConnection != null && packet.getRandomId() == serverConnection.getLastPingId()) { MinecraftConnection smc = serverConnection.getConnection(); @@ -112,13 +111,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(ClientSettingsPacket packet) { + public boolean handle(ServerboundClientSettingsPacket packet) { player.setPlayerSettings(packet); return false; // will forward onto the server } @Override - public boolean handle(ClientboundChatPacket packet) { + public boolean handle(ServerboundChatPacket packet) { VelocityServerConnection serverConnection = player.getConnectedServer(); if (serverConnection == null) { return true; @@ -170,7 +169,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(TabCompleteRequestPacket packet) { + public boolean handle(ServerboundTabCompleteRequestPacket packet) { boolean isCommand = !packet.isAssumeCommand() && packet.getCommand().startsWith("/"); if (isCommand) { @@ -250,7 +249,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(ResourcePackResponsePacket packet) { + public boolean handle(ServerboundResourcePackResponsePacket packet) { server.getEventManager().fireAndForget(new PlayerResourcePackStatusEvent(player, packet.getStatus())); return false; @@ -321,7 +320,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { * @param joinGame the join game packet * @param destination the new server we are connecting to */ - public void handleBackendJoinGame(JoinGamePacket joinGame, VelocityServerConnection destination) { + public void handleBackendJoinGame(ClientboundJoinGamePacket joinGame, + VelocityServerConnection destination) { final MinecraftConnection serverMc = destination.ensureConnected(); if (!spawned) { @@ -346,9 +346,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // Remove previous boss bars. These don't get cleared when sending JoinGame, thus the need to // track them. for (UUID serverBossBar : serverBossBars) { - BossBarPacket deletePacket = new BossBarPacket(); + ClientboundBossBarPacket deletePacket = new ClientboundBossBarPacket(); deletePacket.setUuid(serverBossBar); - deletePacket.setAction(BossBarPacket.REMOVE); + deletePacket.setAction(ClientboundBossBarPacket.REMOVE); player.getConnection().delayedWrite(deletePacket); } serverBossBars.clear(); @@ -368,7 +368,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // Clear any title from the previous server. if (player.getProtocolVersion().gte(MINECRAFT_1_8)) { player.getConnection() - .delayedWrite(TitlePacket.reset(player.getProtocolVersion())); + .delayedWrite(ClientboundTitlePacket.reset(player.getProtocolVersion())); } // Flush everything @@ -377,7 +377,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { destination.completeJoin(); } - private void doFastClientServerSwitch(JoinGamePacket joinGame) { + private void doFastClientServerSwitch(ClientboundJoinGamePacket joinGame) { // In order to handle switching to another server, you will need to send two packets: // // - The join game packet from the backend server, with a different dimension @@ -396,13 +396,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { player.getConnection().delayedWrite(joinGame); player.getConnection().delayedWrite( - new RespawnPacket(sentOldDim, joinGame.getPartialHashedSeed(), + new ClientboundRespawnPacket(sentOldDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), joinGame.getCurrentDimensionData())); } - private void doSafeClientServerSwitch(JoinGamePacket joinGame) { + private void doSafeClientServerSwitch(ClientboundJoinGamePacket joinGame) { // Some clients do not behave well with the "fast" respawn sequence. In this case we will use // a "safe" respawn sequence that involves sending three packets to the client. They have the // same effect but tend to work better with buggier clients (Forge 1.8 in particular). @@ -413,14 +413,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // Send a respawn packet in a different dimension. int tempDim = joinGame.getDimension() == 0 ? -1 : 0; player.getConnection().delayedWrite( - new RespawnPacket(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), - joinGame.getGamemode(), joinGame.getLevelType(), + new ClientboundRespawnPacket(tempDim, joinGame.getPartialHashedSeed(), + joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), joinGame.getCurrentDimensionData())); // Now send a respawn packet in the correct dimension. player.getConnection().delayedWrite( - new RespawnPacket(joinGame.getDimension(), joinGame.getPartialHashedSeed(), + new ClientboundRespawnPacket(joinGame.getDimension(), joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), joinGame.getCurrentDimensionData())); @@ -430,7 +430,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { return serverBossBars; } - private boolean handleCommandTabComplete(TabCompleteRequestPacket packet) { + private boolean handleCommandTabComplete(ServerboundTabCompleteRequestPacket packet) { // In 1.13+, we need to do additional work for the richer suggestions available. String command = packet.getCommand().substring(1); int commandEndPosition = command.indexOf(' '); @@ -460,7 +460,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } int startPos = packet.getCommand().lastIndexOf(' ') + 1; if (startPos > 0) { - TabCompleteResponsePacket resp = new TabCompleteResponsePacket(); + ClientboundTabCompleteResponsePacket resp = new ClientboundTabCompleteResponsePacket(); resp.setTransactionId(packet.getTransactionId()); resp.setStart(startPos); resp.setLength(packet.getCommand().length() - startPos); @@ -476,7 +476,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { return true; // Sorry, handler; we're just gonna have to lie to you here. } - private boolean handleRegularTabComplete(TabCompleteRequestPacket packet) { + private boolean handleRegularTabComplete(ServerboundTabCompleteRequestPacket packet) { if (player.getProtocolVersion().lt(MINECRAFT_1_13)) { // Outstanding tab completes are recorded for use with 1.12 clients and below to provide // additional tab completion support. @@ -490,7 +490,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { * * @param response the tab complete response from the backend */ - public void handleTabCompleteResponse(TabCompleteResponsePacket response) { + public void handleTabCompleteResponse(ClientboundTabCompleteResponsePacket response) { if (outstandingTabComplete != null && !outstandingTabComplete.isAssumeCommand()) { if (outstandingTabComplete.getCommand().startsWith("/")) { this.finishCommandTabComplete(outstandingTabComplete, response); @@ -504,8 +504,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } } - private void finishCommandTabComplete(TabCompleteRequestPacket request, - TabCompleteResponsePacket response) { + private void finishCommandTabComplete(ServerboundTabCompleteRequestPacket request, + ClientboundTabCompleteResponsePacket response) { String command = request.getCommand().substring(1); server.getCommandManager().offerSuggestions(player, command) .thenAcceptAsync(offers -> { @@ -534,8 +534,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { }); } - private void finishRegularTabComplete(TabCompleteRequestPacket request, - TabCompleteResponsePacket response) { + private void finishRegularTabComplete(ServerboundTabCompleteRequestPacket request, + ClientboundTabCompleteResponsePacket response) { List offers = new ArrayList<>(); for (Offer offer : response.getOffers()) { offers.add(offer.getText()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java index dfee04f61..9a04da5e1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java @@ -2,20 +2,20 @@ package com.velocitypowered.proxy.connection.client; import com.velocitypowered.api.proxy.player.PlayerSettings; import com.velocitypowered.api.proxy.player.SkinParts; -import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket; import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public class ClientSettingsWrapper implements PlayerSettings { static final PlayerSettings DEFAULT = new ClientSettingsWrapper( - new ClientSettingsPacket("en_US", (byte) 10, 0, true, (short) 127, 1)); + new ServerboundClientSettingsPacket("en_US", (byte) 10, 0, true, (short) 127, 1)); - private final ClientSettingsPacket settings; + private final ServerboundClientSettingsPacket settings; private final SkinParts parts; private @Nullable Locale locale; - ClientSettingsWrapper(ClientSettingsPacket settings) { + ClientSettingsWrapper(ServerboundClientSettingsPacket settings) { this.settings = settings; this.parts = new SkinParts((byte) settings.getSkinParts()); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 49e1a7669..1edf2c7cf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -36,17 +36,17 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants; import com.velocitypowered.proxy.connection.util.ConnectionMessages; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; -import com.velocitypowered.proxy.protocol.packet.ClientboundChatPacket; -import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; -import com.velocitypowered.proxy.protocol.packet.ResourcePackRequestPacket; -import com.velocitypowered.proxy.protocol.packet.ServerboundChatPacket; -import com.velocitypowered.proxy.protocol.packet.TitlePacket; -import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; +import com.velocitypowered.proxy.network.PluginMessageUtil; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.StateRegistry; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTitlePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.tablist.VelocityTabList; import com.velocitypowered.proxy.tablist.VelocityTabListLegacy; @@ -186,7 +186,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings; } - void setPlayerSettings(ClientSettingsPacket settings) { + void setPlayerSettings(ServerboundClientSettingsPacket settings) { ClientSettingsWrapper cs = new ClientSettingsWrapper(settings); this.settings = cs; server.getEventManager().fireAndForget(new PlayerSettingsChangedEvent(this, cs)); @@ -246,8 +246,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { ProtocolVersion playerVersion = getProtocolVersion(); if (playerVersion.gte(ProtocolVersion.MINECRAFT_1_11)) { // Use the title packet instead. - connection.write(new TitlePacket( - TitlePacket.SET_ACTION_BAR, + connection.write(new ClientboundTitlePacket( + ClientboundTitlePacket.SET_ACTION_BAR, ProtocolUtils.getJsonChatSerializer(playerVersion).serialize(message) )); } else { @@ -268,19 +268,19 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this .getProtocolVersion()); - connection.delayedWrite(new TitlePacket( - TitlePacket.SET_TITLE, + connection.delayedWrite(new ClientboundTitlePacket( + ClientboundTitlePacket.SET_TITLE, serializer.serialize(title.title()) )); - connection.delayedWrite(new TitlePacket( - TitlePacket.SET_SUBTITLE, + connection.delayedWrite(new ClientboundTitlePacket( + ClientboundTitlePacket.SET_SUBTITLE, serializer.serialize(title.subtitle()) )); net.kyori.adventure.title.Title.Times times = title.times(); if (times != null) { - connection.delayedWrite(TitlePacket.times(this.getProtocolVersion(), times)); + connection.delayedWrite(ClientboundTitlePacket.times(this.getProtocolVersion(), times)); } connection.flush(); @@ -288,12 +288,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { @Override public void clearTitle() { - connection.write(TitlePacket.hide(this.getProtocolVersion())); + connection.write(ClientboundTitlePacket.hide(this.getProtocolVersion())); } @Override public void resetTitle() { - connection.write(TitlePacket.reset(this.getProtocolVersion())); + connection.write(ClientboundTitlePacket.reset(this.getProtocolVersion())); } @Override @@ -338,7 +338,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { public void disconnect0(Component reason, boolean duringLogin) { logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(reason)); - connection.closeWith(DisconnectPacket.create(reason, this.getProtocolVersion())); + connection.closeWith(ClientboundDisconnectPacket.create(reason, this.getProtocolVersion())); } public @Nullable VelocityServerConnection getConnectedServer() { @@ -397,7 +397,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { * @param disconnect the disconnect packet * @param safe whether or not we can safely reconnect to a new server */ - public void handleConnectionException(RegisteredServer server, DisconnectPacket disconnect, + public void handleConnectionException(RegisteredServer server, ClientboundDisconnectPacket disconnect, boolean safe) { if (!isActive()) { // If the connection is no longer active, it makes no sense to try and recover it. @@ -502,7 +502,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { case SERVER_DISCONNECTED: Component reason = status.getReason() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); - handleConnectionException(res.getServer(), DisconnectPacket.create(reason, + handleConnectionException(res.getServer(), ClientboundDisconnectPacket.create(reason, getProtocolVersion()), ((Impl) status).isSafe()); break; case SUCCESS: @@ -677,10 +677,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { public void sendResourcePack(String url) { Preconditions.checkNotNull(url, "url"); - ResourcePackRequestPacket request = new ResourcePackRequestPacket(); - request.setUrl(url); - request.setHash(""); - connection.write(request); + connection.write(new ClientboundResourcePackRequestPacket(url, "")); } @Override @@ -689,20 +686,17 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { Preconditions.checkNotNull(hash, "hash"); Preconditions.checkArgument(hash.length == 20, "Hash length is not 20"); - ResourcePackRequestPacket request = new ResourcePackRequestPacket(); - request.setUrl(url); - request.setHash(ByteBufUtil.hexDump(hash)); - connection.write(request); + connection.write(new ClientboundResourcePackRequestPacket(url, ByteBufUtil.hexDump(hash))); } /** - * Sends a {@link KeepAlivePacket} packet to the player with a random ID. + * Sends a {@link ClientboundKeepAlivePacket} packet to the player with a random ID. * The response will be ignored by Velocity as it will not match the * ID last sent by the server. */ public void sendKeepAlive() { if (connection.getState() == StateRegistry.PLAY) { - connection.write(new KeepAlivePacket(ThreadLocalRandom.current().nextLong())); + connection.write(new ClientboundKeepAlivePacket(ThreadLocalRandom.current().nextLong())); } } @@ -873,7 +867,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { case SERVER_DISCONNECTED: Component reason = status.getReason() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); - handleConnectionException(toConnect, DisconnectPacket.create(reason, + handleConnectionException(toConnect, ClientboundDisconnectPacket.create(reason, getProtocolVersion()), status.isSafe()); break; default: diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index 08a3b1c4a..a54053b89 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -12,12 +12,12 @@ import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.HandshakePacket; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyDisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyHandshakePacket; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket; +import com.velocitypowered.proxy.network.StateRegistry; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.legacy.LegacyDisconnectPacket; +import com.velocitypowered.proxy.network.packet.legacy.LegacyHandshakePacket; +import com.velocitypowered.proxy.network.packet.legacy.LegacyPingPacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; import io.netty.buffer.ByteBuf; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -58,7 +58,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(HandshakePacket handshake) { + public boolean handle(ServerboundHandshakePacket handshake) { InitialInboundConnection ic = new InitialInboundConnection(connection, cleanVhost(handshake.getServerAddress()), handshake); StateRegistry nextState = getStateForProtocol(handshake.getNextStatus()); @@ -97,7 +97,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } } - private void handleLogin(HandshakePacket handshake, InitialInboundConnection ic) { + private void handleLogin(ServerboundHandshakePacket handshake, InitialInboundConnection ic) { if (!ProtocolVersion.isSupported(handshake.getProtocolVersion())) { ic.disconnectQuietly(Component.translatable("multiplayer.disconnect.outdated_client")); return; @@ -123,7 +123,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { connection.setSessionHandler(new LoginSessionHandler(server, connection, ic)); } - private ConnectionType getHandshakeConnectionType(HandshakePacket handshake) { + private ConnectionType getHandshakeConnectionType(ServerboundHandshakePacket handshake) { // Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13). if (handshake.getServerAddress().endsWith(LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN) && handshake.getProtocolVersion().lt(ProtocolVersion.MINECRAFT_1_13)) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java index e634a3aaa..275b31c52 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java @@ -3,8 +3,8 @@ package com.velocitypowered.proxy.connection.client; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; -import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; +import com.velocitypowered.proxy.network.PluginMessageUtil; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; public class InitialConnectSessionHandler implements MinecraftSessionHandler { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index 38bcf4cfe..9bbda289f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -4,8 +4,8 @@ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; -import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.HandshakePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import java.net.InetSocketAddress; import java.util.Optional; import net.kyori.adventure.text.Component; @@ -20,10 +20,10 @@ public final class InitialInboundConnection implements InboundConnection, private final MinecraftConnection connection; private final String cleanedAddress; - private final HandshakePacket handshake; + private final ServerboundHandshakePacket handshake; InitialInboundConnection(MinecraftConnection connection, String cleanedAddress, - HandshakePacket handshake) { + ServerboundHandshakePacket handshake) { this.connection = connection; this.cleanedAddress = cleanedAddress; this.handshake = handshake; @@ -61,7 +61,7 @@ public final class InitialInboundConnection implements InboundConnection, public void disconnect(Component reason) { logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(reason)); - connection.closeWith(DisconnectPacket.create(reason, getProtocolVersion())); + connection.closeWith(ClientboundDisconnectPacket.create(reason, getProtocolVersion())); } /** @@ -69,6 +69,6 @@ public final class InitialInboundConnection implements InboundConnection, * @param reason the reason for disconnecting */ public void disconnectQuietly(Component reason) { - connection.closeWith(DisconnectPacket.create(reason, getProtocolVersion())); + connection.closeWith(ClientboundDisconnectPacket.create(reason, getProtocolVersion())); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index c9e298582..545a132d8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -25,13 +25,13 @@ import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket; -import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket; -import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket; -import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; -import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; +import com.velocitypowered.proxy.network.StateRegistry; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket; +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.ServerboundServerLoginPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import io.netty.buffer.ByteBuf; import java.net.InetSocketAddress; import java.security.GeneralSecurityException; @@ -58,7 +58,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { private final VelocityServer server; private final MinecraftConnection mcConnection; private final InitialInboundConnection inbound; - private @MonotonicNonNull ServerLoginPacket login; + private @MonotonicNonNull ServerboundServerLoginPacket login; private byte[] verify = EMPTY_BYTE_ARRAY; private @MonotonicNonNull ConnectedPlayer connectedPlayer; @@ -70,15 +70,15 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(ServerLoginPacket packet) { + public boolean handle(ServerboundServerLoginPacket packet) { this.login = packet; beginPreLogin(); return true; } @Override - public boolean handle(EncryptionResponsePacket packet) { - ServerLoginPacket login = this.login; + public boolean handle(ServerboundEncryptionResponsePacket packet) { + ServerboundServerLoginPacket login = this.login; if (login == null) { throw new IllegalStateException("No ServerLogin packet received yet."); } @@ -153,7 +153,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } private void beginPreLogin() { - ServerLoginPacket login = this.login; + ServerboundServerLoginPacket login = this.login; if (login == null) { throw new IllegalStateException("No ServerLogin packet received yet."); } @@ -169,7 +169,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { Optional disconnectReason = result.getReason(); if (disconnectReason.isPresent()) { // The component is guaranteed to be provided if the connection was denied. - mcConnection.closeWith(DisconnectPacket.create(disconnectReason.get(), + mcConnection.closeWith(ClientboundDisconnectPacket.create(disconnectReason.get(), inbound.getProtocolVersion())); return; } @@ -177,7 +177,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { if (!result.isForceOfflineMode() && (server.getConfiguration().isOnlineMode() || result .isOnlineModeAllowed())) { // Request encryption. - EncryptionRequestPacket request = generateEncryptionRequest(); + ClientboundEncryptionRequestPacket request = generateEncryptionRequest(); this.verify = Arrays.copyOf(request.getVerifyToken(), 4); mcConnection.write(request); } else { @@ -190,11 +190,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler { }); } - private EncryptionRequestPacket generateEncryptionRequest() { + private ClientboundEncryptionRequestPacket generateEncryptionRequest() { byte[] verify = new byte[4]; ThreadLocalRandom.current().nextBytes(verify); - EncryptionRequestPacket request = new EncryptionRequestPacket(); + ClientboundEncryptionRequestPacket request = new ClientboundEncryptionRequestPacket(); request.setPublicKey(server.getServerKeyPair().getPublic().getEncoded()); request.setVerifyToken(verify); return request; @@ -243,7 +243,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { private void completeLoginProtocolPhaseAndInitialize(ConnectedPlayer player) { int threshold = server.getConfiguration().getCompressionThreshold(); if (threshold >= 0 && mcConnection.getProtocolVersion().gte(MINECRAFT_1_8)) { - mcConnection.write(new SetCompressionPacket(threshold)); + mcConnection.write(new ClientboundSetCompressionPacket(threshold)); mcConnection.setCompressionThreshold(threshold); } VelocityConfiguration configuration = server.getConfiguration(); @@ -251,10 +251,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) { playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername()); } - ServerLoginSuccessPacket success = new ServerLoginSuccessPacket(); - success.setUsername(player.getUsername()); - success.setUuid(playerUniqueId); - mcConnection.write(success); + mcConnection.write(new ClientboundServerLoginSuccessPacket(playerUniqueId, player.getUsername())); mcConnection.setAssociation(player); mcConnection.setState(StateRegistry.PLAY); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index a526c5dd4..1b26a9b0f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -13,11 +13,11 @@ import com.velocitypowered.proxy.config.PingPassthroughMode; import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.packet.StatusPingPacket; -import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket; -import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyDisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundStatusResponsePacket; +import com.velocitypowered.proxy.network.packet.legacy.LegacyDisconnectPacket; +import com.velocitypowered.proxy.network.packet.legacy.LegacyPingPacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.util.except.QuietRuntimeException; import io.netty.buffer.ByteBuf; @@ -176,13 +176,13 @@ public class StatusSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(StatusPingPacket packet) { + public boolean handle(ServerboundStatusPingPacket packet) { connection.closeWith(packet); return true; } @Override - public boolean handle(StatusRequestPacket packet) { + public boolean handle(ServerboundStatusRequestPacket packet) { if (this.pingReceived) { throw EXPECTED_AWAITING_REQUEST; } @@ -195,7 +195,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { StringBuilder json = new StringBuilder(); VelocityServer.getPingGsonInstance(connection.getProtocolVersion()) .toJson(event.getPing(), json); - connection.write(new StatusResponsePacket(json)); + connection.write(new ClientboundStatusResponsePacket(json)); }, connection.eventLoop()) .exceptionally((ex) -> { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java index 452aac6f0..549b7fcaf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java @@ -6,7 +6,7 @@ import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase; import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import javax.annotation.Nullable; /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java index 3d756b853..aa831f856 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java @@ -7,7 +7,7 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.client.ClientConnectionPhase; import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import java.util.List; import javax.annotation.Nullable; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java index ff22d6798..8cfb67dc4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java @@ -7,8 +7,8 @@ import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConst import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.util.ModInfo; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.List; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java index 35bf09488..bc529f2b9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java @@ -3,7 +3,7 @@ package com.velocitypowered.proxy.connection.util; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder.Status; import com.velocitypowered.api.proxy.server.RegisteredServer; -import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import java.util.Optional; import javax.annotation.Nullable; import net.kyori.adventure.text.Component; @@ -41,12 +41,12 @@ public class ConnectionRequestResults { return new Impl(Status.SERVER_DISCONNECTED, component, server, true); } - public static Impl forDisconnect(DisconnectPacket disconnect, RegisteredServer server) { + public static Impl forDisconnect(ClientboundDisconnectPacket disconnect, RegisteredServer server) { Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); return forDisconnect(deserialized, server); } - public static Impl forUnsafeDisconnect(DisconnectPacket disconnect, RegisteredServer server) { + public static Impl forUnsafeDisconnect(ClientboundDisconnectPacket disconnect, RegisteredServer server) { Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); return new Impl(Status.SERVER_DISCONNECTED, deserialized, server, false); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java index 9db1dd4c7..607e26fee 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java @@ -8,12 +8,12 @@ import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER; import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT; import com.velocitypowered.proxy.VelocityServer; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.netty.AutoReadHolderHandler; -import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.pipeline.AutoReadHolderHandler; +import com.velocitypowered.proxy.network.pipeline.MinecraftDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftEncoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftVarintFrameDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftVarintLengthEncoder; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.handler.timeout.ReadTimeoutHandler; @@ -37,9 +37,9 @@ public class BackendChannelInitializer extends ChannelInitializer { .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, - new MinecraftDecoder(ProtocolDirection.CLIENTBOUND)) + new MinecraftDecoder(PacketDirection.CLIENTBOUND)) .addLast(FLOW_HANDLER, new AutoReadHolderHandler()) .addLast(MINECRAFT_ENCODER, - new MinecraftEncoder(ProtocolDirection.SERVERBOUND)); + new MinecraftEncoder(PacketDirection.SERVERBOUND)); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializerHolder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializerHolder.java deleted file mode 100644 index 8847ae099..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializerHolder.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.velocitypowered.proxy.network; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelInitializer; - -final class BackendChannelInitializerHolder extends ChannelInitializerHolder { - - BackendChannelInitializerHolder(final ChannelInitializer initializer) { - super("backend channel", initializer); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ChannelInitializerHolder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ChannelInitializerHolder.java index efbb433d7..91c447264 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ChannelInitializerHolder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ChannelInitializerHolder.java @@ -6,8 +6,7 @@ import java.util.function.Supplier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public abstract class ChannelInitializerHolder - implements Supplier> { +public class ChannelInitializerHolder implements Supplier> { private static final Logger LOGGER = LogManager.getLogger(ChannelInitializerHolder.class); private final String name; private ChannelInitializer initializer; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index 3061557bf..22455b9f6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -6,8 +6,8 @@ import static org.asynchttpclient.Dsl.config; import com.google.common.base.Preconditions; import com.velocitypowered.natives.util.Natives; import com.velocitypowered.proxy.VelocityServer; -import com.velocitypowered.proxy.network.netty.SeparatePoolInetNameResolver; -import com.velocitypowered.proxy.protocol.netty.GS4QueryHandler; +import com.velocitypowered.proxy.network.pipeline.GS4QueryHandler; +import com.velocitypowered.proxy.network.resolver.SeparatePoolInetNameResolver; import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; @@ -60,9 +60,9 @@ public final class ConnectionManager { this.transportType = TransportType.bestType(); this.bossGroup = this.transportType.createEventLoopGroup(TransportType.Type.BOSS); this.workerGroup = this.transportType.createEventLoopGroup(TransportType.Type.WORKER); - this.serverChannelInitializer = new ServerChannelInitializerHolder( + this.serverChannelInitializer = new ChannelInitializerHolder<>("server channel", new ServerChannelInitializer(this.server)); - this.backendChannelInitializer = new BackendChannelInitializerHolder( + this.backendChannelInitializer = new ChannelInitializerHolder<>("backend channel", new BackendChannelInitializer(this.server)); this.resolver = new SeparatePoolInetNameResolver(GlobalEventExecutor.INSTANCE); this.httpClient = asyncHttpClient(config() diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/NettyPreconditions.java b/proxy/src/main/java/com/velocitypowered/proxy/network/NettyPreconditions.java similarity index 96% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/util/NettyPreconditions.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/NettyPreconditions.java index cd59316e4..351b268cb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/NettyPreconditions.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/NettyPreconditions.java @@ -1,7 +1,7 @@ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network; import com.google.common.base.Strings; -import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftDecoder; import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.handler.codec.CorruptedFrameException; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java similarity index 97% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java index 6c75538da..4f528fdc7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @@ -6,8 +6,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.util.ProxyVersion; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.nio.charset.StandardCharsets; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ProtocolUtils.java similarity index 98% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/ProtocolUtils.java index 8c4cabc8f..e138c2b59 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ProtocolUtils.java @@ -1,12 +1,12 @@ -package com.velocitypowered.proxy.protocol; +package com.velocitypowered.proxy.network; import static com.google.common.base.Preconditions.checkArgument; -import static com.velocitypowered.proxy.protocol.util.NettyPreconditions.checkFrame; +import static com.velocitypowered.proxy.network.NettyPreconditions.checkFrame; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.util.GameProfile; -import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; -import com.velocitypowered.proxy.protocol.util.VelocityLegacyHoverEventSerializer; +import com.velocitypowered.proxy.network.pipeline.MinecraftDecoder; +import com.velocitypowered.proxy.network.serialization.VelocityLegacyHoverEventSerializer; import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java index ce7d3e3fc..06c1d11e0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java @@ -11,13 +11,13 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.netty.LegacyPingDecoder; -import com.velocitypowered.proxy.protocol.netty.LegacyPingEncoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.pipeline.LegacyPingDecoder; +import com.velocitypowered.proxy.network.pipeline.LegacyPingEncoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftEncoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftVarintFrameDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftVarintLengthEncoder; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.handler.codec.haproxy.HAProxyMessageDecoder; @@ -43,8 +43,8 @@ public class ServerChannelInitializer extends ChannelInitializer { .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) - .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolDirection.SERVERBOUND)) - .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolDirection.CLIENTBOUND)); + .addLast(MINECRAFT_DECODER, new MinecraftDecoder(PacketDirection.SERVERBOUND)) + .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(PacketDirection.CLIENTBOUND)); final MinecraftConnection connection = new MinecraftConnection(ch, this.server); connection.setSessionHandler(new HandshakeSessionHandler(connection, this.server)); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializerHolder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializerHolder.java deleted file mode 100644 index a991ab0f8..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializerHolder.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.velocitypowered.proxy.network; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelInitializer; - -final class ServerChannelInitializerHolder extends ChannelInitializerHolder { - - ServerChannelInitializerHolder(final ChannelInitializer initializer) { - super("server channel", initializer); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/network/StateRegistry.java similarity index 58% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/StateRegistry.java index eea99e08b..48d74d627 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/StateRegistry.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol; +package com.velocitypowered.proxy.network; import static com.google.common.collect.Iterables.getLast; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12; @@ -16,34 +16,38 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION; import static com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket; -import com.velocitypowered.proxy.protocol.packet.BossBarPacket; -import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; -import com.velocitypowered.proxy.protocol.packet.ClientboundChatPacket; -import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; -import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket; -import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket; -import com.velocitypowered.proxy.protocol.packet.HandshakePacket; -import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket; -import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; -import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; -import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket; -import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket; -import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; -import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; -import com.velocitypowered.proxy.protocol.packet.ResourcePackRequestPacket; -import com.velocitypowered.proxy.protocol.packet.ResourcePackResponsePacket; -import com.velocitypowered.proxy.protocol.packet.RespawnPacket; -import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket; -import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; -import com.velocitypowered.proxy.protocol.packet.ServerboundChatPacket; -import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; -import com.velocitypowered.proxy.protocol.packet.StatusPingPacket; -import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket; -import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket; -import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; -import com.velocitypowered.proxy.protocol.packet.TitlePacket; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundAvailableCommandsPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundHeaderAndFooterPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket; +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.ClientboundResourcePackRequestPacket; +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.ClientboundTitlePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket; +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.ServerboundLoginPluginResponsePacket; +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.clientbound.ClientboundDisconnectPacket; +import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import io.netty.buffer.ByteBuf; import io.netty.util.collection.IntObjectHashMap; import io.netty.util.collection.IntObjectMap; @@ -61,123 +65,182 @@ public enum StateRegistry { HANDSHAKE(true) { { - serverbound.register(HandshakePacket.class, HandshakePacket.DECODER, - map(0x00, MINECRAFT_1_7_2, false)); + serverbound.register( + ServerboundHandshakePacket.class, + ServerboundHandshakePacket.DECODER, + map(0x00, MINECRAFT_1_7_2, false) + ); } }, STATUS(true) { { - serverbound.register(StatusRequestPacket.class, StatusRequestPacket.DECODER, - map(0x00, MINECRAFT_1_7_2, false)); - serverbound.register(StatusPingPacket.class, StatusPingPacket.DECODER, - map(0x01, MINECRAFT_1_7_2, false)); + serverbound.register( + ServerboundStatusRequestPacket.class, + ServerboundStatusRequestPacket.DECODER, + map(0x00, MINECRAFT_1_7_2, false) + ); + serverbound.register( + ServerboundStatusPingPacket.class, + ServerboundStatusPingPacket.DECODER, + map(0x01, MINECRAFT_1_7_2, false) + ); - clientbound.register(StatusResponsePacket.class, StatusResponsePacket.DECODER, - map(0x00, MINECRAFT_1_7_2, false)); - clientbound.register(StatusPingPacket.class, StatusPingPacket.DECODER, - map(0x01, MINECRAFT_1_7_2, false)); + clientbound.register( + ClientboundStatusResponsePacket.class, + ClientboundStatusResponsePacket.DECODER, + map(0x00, MINECRAFT_1_7_2, false) + ); + clientbound.register( + ClientboundStatusPingPacket.class, + ClientboundStatusPingPacket.DECODER, + map(0x01, MINECRAFT_1_7_2, false) + ); } }, PLAY(false) { { - serverbound.register(TabCompleteRequestPacket.class, TabCompleteRequestPacket.DECODER, + serverbound.register( + ServerboundTabCompleteRequestPacket.class, + ServerboundTabCompleteRequestPacket.DECODER, map(0x14, MINECRAFT_1_7_2, false), map(0x01, MINECRAFT_1_9, false), map(0x02, MINECRAFT_1_12, false), map(0x01, MINECRAFT_1_12_1, false), map(0x05, MINECRAFT_1_13, false), - map(0x06, MINECRAFT_1_14, false)); - serverbound.register(ServerboundChatPacket.class, ServerboundChatPacket.DECODER, + map(0x06, MINECRAFT_1_14, false) + ); + serverbound.register( + ServerboundChatPacket.class, + ServerboundChatPacket.DECODER, map(0x01, MINECRAFT_1_7_2, false), map(0x02, MINECRAFT_1_9, false), map(0x03, MINECRAFT_1_12, false), map(0x02, MINECRAFT_1_12_1, false), - map(0x03, MINECRAFT_1_14, false)); - serverbound.register(ClientSettingsPacket.class, ClientSettingsPacket.DECODER, + map(0x03, MINECRAFT_1_14, false) + ); + serverbound.register( + ServerboundClientSettingsPacket.class, + ServerboundClientSettingsPacket.DECODER, map(0x15, MINECRAFT_1_7_2, false), map(0x04, MINECRAFT_1_9, false), map(0x05, MINECRAFT_1_12, false), map(0x04, MINECRAFT_1_12_1, false), - map(0x05, MINECRAFT_1_14, false)); - serverbound.register(PluginMessagePacket.class, PluginMessagePacket.DECODER, + map(0x05, MINECRAFT_1_14, false) + ); + serverbound.register( + PluginMessagePacket.class, + PluginMessagePacket.DECODER, map(0x17, MINECRAFT_1_7_2, false), map(0x09, MINECRAFT_1_9, false), map(0x0A, MINECRAFT_1_12, false), map(0x09, MINECRAFT_1_12_1, false), map(0x0A, MINECRAFT_1_13, false), - map(0x0B, MINECRAFT_1_14, false)); - serverbound.register(KeepAlivePacket.class, KeepAlivePacket.DECODER, + map(0x0B, MINECRAFT_1_14, false) + ); + serverbound.register( + ServerboundKeepAlivePacket.class, + ServerboundKeepAlivePacket.DECODER, map(0x00, MINECRAFT_1_7_2, false), map(0x0B, MINECRAFT_1_9, false), map(0x0C, MINECRAFT_1_12, false), map(0x0B, MINECRAFT_1_12_1, false), map(0x0E, MINECRAFT_1_13, false), map(0x0F, MINECRAFT_1_14, false), - map(0x10, MINECRAFT_1_16, false)); - serverbound.register(ResourcePackResponsePacket.class, ResourcePackResponsePacket.DECODER, + map(0x10, MINECRAFT_1_16, false) + ); + serverbound.register( + ServerboundResourcePackResponsePacket.class, + ServerboundResourcePackResponsePacket.DECODER, map(0x19, MINECRAFT_1_8, false), map(0x16, MINECRAFT_1_9, false), map(0x18, MINECRAFT_1_12, false), map(0x1D, MINECRAFT_1_13, false), map(0x1F, MINECRAFT_1_14, false), map(0x20, MINECRAFT_1_16, false), - map(0x21, MINECRAFT_1_16_2, false)); + map(0x21, MINECRAFT_1_16_2, false) + ); - clientbound.register(BossBarPacket.class, BossBarPacket.DECODER, + clientbound.register( + ClientboundBossBarPacket.class, + ClientboundBossBarPacket.DECODER, map(0x0C, MINECRAFT_1_9, false), map(0x0D, MINECRAFT_1_15, false), - map(0x0C, MINECRAFT_1_16, false)); - clientbound.register(ClientboundChatPacket.class, ClientboundChatPacket.DECODER, + map(0x0C, MINECRAFT_1_16, false) + ); + clientbound.register( + ClientboundChatPacket.class, + ClientboundChatPacket.DECODER, map(0x02, MINECRAFT_1_7_2, true), map(0x0F, MINECRAFT_1_9, true), map(0x0E, MINECRAFT_1_13, true), map(0x0F, MINECRAFT_1_15, true), - map(0x0E, MINECRAFT_1_16, true)); - clientbound.register(TabCompleteResponsePacket.class, TabCompleteResponsePacket.DECODER, + map(0x0E, MINECRAFT_1_16, true) + ); + clientbound.register( + ClientboundTabCompleteResponsePacket.class, + ClientboundTabCompleteResponsePacket.DECODER, map(0x3A, MINECRAFT_1_7_2, false), map(0x0E, MINECRAFT_1_9, false), map(0x10, MINECRAFT_1_13, false), map(0x11, MINECRAFT_1_15, false), map(0x10, MINECRAFT_1_16, false), - map(0x0F, MINECRAFT_1_16_2, false)); - clientbound.register(AvailableCommandsPacket.class, AvailableCommandsPacket.DECODER, + map(0x0F, MINECRAFT_1_16_2, false) + ); + clientbound.register( + ClientboundAvailableCommandsPacket.class, + ClientboundAvailableCommandsPacket.DECODER, map(0x11, MINECRAFT_1_13, false), map(0x12, MINECRAFT_1_15, false), map(0x11, MINECRAFT_1_16, false), - map(0x10, MINECRAFT_1_16_2, false)); - clientbound.register(PluginMessagePacket.class, PluginMessagePacket.DECODER, + map(0x10, MINECRAFT_1_16_2, false) + ); + clientbound.register( + PluginMessagePacket.class, + PluginMessagePacket.DECODER, map(0x3F, MINECRAFT_1_7_2, false), map(0x18, MINECRAFT_1_9, false), map(0x19, MINECRAFT_1_13, false), map(0x18, MINECRAFT_1_14, false), map(0x19, MINECRAFT_1_15, false), map(0x18, MINECRAFT_1_16, false), - map(0x17, MINECRAFT_1_16_2, false)); - clientbound.register(DisconnectPacket.class, DisconnectPacket.DECODER, + map(0x17, MINECRAFT_1_16_2, false) + ); + clientbound.register( + ClientboundDisconnectPacket.class, + ClientboundDisconnectPacket.DECODER, map(0x40, MINECRAFT_1_7_2, false), map(0x1A, MINECRAFT_1_9, false), map(0x1B, MINECRAFT_1_13, false), map(0x1A, MINECRAFT_1_14, false), map(0x1B, MINECRAFT_1_15, false), map(0x1A, MINECRAFT_1_16, false), - map(0x19, MINECRAFT_1_16_2, false)); - clientbound.register(KeepAlivePacket.class, KeepAlivePacket.DECODER, + map(0x19, MINECRAFT_1_16_2, false) + ); + clientbound.register( + ClientboundKeepAlivePacket.class, + ClientboundKeepAlivePacket.DECODER, map(0x00, MINECRAFT_1_7_2, false), map(0x1F, MINECRAFT_1_9, false), map(0x21, MINECRAFT_1_13, false), map(0x20, MINECRAFT_1_14, false), map(0x21, MINECRAFT_1_15, false), map(0x20, MINECRAFT_1_16, false), - map(0x1F, MINECRAFT_1_16_2, false)); - clientbound.register(JoinGamePacket.class, JoinGamePacket.DECODER, + map(0x1F, MINECRAFT_1_16_2, false) + ); + clientbound.register( + ClientboundJoinGamePacket.class, + ClientboundJoinGamePacket.DECODER, map(0x01, MINECRAFT_1_7_2, false), map(0x23, MINECRAFT_1_9, false), map(0x25, MINECRAFT_1_13, false), map(0x25, MINECRAFT_1_14, false), map(0x26, MINECRAFT_1_15, false), map(0x25, MINECRAFT_1_16, false), - map(0x24, MINECRAFT_1_16_2, false)); - clientbound.register(RespawnPacket.class, RespawnPacket.DECODER, + map(0x24, MINECRAFT_1_16_2, false) + ); + clientbound.register( + ClientboundRespawnPacket.class, + ClientboundRespawnPacket.DECODER, map(0x07, MINECRAFT_1_7_2, true), map(0x33, MINECRAFT_1_9, true), map(0x34, MINECRAFT_1_12, true), @@ -186,8 +249,11 @@ public enum StateRegistry { map(0x3A, MINECRAFT_1_14, true), map(0x3B, MINECRAFT_1_15, true), map(0x3A, MINECRAFT_1_16, true), - map(0x39, MINECRAFT_1_16_2, true)); - clientbound.register(ResourcePackRequestPacket.class, ResourcePackRequestPacket.DECODER, + map(0x39, MINECRAFT_1_16_2, true) + ); + clientbound.register( + ClientboundResourcePackRequestPacket.class, + ClientboundResourcePackRequestPacket.DECODER, map(0x48, MINECRAFT_1_8, true), map(0x32, MINECRAFT_1_9, true), map(0x33, MINECRAFT_1_12, true), @@ -196,8 +262,11 @@ public enum StateRegistry { map(0x39, MINECRAFT_1_14, true), map(0x3A, MINECRAFT_1_15, true), map(0x39, MINECRAFT_1_16, true), - map(0x38, MINECRAFT_1_16_2, true)); - clientbound.register(HeaderAndFooterPacket.class, HeaderAndFooterPacket.DECODER, + map(0x38, MINECRAFT_1_16_2, true) + ); + clientbound.register( + ClientboundHeaderAndFooterPacket.class, + ClientboundHeaderAndFooterPacket.DECODER, map(0x47, MINECRAFT_1_8, true), map(0x48, MINECRAFT_1_9, true), map(0x47, MINECRAFT_1_9_4, true), @@ -206,8 +275,11 @@ public enum StateRegistry { map(0x4E, MINECRAFT_1_13, true), map(0x53, MINECRAFT_1_14, true), map(0x54, MINECRAFT_1_15, true), - map(0x53, MINECRAFT_1_16, true)); - clientbound.register(TitlePacket.class, TitlePacket.DECODER, + map(0x53, MINECRAFT_1_16, true) + ); + clientbound.register( + ClientboundTitlePacket.class, + ClientboundTitlePacket.DECODER, map(0x45, MINECRAFT_1_8, true), map(0x45, MINECRAFT_1_9, true), map(0x47, MINECRAFT_1_12, true), @@ -215,8 +287,11 @@ public enum StateRegistry { map(0x4B, MINECRAFT_1_13, true), map(0x4F, MINECRAFT_1_14, true), map(0x50, MINECRAFT_1_15, true), - map(0x4F, MINECRAFT_1_16, true)); - clientbound.register(PlayerListItemPacket.class, PlayerListItemPacket.DECODER, + map(0x4F, MINECRAFT_1_16, true) + ); + clientbound.register( + ClientboundPlayerListItemPacket.class, + ClientboundPlayerListItemPacket.DECODER, map(0x38, MINECRAFT_1_7_2, false), map(0x2D, MINECRAFT_1_9, false), map(0x2E, MINECRAFT_1_12_1, false), @@ -224,27 +299,53 @@ public enum StateRegistry { map(0x33, MINECRAFT_1_14, false), map(0x34, MINECRAFT_1_15, false), map(0x33, MINECRAFT_1_16, false), - map(0x32, MINECRAFT_1_16_2, false)); + map(0x32, MINECRAFT_1_16_2, false) + ); } }, LOGIN(true) { { - serverbound.register(ServerLoginPacket.class, ServerLoginPacket.DECODER, - map(0x00, MINECRAFT_1_7_2, false)); - serverbound.register(EncryptionResponsePacket.class, EncryptionResponsePacket.DECODER, - map(0x01, MINECRAFT_1_7_2, false)); - serverbound.register(LoginPluginResponsePacket.class, LoginPluginResponsePacket.DECODER, - map(0x02, MINECRAFT_1_13, false)); - clientbound.register(DisconnectPacket.class, DisconnectPacket.DECODER, - map(0x00, MINECRAFT_1_7_2, false)); - clientbound.register(EncryptionRequestPacket.class, EncryptionRequestPacket.DECODER, - map(0x01, MINECRAFT_1_7_2, false)); - clientbound.register(ServerLoginSuccessPacket.class, ServerLoginSuccessPacket.DECODER, - map(0x02, MINECRAFT_1_7_2, false)); - clientbound.register(SetCompressionPacket.class, SetCompressionPacket.DECODER, - map(0x03, MINECRAFT_1_8, false)); - clientbound.register(LoginPluginMessagePacket.class, LoginPluginMessagePacket.DECODER, - map(0x04, MINECRAFT_1_13, false)); + serverbound.register( + ServerboundServerLoginPacket.class, + ServerboundServerLoginPacket.DECODER, + map(0x00, MINECRAFT_1_7_2, false) + ); + serverbound.register( + ServerboundEncryptionResponsePacket.class, + ServerboundEncryptionResponsePacket.DECODER, + map(0x01, MINECRAFT_1_7_2, false) + ); + serverbound.register( + ServerboundLoginPluginResponsePacket.class, + ServerboundLoginPluginResponsePacket.DECODER, + map(0x02, MINECRAFT_1_13, false) + ); + + clientbound.register( + ClientboundDisconnectPacket.class, + ClientboundDisconnectPacket.DECODER, + map(0x00, MINECRAFT_1_7_2, false) + ); + clientbound.register( + ClientboundEncryptionRequestPacket.class, + ClientboundEncryptionRequestPacket.DECODER, + map(0x01, MINECRAFT_1_7_2, false) + ); + clientbound.register( + ClientboundServerLoginSuccessPacket.class, + ClientboundServerLoginSuccessPacket.DECODER, + map(0x02, MINECRAFT_1_7_2, false) + ); + clientbound.register( + ClientboundSetCompressionPacket.class, + ClientboundSetCompressionPacket.DECODER, + map(0x03, MINECRAFT_1_8, false) + ); + clientbound.register( + ClientboundLoginPluginMessagePacket.class, + ClientboundLoginPluginMessagePacket.DECODER, + map(0x04, MINECRAFT_1_13, false) + ); } }; @@ -253,30 +354,30 @@ public enum StateRegistry { public final PacketRegistry clientbound; public final PacketRegistry serverbound; - StateRegistry(boolean fallback) { - this.clientbound = new PacketRegistry(ProtocolDirection.CLIENTBOUND, fallback); - this.serverbound = new PacketRegistry(ProtocolDirection.SERVERBOUND, fallback); + StateRegistry(boolean useMinimumIfVersionNotFound) { + this.clientbound = new PacketRegistry(PacketDirection.CLIENTBOUND, useMinimumIfVersionNotFound); + this.serverbound = new PacketRegistry(PacketDirection.SERVERBOUND, useMinimumIfVersionNotFound); } - public PacketRegistry.ProtocolRegistry getProtocolRegistry(ProtocolDirection direction, - ProtocolVersion version) { - return (direction == ProtocolDirection.SERVERBOUND ? this.serverbound : this.clientbound) + public PacketRegistry.ProtocolRegistry getProtocolRegistry(PacketDirection direction, + ProtocolVersion version) { + return (direction == PacketDirection.SERVERBOUND ? this.serverbound : this.clientbound) .getProtocolRegistry(version); } public static class PacketRegistry { - private final ProtocolDirection direction; + private final PacketDirection direction; private final Map versions; - private final boolean fallback; + private final boolean useMinimumIfVersionNotFound; - PacketRegistry(ProtocolDirection direction) { + PacketRegistry(PacketDirection direction) { this(direction, true); } - PacketRegistry(ProtocolDirection direction, boolean fallback) { + PacketRegistry(PacketDirection direction, boolean useMinimumIfVersionNotFound) { this.direction = direction; - this.fallback = fallback; + this.useMinimumIfVersionNotFound = useMinimumIfVersionNotFound; Map mutableVersions = new EnumMap<>(ProtocolVersion.class); for (ProtocolVersion version : ProtocolVersion.values()) { @@ -291,7 +392,7 @@ public enum StateRegistry { ProtocolRegistry getProtocolRegistry(final ProtocolVersion version) { ProtocolRegistry registry = versions.get(version); if (registry == null) { - if (fallback) { + if (useMinimumIfVersionNotFound) { return getProtocolRegistry(MINIMUM_VERSION); } throw new IllegalArgumentException("Could not find data for protocol version " + version); @@ -385,7 +486,7 @@ public enum StateRegistry { * @param version the protocol version * @return the packet instance, or {@code null} if the ID is not registered */ - public @Nullable Packet decodePacket(final int id, ByteBuf buf, ProtocolDirection direction, + public @Nullable Packet decodePacket(final int id, ByteBuf buf, PacketDirection direction, ProtocolVersion version) { final Packet.Decoder decoder = this.packetIdToDecoder.get(id); if (decoder == null) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/ByteBufDataInput.java b/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/ByteBufDataInput.java similarity index 97% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/util/ByteBufDataInput.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/buffer/ByteBufDataInput.java index 587366adf..b7fd1035e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/ByteBufDataInput.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/ByteBufDataInput.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network.buffer; import com.google.common.io.ByteArrayDataInput; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/ByteBufDataOutput.java b/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/ByteBufDataOutput.java similarity index 96% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/util/ByteBufDataOutput.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/buffer/ByteBufDataOutput.java index 644c1e3c6..dfb84a706 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/ByteBufDataOutput.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/ByteBufDataOutput.java @@ -1,9 +1,8 @@ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network.buffer; import com.google.common.io.ByteArrayDataOutput; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; -import java.io.DataOutput; import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/DeferredByteBufHolder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/DeferredByteBufHolder.java similarity index 98% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/util/DeferredByteBufHolder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/buffer/DeferredByteBufHolder.java index 6a35a4e5e..9952e4fd0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/DeferredByteBufHolder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/DeferredByteBufHolder.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network.buffer; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufHolder; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractKeepAlivePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractKeepAlivePacket.java new file mode 100644 index 000000000..c3db20c6d --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractKeepAlivePacket.java @@ -0,0 +1,51 @@ +package com.velocitypowered.proxy.network.packet; + +import com.google.common.base.MoreObjects; +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.proxy.network.ProtocolUtils; +import io.netty.buffer.ByteBuf; +import java.util.function.LongFunction; + +public abstract class AbstractKeepAlivePacket implements Packet { + protected static

Decoder

decoder(final LongFunction

factory) { + return (buf, direction, version) -> { + final long randomId; + if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) { + randomId = buf.readLong(); + } else if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { + randomId = ProtocolUtils.readVarInt(buf); + } else { + randomId = buf.readInt(); + } + return factory.apply(randomId); + }; + } + + private final long randomId; + + protected AbstractKeepAlivePacket(final long randomId) { + this.randomId = randomId; + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) { + buf.writeLong(randomId); + } else if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { + ProtocolUtils.writeVarInt(buf, (int) randomId); + } else { + buf.writeInt((int) randomId); + } + } + + public long getRandomId() { + return randomId; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("randomId", this.randomId) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractStatusPingPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractStatusPingPacket.java new file mode 100644 index 000000000..69ffdb4c1 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractStatusPingPacket.java @@ -0,0 +1,33 @@ +package com.velocitypowered.proxy.network.packet; + +import com.google.common.base.MoreObjects; +import com.velocitypowered.api.network.ProtocolVersion; +import io.netty.buffer.ByteBuf; +import java.util.function.LongFunction; + +public abstract class AbstractStatusPingPacket implements Packet { + protected static

Decoder

decoder(final LongFunction

factory) { + return (buf, direction, version) -> { + final long randomId = buf.readLong(); + return factory.apply(randomId); + }; + } + + private final long randomId; + + protected AbstractStatusPingPacket(final long randomId) { + this.randomId = randomId; + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + buf.writeLong(this.randomId); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("randomId", this.randomId) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/Packet.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/Packet.java similarity index 58% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/Packet.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/Packet.java index b43fad23b..8e7e9b664 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/Packet.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/Packet.java @@ -1,23 +1,22 @@ -package com.velocitypowered.proxy.protocol; +package com.velocitypowered.proxy.network.packet; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import io.netty.buffer.ByteBuf; import java.util.function.Supplier; public interface Packet { @Deprecated - default void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { + default void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) { throw new UnsupportedOperationException(); } - void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion); + void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion); - boolean handle(MinecraftSessionHandler handler); + boolean handle(PacketHandler handler); interface Decoder

{ - P decode(final ByteBuf buf, final ProtocolDirection direction, final ProtocolVersion version); + P decode(final ByteBuf buf, final PacketDirection direction, final ProtocolVersion version); static

Decoder

unsupported() { return (buf, direction, version) -> { @@ -25,6 +24,10 @@ public interface Packet { }; } + static

Decoder

instance(final P packet) { + return (buf, direction, version) -> packet; + } + @Deprecated static

Decoder

method(final Supplier

factory) { return (buf, direction, version) -> { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketDirection.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketDirection.java new file mode 100644 index 000000000..aecb2d511 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketDirection.java @@ -0,0 +1,6 @@ +package com.velocitypowered.proxy.network.packet; + +public enum PacketDirection { + SERVERBOUND, + CLIENTBOUND; +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketHandler.java new file mode 100644 index 000000000..38881d15f --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketHandler.java @@ -0,0 +1,176 @@ +package com.velocitypowered.proxy.network.packet; + +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundAvailableCommandsPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; +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.ClientboundJoinGamePacket; +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.ClientboundResourcePackRequestPacket; +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.ClientboundTitlePacket; +import com.velocitypowered.proxy.network.packet.legacy.LegacyHandshakePacket; +import com.velocitypowered.proxy.network.packet.legacy.LegacyPingPacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket; +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.ServerboundLoginPluginResponsePacket; +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.shared.PluginMessagePacket; + +public interface PacketHandler { + default boolean handle(PluginMessagePacket packet) { + return false; + } + + /* + * Clientbound + */ + + default boolean handle(ClientboundAvailableCommandsPacket commands) { + return false; + } + + default boolean handle(ClientboundBossBarPacket packet) { + return false; + } + + default boolean handle(ClientboundChatPacket packet) { + return false; + } + + default boolean handle(ClientboundDisconnectPacket packet) { + return false; + } + + default boolean handle(ClientboundEncryptionRequestPacket packet) { + return false; + } + + default boolean handle(ClientboundHeaderAndFooterPacket packet) { + return false; + } + + default boolean handle(ClientboundJoinGamePacket packet) { + return false; + } + + default boolean handle(ClientboundKeepAlivePacket packet) { + return false; + } + + default boolean handle(ClientboundLoginPluginMessagePacket packet) { + return false; + } + + default boolean handle(ClientboundPlayerListItemPacket packet) { + return false; + } + + default boolean handle(ClientboundResourcePackRequestPacket packet) { + return false; + } + + default boolean handle(ClientboundRespawnPacket packet) { + return false; + } + + default boolean handle(ClientboundServerLoginSuccessPacket packet) { + return false; + } + + default boolean handle(ClientboundSetCompressionPacket packet) { + return false; + } + + default boolean handle(ClientboundStatusPingPacket packet) { + return false; + } + + default boolean handle(ClientboundStatusResponsePacket packet) { + return false; + } + + default boolean handle(ClientboundTabCompleteResponsePacket packet) { + return false; + } + + default boolean handle(ClientboundTitlePacket packet) { + return false; + } + + /* + * Serverbound + */ + + default boolean handle(ServerboundChatPacket packet) { + return false; + } + + default boolean handle(ServerboundClientSettingsPacket packet) { + return false; + } + + default boolean handle(ServerboundEncryptionResponsePacket packet) { + return false; + } + + default boolean handle(ServerboundHandshakePacket packet) { + return false; + } + + default boolean handle(ServerboundKeepAlivePacket packet) { + return false; + } + + default boolean handle(ServerboundLoginPluginResponsePacket packet) { + return false; + } + + default boolean handle(ServerboundResourcePackResponsePacket packet) { + return false; + } + + default boolean handle(ServerboundServerLoginPacket packet) { + return false; + } + + default boolean handle(ServerboundStatusPingPacket packet) { + return false; + } + + default boolean handle(ServerboundStatusRequestPacket packet) { + return false; + } + + default boolean handle(ServerboundTabCompleteRequestPacket packet) { + return false; + } + + /* + * Legacy + */ + + default boolean handle(LegacyHandshakePacket packet) { + return false; + } + + default boolean handle(LegacyPingPacket packet) { + return false; + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/AvailableCommandsPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java similarity index 92% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/AvailableCommandsPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java index ffce940e9..38d98a43e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/AvailableCommandsPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; @@ -18,11 +18,11 @@ import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.RootCommandNode; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentPropertyRegistry; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import com.velocitypowered.proxy.network.serialization.brigadier.ArgumentPropertyRegistry; import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; @@ -35,8 +35,8 @@ import java.util.concurrent.CompletableFuture; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; -public class AvailableCommandsPacket implements Packet { - public static final Decoder DECODER = Decoder.method(AvailableCommandsPacket::new); +public class ClientboundAvailableCommandsPacket implements Packet { + public static final Decoder DECODER = Decoder.method(ClientboundAvailableCommandsPacket::new); private static final Command PLACEHOLDER_COMMAND = source -> 0; @@ -63,7 +63,7 @@ public class AvailableCommandsPacket implements Packet { } @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) { int commands = ProtocolUtils.readVarInt(buf); WireNode[] wireNodes = new WireNode[commands]; for (int i = 0; i < commands; i++) { @@ -95,7 +95,7 @@ public class AvailableCommandsPacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) { // Assign all the children an index. Deque> childrenQueue = new ArrayDeque<>(ImmutableList.of(rootNode)); Object2IntMap> idMappings = new Object2IntLinkedOpenHashMap<>(); @@ -165,7 +165,7 @@ public class AvailableCommandsPacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBarPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java similarity index 76% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBarPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java index 714906e90..d60b5e965 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBarPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java @@ -1,17 +1,18 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.clientbound; +import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import java.util.UUID; import org.checkerframework.checker.nullness.qual.Nullable; -public class BossBarPacket implements Packet { +public class ClientboundBossBarPacket implements Packet { - public static final Decoder DECODER = Decoder.method(BossBarPacket::new); + public static final Decoder DECODER = Decoder.method(ClientboundBossBarPacket::new); public static final int ADD = 0; public static final int REMOVE = 1; @@ -88,20 +89,7 @@ public class BossBarPacket implements Packet { } @Override - public String toString() { - return "BossBarPacket{" - + "uuid=" + uuid - + ", action=" + action - + ", name='" + name + '\'' - + ", percent=" + percent - + ", color=" + color - + ", overlay=" + overlay - + ", flags=" + flags - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { this.uuid = ProtocolUtils.readUuid(buf); this.action = ProtocolUtils.readVarInt(buf); switch (action) { @@ -133,7 +121,7 @@ public class BossBarPacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { if (uuid == null) { throw new IllegalStateException("No boss bar UUID specified"); } @@ -174,14 +162,27 @@ public class BossBarPacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } - public static BossBarPacket createRemovePacket(UUID id) { - BossBarPacket packet = new BossBarPacket(); + public static ClientboundBossBarPacket createRemovePacket(UUID id) { + ClientboundBossBarPacket packet = new ClientboundBossBarPacket(); packet.setUuid(id); packet.setAction(REMOVE); return packet; } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("uuid", this.uuid) + .add("action", this.action) + .add("name", this.name) + .add("percent", this.percent) + .add("color", this.color) + .add("overlay", this.overlay) + .add("flags", this.flags) + .toString(); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientboundChatPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java similarity index 70% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientboundChatPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java index a10f23339..896afdb80 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientboundChatPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java @@ -1,17 +1,16 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.clientbound; +import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; +import java.util.UUID; import org.checkerframework.checker.nullness.qual.Nullable; -import java.util.UUID; - public class ClientboundChatPacket implements Packet { - public static final Decoder DECODER = Decoder.method(ClientboundChatPacket::new); public static final byte CHAT_TYPE = (byte) 0; @@ -32,7 +31,7 @@ public class ClientboundChatPacket implements Packet { } @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { message = ProtocolUtils.readString(buf); if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { type = buf.readByte(); @@ -43,7 +42,7 @@ public class ClientboundChatPacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { if (message == null) { throw new IllegalStateException("Message is not specified"); } @@ -57,7 +56,7 @@ public class ClientboundChatPacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } @@ -78,10 +77,10 @@ public class ClientboundChatPacket implements Packet { @Override public String toString() { - return "ClientboundChatPacket{" - + "message='" + message + '\'' - + ", type=" + type - + ", sender=" + sender - + '}'; + return MoreObjects.toStringHelper(this) + .add("message", this.message) + .add("type", this.type) + .add("sender", this.sender) + .toString(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java new file mode 100644 index 000000000..f5f268df1 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java @@ -0,0 +1,66 @@ +package com.velocitypowered.proxy.network.packet.clientbound; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; +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.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; +import net.kyori.adventure.text.Component; +import org.checkerframework.checker.nullness.qual.Nullable; + +public class ClientboundDisconnectPacket implements Packet { + public static final Decoder DECODER = Decoder.method(ClientboundDisconnectPacket::new); + + private @Nullable String reason; + + public ClientboundDisconnectPacket() { + } + + public ClientboundDisconnectPacket(String reason) { + this.reason = Preconditions.checkNotNull(reason, "reason"); + } + + public String getReason() { + if (reason == null) { + throw new IllegalStateException("No reason specified"); + } + return reason; + } + + public void setReason(@Nullable String reason) { + this.reason = reason; + } + + @Override + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + reason = ProtocolUtils.readString(buf); + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + if (reason == null) { + throw new IllegalStateException("No reason specified."); + } + ProtocolUtils.writeString(buf, reason); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public static ClientboundDisconnectPacket create(Component component, ProtocolVersion version) { + Preconditions.checkNotNull(component, "component"); + return new ClientboundDisconnectPacket(ProtocolUtils.getJsonChatSerializer(version).serialize(component)); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("reason", this.reason) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java similarity index 60% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequestPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java index fcc624754..ee226f4c9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequestPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java @@ -1,17 +1,17 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.clientbound; import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY; +import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; -import java.util.Arrays; -public class EncryptionRequestPacket implements Packet { - public static final Decoder DECODER = Decoder.method(EncryptionRequestPacket::new); +public class ClientboundEncryptionRequestPacket implements Packet { + public static final Decoder DECODER = Decoder.method(ClientboundEncryptionRequestPacket::new); private String serverId = ""; private byte[] publicKey = EMPTY_BYTE_ARRAY; @@ -34,15 +34,7 @@ public class EncryptionRequestPacket implements Packet { } @Override - public String toString() { - return "EncryptionRequestPacket{" - + "publicKey=" + Arrays.toString(publicKey) - + ", verifyToken=" + Arrays.toString(verifyToken) - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { this.serverId = ProtocolUtils.readString(buf, 20); if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { @@ -55,7 +47,7 @@ public class EncryptionRequestPacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { ProtocolUtils.writeString(buf, this.serverId); if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { @@ -68,7 +60,16 @@ public class EncryptionRequestPacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("serverId", this.serverId) + .add("publicKey", this.publicKey) + .add("verifyToken", this.verifyToken) + .toString(); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java new file mode 100644 index 000000000..e24594299 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java @@ -0,0 +1,62 @@ +package com.velocitypowered.proxy.network.packet.clientbound; + +import static com.velocitypowered.proxy.network.ProtocolUtils.writeString; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; + +public class ClientboundHeaderAndFooterPacket implements Packet { + public static final Decoder DECODER = Decoder.method(ClientboundHeaderAndFooterPacket::new); + + private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}"; + private static final ClientboundHeaderAndFooterPacket RESET + = new ClientboundHeaderAndFooterPacket(); + + private final String header; + private final String footer; + + public ClientboundHeaderAndFooterPacket() { + this(EMPTY_COMPONENT, EMPTY_COMPONENT); + } + + public ClientboundHeaderAndFooterPacket(String header, String footer) { + this.header = Preconditions.checkNotNull(header, "header"); + this.footer = Preconditions.checkNotNull(footer, "footer"); + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + writeString(buf, header); + writeString(buf, footer); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public String getHeader() { + return header; + } + + public String getFooter() { + return footer; + } + + public static ClientboundHeaderAndFooterPacket reset() { + return RESET; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("header", this.header) + .add("footer", this.footer) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGamePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java similarity index 77% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGamePacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java index 1d8fcb3c4..1b5b43f17 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGamePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java @@ -1,22 +1,23 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.clientbound; +import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.registry.DimensionData; import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.connection.registry.DimensionRegistry; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import net.kyori.adventure.nbt.BinaryTagTypes; import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.ListBinaryTag; import org.checkerframework.checker.nullness.qual.Nullable; -public class JoinGamePacket implements Packet { - public static final Decoder DECODER = Decoder.method(JoinGamePacket::new); +public class ClientboundJoinGamePacket implements Packet { + public static final Decoder DECODER = Decoder.method(ClientboundJoinGamePacket::new); private int entityId; private short gamemode; @@ -35,138 +36,16 @@ public class JoinGamePacket implements Packet { private short previousGamemode; // 1.16+ private CompoundBinaryTag biomeRegistry; // 1.16.2+ - public int getEntityId() { - return entityId; - } - - public void setEntityId(int entityId) { - this.entityId = entityId; - } - - public short getGamemode() { - return gamemode; - } - - public void setGamemode(short gamemode) { - this.gamemode = gamemode; - } - - public int getDimension() { - return dimension; + public void withDimension(int dimension) { + this.dimension = dimension; } public void setDimension(int dimension) { this.dimension = dimension; } - public long getPartialHashedSeed() { - return partialHashedSeed; - } - - public short getDifficulty() { - return difficulty; - } - - public void setDifficulty(short difficulty) { - this.difficulty = difficulty; - } - - public int getMaxPlayers() { - return maxPlayers; - } - - public void setMaxPlayers(int maxPlayers) { - this.maxPlayers = maxPlayers; - } - - public @Nullable String getLevelType() { - return levelType; - } - - public void setLevelType(String levelType) { - this.levelType = levelType; - } - - public int getViewDistance() { - return viewDistance; - } - - public void setViewDistance(int viewDistance) { - this.viewDistance = viewDistance; - } - - public boolean isReducedDebugInfo() { - return reducedDebugInfo; - } - - public void setReducedDebugInfo(boolean reducedDebugInfo) { - this.reducedDebugInfo = reducedDebugInfo; - } - - public DimensionInfo getDimensionInfo() { - return dimensionInfo; - } - - public void setDimensionInfo(DimensionInfo dimensionInfo) { - this.dimensionInfo = dimensionInfo; - } - - public DimensionRegistry getDimensionRegistry() { - return dimensionRegistry; - } - - public void setDimensionRegistry(DimensionRegistry dimensionRegistry) { - this.dimensionRegistry = dimensionRegistry; - } - - public short getPreviousGamemode() { - return previousGamemode; - } - - public void setPreviousGamemode(short previousGamemode) { - this.previousGamemode = previousGamemode; - } - - public boolean getIsHardcore() { - return isHardcore; - } - - public void setIsHardcore(boolean isHardcore) { - this.isHardcore = isHardcore; - } - - public CompoundBinaryTag getBiomeRegistry() { - return biomeRegistry; - } - - public void setBiomeRegistry(CompoundBinaryTag biomeRegistry) { - this.biomeRegistry = biomeRegistry; - } - - public DimensionData getCurrentDimensionData() { - return currentDimensionData; - } - @Override - public String toString() { - return "JoinGamePacket{" - + "entityId=" + entityId - + ", gamemode=" + gamemode - + ", dimension=" + dimension - + ", partialHashedSeed=" + partialHashedSeed - + ", difficulty=" + difficulty - + ", maxPlayers=" + maxPlayers - + ", levelType='" + levelType + '\'' - + ", viewDistance=" + viewDistance - + ", reducedDebugInfo=" + reducedDebugInfo - + ", dimensionRegistry='" + dimensionRegistry + '\'' - + ", dimensionInfo='" + dimensionInfo + '\'' - + ", previousGamemode=" + previousGamemode - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { this.entityId = buf.readInt(); if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) { this.isHardcore = buf.readBoolean(); @@ -239,7 +118,7 @@ public class JoinGamePacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { buf.writeInt(entityId); if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) { buf.writeBoolean(isHardcore); @@ -306,8 +185,90 @@ public class JoinGamePacket implements Packet { } } + public int getEntityId() { + return entityId; + } + + public short getGamemode() { + return gamemode; + } + + public int getDimension() { + return dimension; + } + + public long getPartialHashedSeed() { + return partialHashedSeed; + } + + public short getDifficulty() { + return difficulty; + } + + public int getMaxPlayers() { + return maxPlayers; + } + + public @Nullable String getLevelType() { + return levelType; + } + + public int getViewDistance() { + return viewDistance; + } + + public boolean isReducedDebugInfo() { + return reducedDebugInfo; + } + + public DimensionInfo getDimensionInfo() { + return dimensionInfo; + } + + public DimensionRegistry getDimensionRegistry() { + return dimensionRegistry; + } + + public short getPreviousGamemode() { + return previousGamemode; + } + + public boolean getIsHardcore() { + return isHardcore; + } + + public CompoundBinaryTag getBiomeRegistry() { + return biomeRegistry; + } + + public DimensionData getCurrentDimensionData() { + return currentDimensionData; + } + @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("entityId", this.entityId) + .add("gamemode", this.gamemode) + .add("dimension", this.dimension) + .add("partialHashedSeed", this.partialHashedSeed) + .add("difficulty", this.difficulty) + .add("isHardcore", this.isHardcore) + .add("maxPlayers", this.maxPlayers) + .add("levelType", this.levelType) + .add("viewDistance", this.viewDistance) + .add("reducedDebugInfo", this.reducedDebugInfo) + .add("showRespawnScreen", this.showRespawnScreen) + .add("dimensionRegistry", this.dimensionRegistry) + .add("dimensionInfo", this.dimensionInfo) + .add("currentDimensionData", this.currentDimensionData) + .add("previousGamemode", this.previousGamemode) + .add("biomeRegistry", this.biomeRegistry) + .toString(); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundKeepAlivePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundKeepAlivePacket.java new file mode 100644 index 000000000..f8331151f --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundKeepAlivePacket.java @@ -0,0 +1,18 @@ +package com.velocitypowered.proxy.network.packet.clientbound; + +import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketHandler; + +public class ClientboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet { + public static final Decoder DECODER = decoder(ClientboundKeepAlivePacket::new); + + public ClientboundKeepAlivePacket(final long randomId) { + super(randomId); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessagePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java similarity index 54% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessagePacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java index b50ac10e1..1205eafb5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessagePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java @@ -1,19 +1,19 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.clientbound; +import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import io.netty.buffer.DefaultByteBufHolder; import io.netty.buffer.Unpooled; import java.util.Objects; import org.checkerframework.checker.nullness.qual.Nullable; -public class LoginPluginMessagePacket extends DefaultByteBufHolder implements Packet { - - public static final Decoder DECODER = (buf, direction, version) -> { +public class ClientboundLoginPluginMessagePacket extends DefaultByteBufHolder implements Packet { + public static final Decoder DECODER = (buf, direction, version) -> { final int id = ProtocolUtils.readVarInt(buf); final String channel = ProtocolUtils.readString(buf); final ByteBuf data; @@ -22,20 +22,20 @@ public class LoginPluginMessagePacket extends DefaultByteBufHolder implements Pa } else { data = Unpooled.EMPTY_BUFFER; } - return new LoginPluginMessagePacket(id, channel, data); + return new ClientboundLoginPluginMessagePacket(id, channel, data); }; private final int id; private final @Nullable String channel; - public LoginPluginMessagePacket(int id, @Nullable String channel, ByteBuf data) { + public ClientboundLoginPluginMessagePacket(int id, @Nullable String channel, ByteBuf data) { super(data); this.id = id; this.channel = channel; } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { ProtocolUtils.writeVarInt(buf, id); if (channel == null) { throw new IllegalStateException("Channel is not specified!"); @@ -45,7 +45,7 @@ public class LoginPluginMessagePacket extends DefaultByteBufHolder implements Pa } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } @@ -60,20 +60,15 @@ public class LoginPluginMessagePacket extends DefaultByteBufHolder implements Pa return channel; } - @Override - public String toString() { - return "LoginPluginMessagePacket{" - + "id=" + id - + ", channel='" + channel + '\'' - + ", data=" + super.toString() - + '}'; - } - @Override public boolean equals(final Object other) { - if(this == other) return true; - if(other == null || this.getClass() != other.getClass()) return false; - final LoginPluginMessagePacket that = (LoginPluginMessagePacket) other; + if (this == other) { + return true; + } + if (other == null || this.getClass() != other.getClass()) { + return false; + } + final ClientboundLoginPluginMessagePacket that = (ClientboundLoginPluginMessagePacket) other; return this.id == that.id && Objects.equals(this.channel, that.channel) && super.equals(other); @@ -83,4 +78,13 @@ public class LoginPluginMessagePacket extends DefaultByteBufHolder implements Pa public int hashCode() { return Objects.hash(this.id, this.channel, super.hashCode()); } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("id", this.id) + .add("channel", this.channel) + .add("data", this.contentToString()) + .toString(); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItemPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java similarity index 86% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItemPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java index 992fc5085..5b7aaef3b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItemPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java @@ -1,13 +1,14 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.clientbound; +import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.util.GameProfile; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; @@ -16,8 +17,8 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; -public class PlayerListItemPacket implements Packet { - public static final Decoder DECODER = Decoder.method(PlayerListItemPacket::new); +public class ClientboundPlayerListItemPacket implements Packet { + public static final Decoder DECODER = Decoder.method(ClientboundPlayerListItemPacket::new); public static final int ADD_PLAYER = 0; public static final int UPDATE_GAMEMODE = 1; @@ -27,12 +28,12 @@ public class PlayerListItemPacket implements Packet { private int action; private final List items = new ArrayList<>(); - public PlayerListItemPacket(int action, List items) { + public ClientboundPlayerListItemPacket(int action, List items) { this.action = action; this.items.addAll(items); } - public PlayerListItemPacket() { + public ClientboundPlayerListItemPacket() { } public int getAction() { @@ -44,7 +45,7 @@ public class PlayerListItemPacket implements Packet { } @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { action = ProtocolUtils.readVarInt(buf); int length = ProtocolUtils.readVarInt(buf); @@ -94,7 +95,7 @@ public class PlayerListItemPacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { ProtocolUtils.writeVarInt(buf, action); ProtocolUtils.writeVarInt(buf, items.size()); @@ -145,7 +146,7 @@ public class PlayerListItemPacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } @@ -158,6 +159,14 @@ public class PlayerListItemPacket implements Packet { } } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("action", this.action) + .add("items", this.items) + .toString(); + } + public static class Item { private final UUID uuid; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java new file mode 100644 index 000000000..e9a9ad969 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java @@ -0,0 +1,53 @@ +package com.velocitypowered.proxy.network.packet.clientbound; + +import com.google.common.base.MoreObjects; +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.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; +import java.util.Objects; + +public class ClientboundResourcePackRequestPacket implements Packet { + public static final Decoder DECODER = (buf, direction, version) -> { + final String url = ProtocolUtils.readString(buf); + final String hash = ProtocolUtils.readString(buf); + return new ClientboundResourcePackRequestPacket(url, hash); + }; + + private final String url; + private final String hash; + + public ClientboundResourcePackRequestPacket(final String url, final String hash) { + this.url = Objects.requireNonNull(url, "url"); + this.hash = Objects.requireNonNull(hash, "hash"); + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) { + ProtocolUtils.writeString(buf, url); + ProtocolUtils.writeString(buf, hash); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public String getUrl() { + return url; + } + + public String getHash() { + return hash; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("url", this.url) + .add("hash", this.hash) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/RespawnPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java similarity index 74% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/RespawnPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java index 81c35f365..cf5939974 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/RespawnPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java @@ -1,17 +1,18 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.clientbound; +import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.registry.DimensionData; import com.velocitypowered.proxy.connection.registry.DimensionInfo; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import net.kyori.adventure.nbt.CompoundBinaryTag; -public class RespawnPacket implements Packet { - public static final Decoder DECODER = Decoder.method(RespawnPacket::new); +public class ClientboundRespawnPacket implements Packet { + public static final Decoder DECODER = Decoder.method(ClientboundRespawnPacket::new); private int dimension; private long partialHashedSeed; @@ -23,12 +24,12 @@ public class RespawnPacket implements Packet { private short previousGamemode; // 1.16+ private DimensionData currentDimensionData; // 1.16.2+ - public RespawnPacket() { + public ClientboundRespawnPacket() { } - public RespawnPacket(int dimension, long partialHashedSeed, short difficulty, short gamemode, - String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo, - short previousGamemode, DimensionData currentDimensionData) { + public ClientboundRespawnPacket(int dimension, long partialHashedSeed, short difficulty, short gamemode, + String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo, + short previousGamemode, DimensionData currentDimensionData) { this.dimension = dimension; this.partialHashedSeed = partialHashedSeed; this.difficulty = difficulty; @@ -97,23 +98,7 @@ public class RespawnPacket implements Packet { } @Override - public String toString() { - return "RespawnPacket{" - + "dimension=" + dimension - + ", partialHashedSeed=" + partialHashedSeed - + ", difficulty=" + difficulty - + ", gamemode=" + gamemode - + ", levelType='" + levelType + '\'' - + ", shouldKeepPlayerData=" + shouldKeepPlayerData - + ", dimensionRegistryName='" + dimensionInfo.toString() + '\'' - + ", dimensionInfo=" + dimensionInfo - + ", previousGamemode=" + previousGamemode - + ", dimensionData=" + currentDimensionData - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { String dimensionIdentifier = null; String levelName = null; if (version.gte(ProtocolVersion.MINECRAFT_1_16)) { @@ -148,7 +133,7 @@ public class RespawnPacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { if (version.gte(ProtocolVersion.MINECRAFT_1_16)) { if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) { ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails()); @@ -178,7 +163,22 @@ public class RespawnPacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("dimension", this.dimension) + .add("partialHashedSeed", this.partialHashedSeed) + .add("difficulty", this.difficulty) + .add("gamemode", this.gamemode) + .add("levelType", this.levelType) + .add("shouldKeepPlayerData", this.shouldKeepPlayerData) + .add("dimensionInfo", this.dimensionInfo) + .add("previousGamemode", this.previousGamemode) + .add("currentDimensionData", this.currentDimensionData) + .toString(); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java new file mode 100644 index 000000000..95497e492 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java @@ -0,0 +1,68 @@ +package com.velocitypowered.proxy.network.packet.clientbound; + +import com.google.common.base.MoreObjects; +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.util.UuidUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import java.util.UUID; + +public class ClientboundServerLoginSuccessPacket implements Packet { + public static final Decoder DECODER = (buf, direction, version) -> { + final UUID uuid; + if (version.gte(ProtocolVersion.MINECRAFT_1_16)) { + uuid = ProtocolUtils.readUuidIntArray(buf); + } else if (version.gte(ProtocolVersion.MINECRAFT_1_7_6)) { + uuid = UUID.fromString(ProtocolUtils.readString(buf, 36)); + } else { + uuid = UuidUtils.fromUndashed(ProtocolUtils.readString(buf, 32)); + } + final String username = ProtocolUtils.readString(buf, 16); + return new ClientboundServerLoginSuccessPacket(uuid, username); + }; + + private final UUID uuid; + private final String username; + + public ClientboundServerLoginSuccessPacket(final UUID uuid, final String username) { + this.uuid = Objects.requireNonNull(uuid, "uuid"); + this.username = Objects.requireNonNull(username, "username"); + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + if (version.gte(ProtocolVersion.MINECRAFT_1_16)) { + ProtocolUtils.writeUuidIntArray(buf, uuid); + } else if (version.gte(ProtocolVersion.MINECRAFT_1_7_6)) { + ProtocolUtils.writeString(buf, uuid.toString()); + } else { + ProtocolUtils.writeString(buf, UuidUtils.toUndashed(uuid)); + } + ProtocolUtils.writeString(buf, username); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public UUID getUuid() { + return uuid; + } + + public String getUsername() { + return username; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("uuid", this.uuid) + .add("username", this.username) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundSetCompressionPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundSetCompressionPacket.java new file mode 100644 index 000000000..de5a0323a --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundSetCompressionPacket.java @@ -0,0 +1,43 @@ +package com.velocitypowered.proxy.network.packet.clientbound; + +import com.google.common.base.MoreObjects; +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.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; + +public class ClientboundSetCompressionPacket implements Packet { + public static final Decoder DECODER = (buf, direction, version) -> { + final int threshold = ProtocolUtils.readVarInt(buf); + return new ClientboundSetCompressionPacket(threshold); + }; + + private final int threshold; + + public ClientboundSetCompressionPacket(int threshold) { + this.threshold = threshold; + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + ProtocolUtils.writeVarInt(buf, threshold); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public int getThreshold() { + return threshold; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("threshold", this.threshold) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusPingPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusPingPacket.java new file mode 100644 index 000000000..a833afd76 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusPingPacket.java @@ -0,0 +1,18 @@ +package com.velocitypowered.proxy.network.packet.clientbound; + +import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketHandler; + +public class ClientboundStatusPingPacket extends AbstractStatusPingPacket implements Packet { + public static final Decoder DECODER = decoder(ClientboundStatusPingPacket::new); + + public ClientboundStatusPingPacket(final long randomId) { + super(randomId); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java new file mode 100644 index 000000000..b7cd19550 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java @@ -0,0 +1,50 @@ +package com.velocitypowered.proxy.network.packet.clientbound; + +import com.google.common.base.MoreObjects; +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.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; +import org.checkerframework.checker.nullness.qual.Nullable; + +public class ClientboundStatusResponsePacket implements Packet { + public static final Decoder DECODER = (buf, direction, version) -> { + final String status = ProtocolUtils.readString(buf, Short.MAX_VALUE); + return new ClientboundStatusResponsePacket(status); + }; + + private final @Nullable CharSequence status; + + public ClientboundStatusResponsePacket(CharSequence status) { + this.status = status; + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + if (status == null) { + throw new IllegalStateException("Status is not specified"); + } + ProtocolUtils.writeString(buf, status); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public String getStatus() { + if (status == null) { + throw new IllegalStateException("Status is not specified"); + } + return status.toString(); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", this.status) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java similarity index 76% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponsePacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java index c9f11b282..9d3fb68d6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponsePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java @@ -1,22 +1,19 @@ -package com.velocitypowered.proxy.protocol.packet; - -import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13; +package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; -public class TabCompleteResponsePacket implements Packet { - - public static final Decoder DECODER = Decoder.method(TabCompleteResponsePacket::new); +public class ClientboundTabCompleteResponsePacket implements Packet { + public static final Decoder DECODER = Decoder.method(ClientboundTabCompleteResponsePacket::new); private int transactionId; private int start; @@ -52,18 +49,8 @@ public class TabCompleteResponsePacket implements Packet { } @Override - public String toString() { - return "TabCompleteResponsePacket{" - + "transactionId=" + transactionId - + ", start=" + start - + ", length=" + length - + ", offers=" + offers - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (version.gte(MINECRAFT_1_13)) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { this.transactionId = ProtocolUtils.readVarInt(buf); this.start = ProtocolUtils.readVarInt(buf); this.length = ProtocolUtils.readVarInt(buf); @@ -83,8 +70,8 @@ public class TabCompleteResponsePacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (version.gte(MINECRAFT_1_13)) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { ProtocolUtils.writeVarInt(buf, this.transactionId); ProtocolUtils.writeVarInt(buf, this.start); ProtocolUtils.writeVarInt(buf, this.length); @@ -106,10 +93,20 @@ public class TabCompleteResponsePacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("transactionId", this.transactionId) + .add("start", this.start) + .add("length", this.length) + .add("offers", this.offers) + .toString(); + } + public static class Offer implements Comparable { private final String text; private final @Nullable Component tooltip; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTitlePacket.java similarity index 63% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTitlePacket.java index dd8bc007a..b1e690ac2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTitlePacket.java @@ -1,42 +1,42 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.clientbound; +import com.google.common.base.MoreObjects; import com.google.common.primitives.Ints; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.util.DurationUtils; import io.netty.buffer.ByteBuf; import java.util.Arrays; import net.kyori.adventure.title.Title; import org.checkerframework.checker.nullness.qual.Nullable; -public class TitlePacket implements Packet { +public class ClientboundTitlePacket implements Packet { + public static final Decoder DECODER = Decoder.unsupported(); - public static final Decoder DECODER = Decoder.unsupported(); - - public static TitlePacket hide(final ProtocolVersion version) { + public static ClientboundTitlePacket hide(final ProtocolVersion version) { return version.gte(ProtocolVersion.MINECRAFT_1_11) ? Instances.HIDE : Instances.HIDE_OLD; } - public static TitlePacket reset(final ProtocolVersion version) { + public static ClientboundTitlePacket reset(final ProtocolVersion version) { return version.gte(ProtocolVersion.MINECRAFT_1_11) - ? Instances.RESET - : Instances.RESET_OLD; + ? Instances.RESET + : Instances.RESET_OLD; } - public static TitlePacket times(final ProtocolVersion version, final Title.Times times) { + public static ClientboundTitlePacket times(final ProtocolVersion version, final Title.Times times) { final int action = version.gte(ProtocolVersion.MINECRAFT_1_11) - ? SET_TIMES - : SET_TIMES_OLD; - return new TitlePacket( - action, - (int) DurationUtils.toTicks(times.fadeIn()), - (int) DurationUtils.toTicks(times.stay()), - (int) DurationUtils.toTicks(times.fadeOut()) + ? SET_TIMES + : SET_TIMES_OLD; + return new ClientboundTitlePacket( + action, + (int) DurationUtils.toTicks(times.fadeIn()), + (int) DurationUtils.toTicks(times.stay()), + (int) DurationUtils.toTicks(times.fadeOut()) ); } @@ -57,7 +57,7 @@ public class TitlePacket implements Packet { private final int stay; private final int fadeOut; - private TitlePacket(final int action) { + private ClientboundTitlePacket(final int action) { checkAction(action, HIDE, RESET, HIDE_OLD, RESET_OLD); this.action = action; this.component = null; @@ -66,7 +66,7 @@ public class TitlePacket implements Packet { this.fadeOut = -1; } - public TitlePacket(final int action, final String component) { + public ClientboundTitlePacket(final int action, final String component) { checkAction(action, SET_TITLE, SET_SUBTITLE, SET_ACTION_BAR); this.action = action; this.component = component; @@ -75,7 +75,7 @@ public class TitlePacket implements Packet { this.fadeOut = -1; } - public TitlePacket(final int action, final int fadeIn, final int stay, final int fadeOut) { + public ClientboundTitlePacket(final int action, final int fadeIn, final int stay, final int fadeOut) { checkAction(action, SET_TIMES, SET_TIMES_OLD); this.action = action; this.component = null; @@ -91,7 +91,7 @@ public class TitlePacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { ProtocolUtils.writeVarInt(buf, action); if (version.gte(ProtocolVersion.MINECRAFT_1_11)) { // 1.11+ shifted the action enum by 1 to handle the action bar @@ -139,7 +139,7 @@ public class TitlePacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } @@ -165,21 +165,23 @@ public class TitlePacket implements Packet { @Override public String toString() { - return "TitlePacket{" - + "action=" + action - + ", component='" + component + '\'' - + ", fadeIn=" + fadeIn - + ", stay=" + stay - + ", fadeOut=" + fadeOut - + '}'; + return MoreObjects.toStringHelper(this) + .add("action", this.action) + .add("component", this.component) + .add("fadeIn", this.fadeIn) + .add("stay", this.stay) + .add("fadeOut", this.fadeOut) + .toString(); } public static final class Instances { - public static final TitlePacket HIDE = new TitlePacket(TitlePacket.HIDE); - public static final TitlePacket RESET = new TitlePacket(TitlePacket.RESET); + public static final ClientboundTitlePacket HIDE + = new ClientboundTitlePacket(ClientboundTitlePacket.HIDE); + public static final ClientboundTitlePacket RESET + = new ClientboundTitlePacket(ClientboundTitlePacket.RESET); - public static final TitlePacket HIDE_OLD = new TitlePacket(TitlePacket.HIDE_OLD); - public static final TitlePacket RESET_OLD = new TitlePacket(TitlePacket.RESET_OLD); + public static final ClientboundTitlePacket HIDE_OLD = new ClientboundTitlePacket(ClientboundTitlePacket.HIDE_OLD); + public static final ClientboundTitlePacket RESET_OLD = new ClientboundTitlePacket(ClientboundTitlePacket.RESET_OLD); private Instances() { } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyDisconnectPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java similarity index 95% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyDisconnectPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java index 917a0b9f9..4f8099476 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyDisconnectPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java @@ -1,9 +1,8 @@ -package com.velocitypowered.proxy.protocol.packet.legacy; +package com.velocitypowered.proxy.network.packet.legacy; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing.Players; -import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyHandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyHandshakePacket.java new file mode 100644 index 000000000..42f44388c --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyHandshakePacket.java @@ -0,0 +1,20 @@ +package com.velocitypowered.proxy.network.packet.legacy; + +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; + +public class LegacyHandshakePacket implements LegacyPacket, Packet { + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacyping/LegacyMinecraftPingVersion.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyMinecraftPingVersion.java similarity index 60% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacyping/LegacyMinecraftPingVersion.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyMinecraftPingVersion.java index 5c0864f7d..5b63c44c2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacyping/LegacyMinecraftPingVersion.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyMinecraftPingVersion.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet.legacyping; +package com.velocitypowered.proxy.network.packet.legacy; public enum LegacyMinecraftPingVersion { MINECRAFT_1_3, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPacket.java new file mode 100644 index 000000000..67ff76360 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPacket.java @@ -0,0 +1,4 @@ +package com.velocitypowered.proxy.network.packet.legacy; + +public interface LegacyPacket { +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyPingPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPingPacket.java similarity index 65% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyPingPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPingPacket.java index 3d8413e45..6d18c5b3e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyPingPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPingPacket.java @@ -1,10 +1,9 @@ -package com.velocitypowered.proxy.protocol.packet.legacy; +package com.velocitypowered.proxy.network.packet.legacy; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import java.net.InetSocketAddress; import org.checkerframework.checker.nullness.qual.Nullable; @@ -25,12 +24,12 @@ public class LegacyPingPacket implements LegacyPacket, Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { throw new UnsupportedOperationException(); } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerboundChatPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundChatPacket.java similarity index 55% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerboundChatPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundChatPacket.java index 25f5c6507..c9b774ddd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerboundChatPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundChatPacket.java @@ -1,14 +1,14 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.serverbound; +import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; public class ServerboundChatPacket implements Packet { - public static final Decoder DECODER = (buf, direction, version) -> { final String message = ProtocolUtils.readString(buf); return new ServerboundChatPacket(message); @@ -23,12 +23,12 @@ public class ServerboundChatPacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { ProtocolUtils.writeString(buf, message); } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } @@ -38,8 +38,8 @@ public class ServerboundChatPacket implements Packet { @Override public String toString() { - return "ServerboundChatPacket{" - + "message='" + message + '\'' - + '}'; + return MoreObjects.toStringHelper(this) + .add("message", this.message) + .toString(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java similarity index 55% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java index 3e2e6ddb5..9591cdae6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java @@ -1,16 +1,16 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.serverbound; +import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class ClientSettingsPacket implements Packet { - - public static final Decoder DECODER = Decoder.method(ClientSettingsPacket::new); +public class ServerboundClientSettingsPacket implements Packet { + public static final Decoder DECODER = Decoder.method(ServerboundClientSettingsPacket::new); private @Nullable String locale; private byte viewDistance; @@ -20,11 +20,11 @@ public class ClientSettingsPacket implements Packet { private short skinParts; private int mainHand; - public ClientSettingsPacket() { + public ServerboundClientSettingsPacket() { } - public ClientSettingsPacket(String locale, byte viewDistance, int chatVisibility, boolean chatColors, - short skinParts, int mainHand) { + public ServerboundClientSettingsPacket(String locale, byte viewDistance, int chatVisibility, boolean chatColors, + short skinParts, int mainHand) { this.locale = locale; this.viewDistance = viewDistance; this.chatVisibility = chatVisibility; @@ -33,71 +33,8 @@ public class ClientSettingsPacket implements Packet { this.mainHand = mainHand; } - public String getLocale() { - if (locale == null) { - throw new IllegalStateException("No locale specified"); - } - return locale; - } - - public void setLocale(String locale) { - this.locale = locale; - } - - public byte getViewDistance() { - return viewDistance; - } - - public void setViewDistance(byte viewDistance) { - this.viewDistance = viewDistance; - } - - public int getChatVisibility() { - return chatVisibility; - } - - public void setChatVisibility(int chatVisibility) { - this.chatVisibility = chatVisibility; - } - - public boolean isChatColors() { - return chatColors; - } - - public void setChatColors(boolean chatColors) { - this.chatColors = chatColors; - } - - public short getSkinParts() { - return skinParts; - } - - public void setSkinParts(short skinParts) { - this.skinParts = skinParts; - } - - public int getMainHand() { - return mainHand; - } - - public void setMainHand(int mainHand) { - this.mainHand = mainHand; - } - @Override - public String toString() { - return "ClientSettingsPacket{" - + "locale='" + locale + '\'' - + ", viewDistance=" + viewDistance - + ", chatVisibility=" + chatVisibility - + ", chatColors=" + chatColors - + ", skinParts=" + skinParts - + ", mainHand=" + mainHand - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { this.locale = ProtocolUtils.readString(buf, 16); this.viewDistance = buf.readByte(); this.chatVisibility = ProtocolUtils.readVarInt(buf); @@ -115,7 +52,7 @@ public class ClientSettingsPacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { if (locale == null) { throw new IllegalStateException("No locale specified"); } @@ -136,7 +73,47 @@ public class ClientSettingsPacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } + + public String getLocale() { + if (locale == null) { + throw new IllegalStateException("No locale specified"); + } + return locale; + } + + public byte getViewDistance() { + return viewDistance; + } + + public int getChatVisibility() { + return chatVisibility; + } + + public boolean isChatColors() { + return chatColors; + } + + public short getSkinParts() { + return skinParts; + } + + public int getMainHand() { + return mainHand; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("locale", this.locale) + .add("viewDistance", this.viewDistance) + .add("chatVisibility", this.chatVisibility) + .add("chatColors", this.chatColors) + .add("difficulty", this.difficulty) + .add("skinParts", this.skinParts) + .add("mainHand", this.mainHand) + .toString(); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundEncryptionResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundEncryptionResponsePacket.java new file mode 100644 index 000000000..78401e2ad --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundEncryptionResponsePacket.java @@ -0,0 +1,64 @@ +package com.velocitypowered.proxy.network.packet.serverbound; + +import com.google.common.base.MoreObjects; +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.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; + +public class ServerboundEncryptionResponsePacket implements Packet { + public static final Decoder DECODER = (buf, direction, version) -> { + final byte[] sharedSecret; + final byte[] verifyToken; + if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { + sharedSecret = ProtocolUtils.readByteArray(buf, 256); + verifyToken = ProtocolUtils.readByteArray(buf, 128); + } else { + sharedSecret = ProtocolUtils.readByteArray17(buf); + verifyToken = ProtocolUtils.readByteArray17(buf); + } + return new ServerboundEncryptionResponsePacket(sharedSecret, verifyToken); + }; + + private final byte[] sharedSecret; + private final byte[] verifyToken; + + public ServerboundEncryptionResponsePacket(final byte[] sharedSecret, final byte[] verifyToken) { + this.sharedSecret = sharedSecret; + this.verifyToken = verifyToken; + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { + ProtocolUtils.writeByteArray(buf, sharedSecret); + ProtocolUtils.writeByteArray(buf, verifyToken); + } else { + ProtocolUtils.writeByteArray17(sharedSecret, buf, false); + ProtocolUtils.writeByteArray17(verifyToken, buf, false); + } + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public byte[] getSharedSecret() { + return sharedSecret.clone(); + } + + public byte[] getVerifyToken() { + return verifyToken.clone(); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("sharedSecret", this.sharedSecret) + .add("verifyToken", this.verifyToken) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java new file mode 100644 index 000000000..7f910a0fb --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java @@ -0,0 +1,94 @@ +package com.velocitypowered.proxy.network.packet.serverbound; + +import com.google.common.base.MoreObjects; +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.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; + +public class ServerboundHandshakePacket implements Packet { + public static final Decoder DECODER = (buf, direction, version) -> { + int realProtocolVersion = ProtocolUtils.readVarInt(buf); + final ProtocolVersion protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion); + final String hostname = ProtocolUtils.readString(buf); + final int port = buf.readUnsignedShort(); + final int nextStatus = ProtocolUtils.readVarInt(buf); + return new ServerboundHandshakePacket(protocolVersion, hostname, port, nextStatus); + }; + + private ProtocolVersion protocolVersion; + private String serverAddress = ""; + private int port; + private int nextStatus; + + public ServerboundHandshakePacket() { + } + + public ServerboundHandshakePacket(final ProtocolVersion protocolVersion, final String hostname, final int port, final int nextStatus) { + this.protocolVersion = protocolVersion; + this.serverAddress = hostname; + this.port = port; + this.nextStatus = nextStatus; + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion ignored) { + ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol()); + ProtocolUtils.writeString(buf, this.serverAddress); + buf.writeShort(this.port); + ProtocolUtils.writeVarInt(buf, this.nextStatus); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public ProtocolVersion getProtocolVersion() { + return protocolVersion; + } + + @Deprecated + public void setProtocolVersion(ProtocolVersion protocolVersion) { + this.protocolVersion = protocolVersion; + } + + public String getServerAddress() { + return serverAddress; + } + + @Deprecated + public void setServerAddress(String serverAddress) { + this.serverAddress = serverAddress; + } + + public int getPort() { + return port; + } + + @Deprecated + public void setPort(int port) { + this.port = port; + } + + public int getNextStatus() { + return nextStatus; + } + + @Deprecated + public void setNextStatus(int nextStatus) { + this.nextStatus = nextStatus; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("protocolVersion", this.protocolVersion) + .add("serverAddress", this.serverAddress) + .add("port", this.port) + .add("nextStatus", this.nextStatus) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundKeepAlivePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundKeepAlivePacket.java new file mode 100644 index 000000000..7c680b184 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundKeepAlivePacket.java @@ -0,0 +1,18 @@ +package com.velocitypowered.proxy.network.packet.serverbound; + +import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketHandler; + +public class ServerboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet { + public static final Decoder DECODER = decoder(ServerboundKeepAlivePacket::new); + + public ServerboundKeepAlivePacket(final long randomId) { + super(randomId); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java new file mode 100644 index 000000000..4591156a8 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java @@ -0,0 +1,84 @@ +package com.velocitypowered.proxy.network.packet.serverbound; + +import com.google.common.base.MoreObjects; +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.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.DefaultByteBufHolder; +import io.netty.buffer.Unpooled; +import java.util.Objects; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; + +public class ServerboundLoginPluginResponsePacket extends DefaultByteBufHolder implements Packet { + public static final Decoder DECODER = (buf, direction, version) -> { + final int id = ProtocolUtils.readVarInt(buf); + final boolean success = buf.readBoolean(); + final ByteBuf data; + if (buf.isReadable()) { + data = buf.readSlice(buf.readableBytes()); + } else { + data = Unpooled.EMPTY_BUFFER; + } + return new ServerboundLoginPluginResponsePacket(id, success, data); + }; + + private final int id; + private final boolean success; + + public ServerboundLoginPluginResponsePacket(int id, boolean success, @MonotonicNonNull ByteBuf buf) { + super(buf); + this.id = id; + this.success = success; + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + ProtocolUtils.writeVarInt(buf, id); + buf.writeBoolean(success); + buf.writeBytes(content()); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public int getId() { + return id; + } + + public boolean isSuccess() { + return success; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("id", this.id) + .add("success", this.success) + .add("data", this.contentToString()) + .toString(); + } + + @Override + public boolean equals(final Object other) { + if (this == other) { + return true; + } + if (other == null || this.getClass() != other.getClass()) { + return false; + } + final ServerboundLoginPluginResponsePacket that = (ServerboundLoginPluginResponsePacket) other; + return this.id == that.id + && Objects.equals(this.success, that.success) + && super.equals(other); + } + + @Override + public int hashCode() { + return Objects.hash(this.id, this.success, super.hashCode()); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java new file mode 100644 index 000000000..4f93b2f90 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java @@ -0,0 +1,57 @@ +package com.velocitypowered.proxy.network.packet.serverbound; + +import com.google.common.base.MoreObjects; +import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent.Status; +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.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; +import org.checkerframework.checker.nullness.qual.Nullable; + +public class ServerboundResourcePackResponsePacket implements Packet { + public static final Decoder DECODER = (buf, direction, version) -> { + final String hash; + if (version.lte(ProtocolVersion.MINECRAFT_1_9_4)) { + hash = ProtocolUtils.readString(buf); + } else { + hash = null; + } + final Status status = Status.values()[ProtocolUtils.readVarInt(buf)]; + return new ServerboundResourcePackResponsePacket(hash, status); + }; + + private final @Nullable String hash; + private final Status status; + + public ServerboundResourcePackResponsePacket(final @Nullable String hash, final Status status) { + this.hash = hash; + this.status = status; + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) { + if (protocolVersion.lte(ProtocolVersion.MINECRAFT_1_9_4)) { + ProtocolUtils.writeString(buf, hash); + } + ProtocolUtils.writeVarInt(buf, status.ordinal()); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public Status getStatus() { + return status; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("hash", this.hash) + .add("status", this.status) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundServerLoginPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundServerLoginPacket.java new file mode 100644 index 000000000..443f2ce71 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundServerLoginPacket.java @@ -0,0 +1,50 @@ +package com.velocitypowered.proxy.network.packet.serverbound; + +import com.google.common.base.MoreObjects; +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.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import com.velocitypowered.proxy.util.except.QuietDecoderException; +import io.netty.buffer.ByteBuf; +import java.util.Objects; + +public class ServerboundServerLoginPacket implements Packet { + private static final QuietDecoderException EMPTY_USERNAME = new QuietDecoderException("Empty username!"); + + public static final Decoder DECODER = (buf, direction, version) -> { + final String username = ProtocolUtils.readString(buf, 16); + if (username.isEmpty()) { + throw EMPTY_USERNAME; + } + return new ServerboundServerLoginPacket(username); + }; + + private final String username; + + public ServerboundServerLoginPacket(String username) { + this.username = Objects.requireNonNull(username, "username"); + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + ProtocolUtils.writeString(buf, username); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + public String getUsername() { + return username; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("username", this.username) + .toString(); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusPingPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusPingPacket.java new file mode 100644 index 000000000..6fff3934c --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusPingPacket.java @@ -0,0 +1,18 @@ +package com.velocitypowered.proxy.network.packet.serverbound; + +import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketHandler; + +public class ServerboundStatusPingPacket extends AbstractStatusPingPacket implements Packet { + public static final Decoder DECODER = decoder(ServerboundStatusPingPacket::new); + + public ServerboundStatusPingPacket(final long randomId) { + super(randomId); + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java new file mode 100644 index 000000000..675fbe064 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java @@ -0,0 +1,30 @@ +package com.velocitypowered.proxy.network.packet.serverbound; + +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; +import io.netty.buffer.ByteBuf; + +public class ServerboundStatusRequestPacket implements Packet { + public static final ServerboundStatusRequestPacket INSTANCE = new ServerboundStatusRequestPacket(); + public static final Decoder DECODER = Decoder.instance(INSTANCE); + + private ServerboundStatusRequestPacket() { + } + + @Override + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { + // There is no data to decode. + } + + @Override + public boolean handle(PacketHandler handler) { + return handler.handle(this); + } + + @Override + public String toString() { + return "StatusRequestPacket"; + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java similarity index 74% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequestPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java index d06c9bf38..4b41b959a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequestPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.serverbound; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_8; @@ -6,16 +6,15 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9; import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class TabCompleteRequestPacket implements Packet { - - public static final Decoder DECODER = Decoder.method(TabCompleteRequestPacket::new); +public class ServerboundTabCompleteRequestPacket implements Packet { + public static final Decoder DECODER = Decoder.method(ServerboundTabCompleteRequestPacket::new); private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048; @@ -69,18 +68,7 @@ public class TabCompleteRequestPacket implements Packet { } @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("command", command) - .add("transactionId", transactionId) - .add("assumeCommand", assumeCommand) - .add("hasPosition", hasPosition) - .add("position", position) - .toString(); - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { if (version.gte(MINECRAFT_1_13)) { this.transactionId = ProtocolUtils.readVarInt(buf); this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN); @@ -99,7 +87,7 @@ public class TabCompleteRequestPacket implements Packet { } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { if (command == null) { throw new IllegalStateException("Command is not specified"); } @@ -122,7 +110,18 @@ public class TabCompleteRequestPacket implements Packet { } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("command", command) + .add("transactionId", transactionId) + .add("assumeCommand", assumeCommand) + .add("hasPosition", hasPosition) + .add("position", position) + .toString(); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessagePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/shared/PluginMessagePacket.java similarity index 76% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessagePacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/packet/shared/PluginMessagePacket.java index a23450812..2b5e1eaa0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessagePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/shared/PluginMessagePacket.java @@ -1,12 +1,13 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.network.packet.shared; -import static com.velocitypowered.proxy.protocol.util.PluginMessageUtil.transformLegacyToModernChannel; +import static com.velocitypowered.proxy.network.PluginMessageUtil.transformLegacyToModernChannel; +import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.PacketHandler; import io.netty.buffer.ByteBuf; import io.netty.buffer.DefaultByteBufHolder; import java.util.Objects; @@ -14,7 +15,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; public class PluginMessagePacket extends DefaultByteBufHolder implements Packet { - public static final Decoder DECODER = (buf, direction, version) -> { String channel = ProtocolUtils.readString(buf); if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { @@ -38,7 +38,7 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet } @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { if (channel == null) { throw new IllegalStateException("Channel is not specified."); } @@ -55,7 +55,7 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet } @Override - public boolean handle(MinecraftSessionHandler handler) { + public boolean handle(PacketHandler handler) { return handler.handle(this); } @@ -91,18 +91,14 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet return (PluginMessagePacket) super.touch(hint); } - @Override - public String toString() { - return "PluginMessagePacket{" - + "channel='" + channel + '\'' - + ", data=" + super.toString() - + '}'; - } - @Override public boolean equals(final Object other) { - if(this == other) return true; - if(other == null || this.getClass() != other.getClass()) return false; + if (this == other) { + return true; + } + if (other == null || this.getClass() != other.getClass()) { + return false; + } final PluginMessagePacket that = (PluginMessagePacket) other; return Objects.equals(this.channel, that.channel) && super.equals(other); @@ -112,4 +108,12 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet public int hashCode() { return Objects.hash(this.channel, super.hashCode()); } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("channel", this.channel) + .add("data", this.contentToString()) + .toString(); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/AutoReadHolderHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/AutoReadHolderHandler.java similarity index 96% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/AutoReadHolderHandler.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/AutoReadHolderHandler.java index 037bf47f9..69012455a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/AutoReadHolderHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/AutoReadHolderHandler.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java similarity index 99% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java index a59318974..37c8897bc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import static com.velocitypowered.api.event.connection.ProxyQueryEvent.QueryType.BASIC; import static com.velocitypowered.api.event.connection.ProxyQueryEvent.QueryType.FULL; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingDecoder.java similarity index 85% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingDecoder.java index 1bb86ca2d..95277af02 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingDecoder.java @@ -1,10 +1,10 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; -import static com.velocitypowered.proxy.protocol.util.NettyPreconditions.checkFrame; +import static com.velocitypowered.proxy.network.NettyPreconditions.checkFrame; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyHandshakePacket; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket; -import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; +import com.velocitypowered.proxy.network.packet.legacy.LegacyHandshakePacket; +import com.velocitypowered.proxy.network.packet.legacy.LegacyMinecraftPingVersion; +import com.velocitypowered.proxy.network.packet.legacy.LegacyPingPacket; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingEncoder.java similarity index 86% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingEncoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingEncoder.java index 0a96f01bb..dc00506b5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingEncoder.java @@ -1,6 +1,6 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; -import com.velocitypowered.proxy.protocol.packet.legacy.LegacyDisconnectPacket; +import com.velocitypowered.proxy.network.packet.legacy.LegacyDisconnectPacket; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherDecoder.java similarity index 95% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherDecoder.java index 6a8e5158d..0219e4604 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherDecoder.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import com.google.common.base.Preconditions; import com.velocitypowered.natives.encryption.VelocityCipher; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherEncoder.java similarity index 95% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherEncoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherEncoder.java index 8a5983b22..30dac4673 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherEncoder.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import com.google.common.base.Preconditions; import com.velocitypowered.natives.encryption.VelocityCipher; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressDecoder.java similarity index 92% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressDecoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressDecoder.java index a083a9291..7285991e8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressDecoder.java @@ -1,11 +1,11 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import static com.velocitypowered.natives.util.MoreByteBufUtils.ensureCompatible; import static com.velocitypowered.natives.util.MoreByteBufUtils.preferredBuffer; -import static com.velocitypowered.proxy.protocol.util.NettyPreconditions.checkFrame; +import static com.velocitypowered.proxy.network.NettyPreconditions.checkFrame; import com.velocitypowered.natives.compression.VelocityCompressor; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressEncoder.java similarity index 95% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressEncoder.java index a3e36f4cc..0912c437e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressEncoder.java @@ -1,8 +1,8 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import com.velocitypowered.natives.compression.VelocityCompressor; import com.velocitypowered.natives.util.MoreByteBufUtils; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftDecoder.java similarity index 89% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftDecoder.java index b24ba7d07..3271b82b5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftDecoder.java @@ -1,11 +1,11 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.StateRegistry; +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.PacketDirection; import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -19,7 +19,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter { new QuietDecoderException("A packet did not decode successfully (invalid data). If you are a " + "developer, launch Velocity with -Dvelocity.packet-decode-logging=true to see more."); - private final ProtocolDirection direction; + private final PacketDirection direction; private StateRegistry state; private StateRegistry.PacketRegistry.ProtocolRegistry registry; @@ -28,7 +28,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter { * * @param direction the direction from which we decode from */ - public MinecraftDecoder(ProtocolDirection direction) { + public MinecraftDecoder(PacketDirection direction) { this.direction = Preconditions.checkNotNull(direction, "direction"); this.registry = StateRegistry.HANDSHAKE.getProtocolRegistry(direction, ProtocolVersion.MINIMUM_VERSION); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftEncoder.java similarity index 77% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftEncoder.java index e6c0800b6..47f76f7c8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftEncoder.java @@ -1,18 +1,18 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.StateRegistry; +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.PacketDirection; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; public class MinecraftEncoder extends MessageToByteEncoder { - private final ProtocolDirection direction; + private final PacketDirection direction; private StateRegistry state; private StateRegistry.PacketRegistry.ProtocolRegistry registry; @@ -21,7 +21,7 @@ public class MinecraftEncoder extends MessageToByteEncoder { * * @param direction the direction to encode to */ - public MinecraftEncoder(ProtocolDirection direction) { + public MinecraftEncoder(PacketDirection direction) { this.direction = Preconditions.checkNotNull(direction, "direction"); this.registry = StateRegistry.HANDSHAKE .getProtocolRegistry(direction, ProtocolVersion.MINIMUM_VERSION); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintFrameDecoder.java similarity index 92% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintFrameDecoder.java index 6ffeaa44f..7c45c28fa 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintFrameDecoder.java @@ -1,6 +1,6 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; -import com.velocitypowered.proxy.protocol.netty.VarintByteDecoder.DecodeResult; +import com.velocitypowered.proxy.network.pipeline.VarintByteDecoder.DecodeResult; import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintLengthEncoder.java similarity index 91% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintLengthEncoder.java index 667ab6303..673bf065b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintLengthEncoder.java @@ -1,8 +1,8 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import com.velocitypowered.natives.encryption.JavaVelocityCipher; import com.velocitypowered.natives.util.Natives; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/VarintByteDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java similarity index 93% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/VarintByteDecoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java index 1c01f1244..56da82e6d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/VarintByteDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; import io.netty.util.ByteProcessor; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/netty/SeparatePoolInetNameResolver.java b/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java similarity index 98% rename from proxy/src/main/java/com/velocitypowered/proxy/network/netty/SeparatePoolInetNameResolver.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java index 75e03d5f6..b1d695e19 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/netty/SeparatePoolInetNameResolver.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.network.netty; +package com.velocitypowered.proxy.network.resolver; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/FaviconSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/FaviconSerializer.java similarity index 93% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/util/FaviconSerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/FaviconSerializer.java index a67862323..818c76103 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/FaviconSerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/FaviconSerializer.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network.serialization; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/GameProfileSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/GameProfileSerializer.java similarity index 96% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/util/GameProfileSerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/GameProfileSerializer.java index c93b9a3cc..acabbfa0e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/GameProfileSerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/GameProfileSerializer.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network.serialization; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/VelocityLegacyHoverEventSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/VelocityLegacyHoverEventSerializer.java similarity index 97% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/util/VelocityLegacyHoverEventSerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/VelocityLegacyHoverEventSerializer.java index dbf27b039..dcfc3f45c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/VelocityLegacyHoverEventSerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/VelocityLegacyHoverEventSerializer.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network.serialization; import java.io.IOException; import java.util.UUID; @@ -7,7 +7,6 @@ import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.TagStringIO; import net.kyori.adventure.nbt.api.BinaryTagHolder; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent.ShowEntity; import net.kyori.adventure.text.event.HoverEvent.ShowItem; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ArgumentPropertyRegistry.java similarity index 86% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ArgumentPropertyRegistry.java index c175f8dc4..484eab616 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ArgumentPropertyRegistry.java @@ -1,11 +1,11 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; -import static com.velocitypowered.proxy.protocol.packet.brigadier.DoubleArgumentPropertySerializer.DOUBLE; -import static com.velocitypowered.proxy.protocol.packet.brigadier.EmptyArgumentPropertySerializer.EMPTY; -import static com.velocitypowered.proxy.protocol.packet.brigadier.FloatArgumentPropertySerializer.FLOAT; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.INTEGER; -import static com.velocitypowered.proxy.protocol.packet.brigadier.LongArgumentPropertySerializer.LONG; -import static com.velocitypowered.proxy.protocol.packet.brigadier.StringArgumentPropertySerializer.STRING; +import static com.velocitypowered.proxy.network.serialization.brigadier.DoubleArgumentPropertySerializer.DOUBLE; +import static com.velocitypowered.proxy.network.serialization.brigadier.EmptyArgumentPropertySerializer.EMPTY; +import static com.velocitypowered.proxy.network.serialization.brigadier.FloatArgumentPropertySerializer.FLOAT; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.INTEGER; +import static com.velocitypowered.proxy.network.serialization.brigadier.LongArgumentPropertySerializer.LONG; +import static com.velocitypowered.proxy.network.serialization.brigadier.StringArgumentPropertySerializer.STRING; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; @@ -14,7 +14,7 @@ import com.mojang.brigadier.arguments.FloatArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.LongArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; import io.netty.buffer.ByteBuf; import java.util.HashMap; import java.util.Map; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ArgumentPropertySerializer.java similarity index 77% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertySerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ArgumentPropertySerializer.java index 077474a63..1e1105d56 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ArgumentPropertySerializer.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ByteArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ByteArgumentPropertySerializer.java similarity index 86% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ByteArgumentPropertySerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ByteArgumentPropertySerializer.java index 742084a0e..6f037fc0f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ByteArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ByteArgumentPropertySerializer.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/DoubleArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/DoubleArgumentPropertySerializer.java similarity index 73% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/DoubleArgumentPropertySerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/DoubleArgumentPropertySerializer.java index 269d686d0..3ce325766 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/DoubleArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/DoubleArgumentPropertySerializer.java @@ -1,8 +1,8 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.HAS_MINIMUM; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.getFlags; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.HAS_MINIMUM; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.getFlags; import com.mojang.brigadier.arguments.DoubleArgumentType; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/EmptyArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/EmptyArgumentPropertySerializer.java similarity index 89% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/EmptyArgumentPropertySerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/EmptyArgumentPropertySerializer.java index f101484a7..e8cdba120 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/EmptyArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/EmptyArgumentPropertySerializer.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/FloatArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/FloatArgumentPropertySerializer.java similarity index 72% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/FloatArgumentPropertySerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/FloatArgumentPropertySerializer.java index 1ccd7af23..f5c079697 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/FloatArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/FloatArgumentPropertySerializer.java @@ -1,8 +1,8 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.HAS_MINIMUM; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.getFlags; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.HAS_MINIMUM; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.getFlags; import com.mojang.brigadier.arguments.FloatArgumentType; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/GenericArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/GenericArgumentPropertySerializer.java similarity index 92% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/GenericArgumentPropertySerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/GenericArgumentPropertySerializer.java index f4e27dbf6..f25854eb5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/GenericArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/GenericArgumentPropertySerializer.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; import com.mojang.brigadier.arguments.ArgumentType; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/IntegerArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/IntegerArgumentPropertySerializer.java similarity index 95% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/IntegerArgumentPropertySerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/IntegerArgumentPropertySerializer.java index 29a112a68..a4c09a390 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/IntegerArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/IntegerArgumentPropertySerializer.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; import com.mojang.brigadier.arguments.IntegerArgumentType; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/LongArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/LongArgumentPropertySerializer.java similarity index 71% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/LongArgumentPropertySerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/LongArgumentPropertySerializer.java index 9d3b40b6d..e63823836 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/LongArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/LongArgumentPropertySerializer.java @@ -1,8 +1,8 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.HAS_MINIMUM; -import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.getFlags; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.HAS_MINIMUM; +import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.getFlags; import com.mojang.brigadier.arguments.LongArgumentType; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/PassthroughProperty.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/PassthroughProperty.java similarity index 92% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/PassthroughProperty.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/PassthroughProperty.java index deb5bdda3..2a43df76a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/PassthroughProperty.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/PassthroughProperty.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/StringArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/StringArgumentPropertySerializer.java similarity index 91% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/StringArgumentPropertySerializer.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/StringArgumentPropertySerializer.java index 3c6f03a1e..3ec2e3911 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/StringArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/StringArgumentPropertySerializer.java @@ -1,7 +1,7 @@ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; import com.mojang.brigadier.arguments.StringArgumentType; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; import io.netty.buffer.ByteBuf; /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolDirection.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolDirection.java deleted file mode 100644 index d1a218b12..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolDirection.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.velocitypowered.proxy.protocol; - -public enum ProtocolDirection { - SERVERBOUND, - CLIENTBOUND; -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/DisconnectPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/DisconnectPacket.java deleted file mode 100644 index 05a44b9cc..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/DisconnectPacket.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.google.common.base.Preconditions; -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import io.netty.buffer.ByteBuf; -import net.kyori.adventure.text.Component; -import org.checkerframework.checker.nullness.qual.Nullable; - -public class DisconnectPacket implements Packet { - public static final Decoder DECODER = Decoder.method(DisconnectPacket::new); - - private @Nullable String reason; - - public DisconnectPacket() { - } - - public DisconnectPacket(String reason) { - this.reason = Preconditions.checkNotNull(reason, "reason"); - } - - public String getReason() { - if (reason == null) { - throw new IllegalStateException("No reason specified"); - } - return reason; - } - - public void setReason(@Nullable String reason) { - this.reason = reason; - } - - @Override - public String toString() { - return "DisconnectPacket{" - + "reason='" + reason + '\'' - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - reason = ProtocolUtils.readString(buf); - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (reason == null) { - throw new IllegalStateException("No reason specified."); - } - ProtocolUtils.writeString(buf, reason); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } - - public static DisconnectPacket create(Component component, ProtocolVersion version) { - Preconditions.checkNotNull(component, "component"); - return new DisconnectPacket(ProtocolUtils.getJsonChatSerializer(version).serialize(component)); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponsePacket.java deleted file mode 100644 index 06f1c660a..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponsePacket.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import io.netty.buffer.ByteBuf; -import java.util.Arrays; - -public class EncryptionResponsePacket implements Packet { - public static final Decoder DECODER = Decoder.method(EncryptionResponsePacket::new); - - private byte[] sharedSecret = EMPTY_BYTE_ARRAY; - private byte[] verifyToken = EMPTY_BYTE_ARRAY; - - public byte[] getSharedSecret() { - return sharedSecret.clone(); - } - - public byte[] getVerifyToken() { - return verifyToken.clone(); - } - - @Override - public String toString() { - return "EncryptionResponsePacket{" - + "sharedSecret=" + Arrays.toString(sharedSecret) - + ", verifyToken=" + Arrays.toString(verifyToken) - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { - this.sharedSecret = ProtocolUtils.readByteArray(buf, 256); - this.verifyToken = ProtocolUtils.readByteArray(buf, 128); - } else { - this.sharedSecret = ProtocolUtils.readByteArray17(buf); - this.verifyToken = ProtocolUtils.readByteArray17(buf); - } - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { - ProtocolUtils.writeByteArray(buf, sharedSecret); - ProtocolUtils.writeByteArray(buf, verifyToken); - } else { - ProtocolUtils.writeByteArray17(sharedSecret, buf, false); - ProtocolUtils.writeByteArray17(verifyToken, buf, false); - } - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java deleted file mode 100644 index 9d11ea1f5..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import io.netty.buffer.ByteBuf; - -public class HandshakePacket implements Packet { - - public static final Decoder DECODER = Decoder.method(HandshakePacket::new); - - private ProtocolVersion protocolVersion; - private String serverAddress = ""; - private int port; - private int nextStatus; - - public ProtocolVersion getProtocolVersion() { - return protocolVersion; - } - - public void setProtocolVersion(ProtocolVersion protocolVersion) { - this.protocolVersion = protocolVersion; - } - - public String getServerAddress() { - return serverAddress; - } - - public void setServerAddress(String serverAddress) { - this.serverAddress = serverAddress; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public int getNextStatus() { - return nextStatus; - } - - public void setNextStatus(int nextStatus) { - this.nextStatus = nextStatus; - } - - @Override - public String toString() { - return "HandshakePacket{" - + "protocolVersion=" + protocolVersion - + ", serverAddress='" + serverAddress + '\'' - + ", port=" + port - + ", nextStatus=" + nextStatus - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion ignored) { - int realProtocolVersion = ProtocolUtils.readVarInt(buf); - this.protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion); - this.serverAddress = ProtocolUtils.readString(buf); - this.port = buf.readUnsignedShort(); - this.nextStatus = ProtocolUtils.readVarInt(buf); - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion ignored) { - ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol()); - ProtocolUtils.writeString(buf, this.serverAddress); - buf.writeShort(this.port); - ProtocolUtils.writeVarInt(buf, this.nextStatus); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooterPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooterPacket.java deleted file mode 100644 index 8004ae70c..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooterPacket.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import static com.velocitypowered.proxy.protocol.ProtocolUtils.writeString; - -import com.google.common.base.Preconditions; -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import io.netty.buffer.ByteBuf; - -public class HeaderAndFooterPacket implements Packet { - public static final Decoder DECODER = Decoder.method(HeaderAndFooterPacket::new); - - private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}"; - private static final HeaderAndFooterPacket RESET = new HeaderAndFooterPacket(); - - private final String header; - private final String footer; - - public HeaderAndFooterPacket() { - this(EMPTY_COMPONENT, EMPTY_COMPONENT); - } - - public HeaderAndFooterPacket(String header, String footer) { - this.header = Preconditions.checkNotNull(header, "header"); - this.footer = Preconditions.checkNotNull(footer, "footer"); - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - writeString(buf, header); - writeString(buf, footer); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } - - public String getHeader() { - return header; - } - - public String getFooter() { - return footer; - } - - public static HeaderAndFooterPacket reset() { - return RESET; - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlivePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlivePacket.java deleted file mode 100644 index a8e9afb55..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlivePacket.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import io.netty.buffer.ByteBuf; - -public class KeepAlivePacket implements Packet { - - public static final Decoder DECODER = (buf, direction, version) -> { - final long randomId; - if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) { - randomId = buf.readLong(); - } else if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { - randomId = ProtocolUtils.readVarInt(buf); - } else { - randomId = buf.readInt(); - } - return new KeepAlivePacket(randomId); - }; - - private final long randomId; - - public KeepAlivePacket(final long randomId) { - this.randomId = randomId; - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) { - buf.writeLong(randomId); - } else if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { - ProtocolUtils.writeVarInt(buf, (int) randomId); - } else { - buf.writeInt((int) randomId); - } - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } - - public long getRandomId() { - return randomId; - } - - @Override - public String toString() { - return "KeepAlivePacket{" - + "randomId=" + randomId - + '}'; - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponsePacket.java deleted file mode 100644 index ba1b6e738..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponsePacket.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.DefaultByteBufHolder; -import io.netty.buffer.Unpooled; -import java.util.Objects; -import org.checkerframework.checker.nullness.qual.MonotonicNonNull; - -public class LoginPluginResponsePacket extends DefaultByteBufHolder implements Packet { - - public static final Decoder DECODER = (buf, direction, version) -> { - final int id = ProtocolUtils.readVarInt(buf); - final boolean success = buf.readBoolean(); - final ByteBuf data; - if (buf.isReadable()) { - data = buf.readSlice(buf.readableBytes()); - } else { - data = Unpooled.EMPTY_BUFFER; - } - return new LoginPluginResponsePacket(id, success, data); - }; - - private final int id; - private final boolean success; - - public LoginPluginResponsePacket(int id, boolean success, @MonotonicNonNull ByteBuf buf) { - super(buf); - this.id = id; - this.success = success; - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - ProtocolUtils.writeVarInt(buf, id); - buf.writeBoolean(success); - buf.writeBytes(content()); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } - - public int getId() { - return id; - } - - public boolean isSuccess() { - return success; - } - - @Override - public String toString() { - return "LoginPluginResponsePacket{" - + "id=" + id - + ", success=" + success - + ", data=" + super.toString() - + '}'; - } - - @Override - public boolean equals(final Object other) { - if(this == other) return true; - if(other == null || this.getClass() != other.getClass()) return false; - final LoginPluginResponsePacket that = (LoginPluginResponsePacket) other; - return this.id == that.id - && Objects.equals(this.success, that.success) - && super.equals(other); - } - - @Override - public int hashCode() { - return Objects.hash(this.id, this.success, super.hashCode()); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackRequestPacket.java deleted file mode 100644 index 6b4b2504f..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackRequestPacket.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import io.netty.buffer.ByteBuf; -import org.checkerframework.checker.nullness.qual.MonotonicNonNull; -import org.checkerframework.checker.nullness.qual.Nullable; - -public class ResourcePackRequestPacket implements Packet { - public static final Decoder DECODER = Decoder.method(ResourcePackRequestPacket::new); - - private @MonotonicNonNull String url; - private @MonotonicNonNull String hash; - - public @Nullable String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public @Nullable String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { - this.url = ProtocolUtils.readString(buf); - this.hash = ProtocolUtils.readString(buf); - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { - if (url == null || hash == null) { - throw new IllegalStateException("Packet not fully filled in yet!"); - } - ProtocolUtils.writeString(buf, url); - ProtocolUtils.writeString(buf, hash); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } - - @Override - public String toString() { - return "ResourcePackRequestPacket{" - + "url='" + url + '\'' - + ", hash='" + hash + '\'' - + '}'; - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackResponsePacket.java deleted file mode 100644 index 98433d7e4..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackResponsePacket.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent.Status; -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import io.netty.buffer.ByteBuf; -import org.checkerframework.checker.nullness.qual.MonotonicNonNull; - -public class ResourcePackResponsePacket implements Packet { - - public static final Decoder DECODER = Decoder.method(ResourcePackResponsePacket::new); - - private String hash = ""; - private @MonotonicNonNull Status status; - - public Status getStatus() { - if (status == null) { - throw new IllegalStateException("Packet not yet deserialized"); - } - return status; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { - if (protocolVersion.lte(ProtocolVersion.MINECRAFT_1_9_4)) { - this.hash = ProtocolUtils.readString(buf); - } - this.status = Status.values()[ProtocolUtils.readVarInt(buf)]; - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { - if (protocolVersion.lte(ProtocolVersion.MINECRAFT_1_9_4)) { - ProtocolUtils.writeString(buf, hash); - } - ProtocolUtils.writeVarInt(buf, status.ordinal()); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } - - @Override - public String toString() { - return "ResourcePackResponsePacket{" - + "hash=" + hash + ", " - + "status=" + status - + '}'; - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginPacket.java deleted file mode 100644 index b778cef00..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginPacket.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.google.common.base.Preconditions; -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.util.except.QuietDecoderException; -import io.netty.buffer.ByteBuf; -import org.checkerframework.checker.nullness.qual.Nullable; - -public class ServerLoginPacket implements Packet { - public static final Decoder DECODER = Decoder.method(ServerLoginPacket::new); - - private static final QuietDecoderException EMPTY_USERNAME = new QuietDecoderException("Empty username!"); - - private @Nullable String username; - - public ServerLoginPacket() { - } - - public ServerLoginPacket(String username) { - this.username = Preconditions.checkNotNull(username, "username"); - } - - public String getUsername() { - if (username == null) { - throw new IllegalStateException("No username found!"); - } - return username; - } - - @Override - public String toString() { - return "ServerLoginPacket{" - + "username='" + username + '\'' - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - username = ProtocolUtils.readString(buf, 16); - if (username.isEmpty()) { - throw EMPTY_USERNAME; - } - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (username == null) { - throw new IllegalStateException("No username found!"); - } - ProtocolUtils.writeString(buf, username); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccessPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccessPacket.java deleted file mode 100644 index 160a8d213..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccessPacket.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.api.util.UuidUtils; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import io.netty.buffer.ByteBuf; -import java.util.UUID; -import org.checkerframework.checker.nullness.qual.Nullable; - -public class ServerLoginSuccessPacket implements Packet { - public static final Decoder DECODER = Decoder.method(ServerLoginSuccessPacket::new); - - private @Nullable UUID uuid; - private @Nullable String username; - - public UUID getUuid() { - if (uuid == null) { - throw new IllegalStateException("No UUID specified!"); - } - return uuid; - } - - public void setUuid(UUID uuid) { - this.uuid = uuid; - } - - public String getUsername() { - if (username == null) { - throw new IllegalStateException("No username specified!"); - } - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - @Override - public String toString() { - return "ServerLoginSuccessPacket{" - + "uuid=" + uuid - + ", username='" + username + '\'' - + '}'; - } - - @Override - public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (version.gte(ProtocolVersion.MINECRAFT_1_16)) { - uuid = ProtocolUtils.readUuidIntArray(buf); - } else if (version.gte(ProtocolVersion.MINECRAFT_1_7_6)) { - uuid = UUID.fromString(ProtocolUtils.readString(buf, 36)); - } else { - uuid = UuidUtils.fromUndashed(ProtocolUtils.readString(buf, 32)); - } - username = ProtocolUtils.readString(buf, 16); - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (uuid == null) { - throw new IllegalStateException("No UUID specified!"); - } - if (version.gte(ProtocolVersion.MINECRAFT_1_16)) { - ProtocolUtils.writeUuidIntArray(buf, uuid); - } else if (version.gte(ProtocolVersion.MINECRAFT_1_7_6)) { - ProtocolUtils.writeString(buf, uuid.toString()); - } else { - ProtocolUtils.writeString(buf, UuidUtils.toUndashed(uuid)); - } - if (username == null) { - throw new IllegalStateException("No username specified!"); - } - ProtocolUtils.writeString(buf, username); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompressionPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompressionPacket.java deleted file mode 100644 index 3423cbfaa..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompressionPacket.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import io.netty.buffer.ByteBuf; - -public class SetCompressionPacket implements Packet { - - public static final Decoder DECODER = (buf, direction, version) -> { - final int threshold = ProtocolUtils.readVarInt(buf); - return new SetCompressionPacket(threshold); - }; - - private final int threshold; - - public SetCompressionPacket(int threshold) { - this.threshold = threshold; - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - ProtocolUtils.writeVarInt(buf, threshold); - } - - public int getThreshold() { - return threshold; - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } - - @Override - public String toString() { - return "SetCompressionPacket{" - + "threshold=" + threshold - + '}'; - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPingPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPingPacket.java deleted file mode 100644 index 501164737..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPingPacket.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import io.netty.buffer.ByteBuf; - -public class StatusPingPacket implements Packet { - - public static final Decoder DECODER = (buf, direction, version) -> { - final long randomId = buf.readLong(); - return new StatusPingPacket(randomId); - }; - - private final long randomId; - - public StatusPingPacket(final long randomId) { - this.randomId = randomId; - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - buf.writeLong(randomId); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequestPacket.java deleted file mode 100644 index f7872628e..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequestPacket.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import io.netty.buffer.ByteBuf; - -public class StatusRequestPacket implements Packet { - - public static final StatusRequestPacket INSTANCE = new StatusRequestPacket(); - public static final Decoder DECODER = (buf, direction, version) -> INSTANCE; - - private StatusRequestPacket() { - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - // There is no data to decode. - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } - - @Override - public String toString() { - return "StatusRequestPacket"; - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponsePacket.java deleted file mode 100644 index 9bde7cabc..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponsePacket.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import io.netty.buffer.ByteBuf; -import org.checkerframework.checker.nullness.qual.Nullable; - -public class StatusResponsePacket implements Packet { - - public static final Decoder DECODER = (buf, direction, version) -> { - final String status = ProtocolUtils.readString(buf, Short.MAX_VALUE); - return new StatusResponsePacket(status); - }; - - private final @Nullable CharSequence status; - - public StatusResponsePacket(CharSequence status) { - this.status = status; - } - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - if (status == null) { - throw new IllegalStateException("Status is not specified"); - } - ProtocolUtils.writeString(buf, status); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } - - public String getStatus() { - if (status == null) { - throw new IllegalStateException("Status is not specified"); - } - return status.toString(); - } - - @Override - public String toString() { - return "StatusResponsePacket{" - + "status='" + status + '\'' - + '}'; - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyHandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyHandshakePacket.java deleted file mode 100644 index 566550bf3..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyHandshakePacket.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet.legacy; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.Packet; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import io.netty.buffer.ByteBuf; - -public class LegacyHandshakePacket implements LegacyPacket, Packet { - - @Override - public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyPacket.java deleted file mode 100644 index 8f284c16b..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyPacket.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet.legacy; - -public interface LegacyPacket { -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java index b608afcf6..d1de4627a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java @@ -6,10 +6,10 @@ import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.HandshakePacket; -import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket; -import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket; +import com.velocitypowered.proxy.network.StateRegistry; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundStatusResponsePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -33,7 +33,7 @@ public class PingSessionHandler implements MinecraftSessionHandler { @Override public void activated() { - HandshakePacket handshake = new HandshakePacket(); + ServerboundHandshakePacket handshake = new ServerboundHandshakePacket(); handshake.setNextStatus(StateRegistry.STATUS_ID); SocketAddress address = server.getServerInfo().getAddress(); @@ -49,13 +49,13 @@ public class PingSessionHandler implements MinecraftSessionHandler { connection.delayedWrite(handshake); connection.setState(StateRegistry.STATUS); - connection.delayedWrite(StatusRequestPacket.INSTANCE); + connection.delayedWrite(ServerboundStatusRequestPacket.INSTANCE); connection.flush(); } @Override - public boolean handle(StatusResponsePacket packet) { + public boolean handle(ClientboundStatusResponsePacket packet) { // All good! completed = true; connection.close(true); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java index 65b9df82b..8617e2013 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -19,11 +19,11 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; -import com.velocitypowered.proxy.protocol.ProtocolDirection; -import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.pipeline.MinecraftDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftEncoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftVarintFrameDecoder; +import com.velocitypowered.proxy.network.pipeline.MinecraftVarintLengthEncoder; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; @@ -90,9 +90,9 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, - new MinecraftDecoder(ProtocolDirection.CLIENTBOUND)) + new MinecraftDecoder(PacketDirection.CLIENTBOUND)) .addLast(MINECRAFT_ENCODER, - new MinecraftEncoder(ProtocolDirection.SERVERBOUND)); + new MinecraftEncoder(PacketDirection.SERVERBOUND)); ch.pipeline().addLast(HANDLER, new MinecraftConnection(ch, server)); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java index 276d08fb8..e7d83c679 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -5,9 +5,9 @@ import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.proxy.connection.MinecraftConnection; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket; -import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundHeaderAndFooterPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -35,7 +35,7 @@ public class VelocityTabList implements TabList { Preconditions.checkNotNull(footer, "footer"); GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer( connection.getProtocolVersion()); - connection.write(new HeaderAndFooterPacket( + connection.write(new ClientboundHeaderAndFooterPacket( serializer.serialize(header), serializer.serialize(footer) )); @@ -43,7 +43,7 @@ public class VelocityTabList implements TabList { @Override public void clearHeaderAndFooter() { - connection.write(HeaderAndFooterPacket.reset()); + connection.write(ClientboundHeaderAndFooterPacket.reset()); } @Override @@ -56,9 +56,8 @@ public class VelocityTabList implements TabList { Preconditions.checkArgument(entry instanceof VelocityTabListEntry, "Not a Velocity tab list entry"); - PlayerListItemPacket.Item packetItem = PlayerListItemPacket.Item.from(entry); - connection.write(new PlayerListItemPacket(PlayerListItemPacket.ADD_PLAYER, - Collections.singletonList(packetItem))); + connection.write(new ClientboundPlayerListItemPacket(ClientboundPlayerListItemPacket.ADD_PLAYER, + Collections.singletonList(ClientboundPlayerListItemPacket.Item.from(entry)))); entries.put(entry.getProfile().getId(), (VelocityTabListEntry) entry); } @@ -68,9 +67,10 @@ public class VelocityTabList implements TabList { TabListEntry entry = entries.remove(uuid); if (entry != null) { - PlayerListItemPacket.Item packetItem = PlayerListItemPacket.Item.from(entry); - connection.write(new PlayerListItemPacket(PlayerListItemPacket.REMOVE_PLAYER, - Collections.singletonList(packetItem))); + connection.write(new ClientboundPlayerListItemPacket( + ClientboundPlayerListItemPacket.REMOVE_PLAYER, + Collections.singletonList(ClientboundPlayerListItemPacket.Item.from(entry)) + )); } return Optional.ofNullable(entry); @@ -92,12 +92,13 @@ public class VelocityTabList implements TabList { if (listEntries.isEmpty()) { return; } - List items = new ArrayList<>(listEntries.size()); + List items = new ArrayList<>(listEntries.size()); for (TabListEntry value : listEntries) { - items.add(PlayerListItemPacket.Item.from(value)); + items.add(ClientboundPlayerListItemPacket.Item.from(value)); } entries.clear(); - connection.delayedWrite(new PlayerListItemPacket(PlayerListItemPacket.REMOVE_PLAYER, items)); + connection.delayedWrite(new ClientboundPlayerListItemPacket( + ClientboundPlayerListItemPacket.REMOVE_PLAYER, items)); } @Override @@ -116,19 +117,20 @@ public class VelocityTabList implements TabList { * * @param packet the packet to process */ - public void processBackendPacket(PlayerListItemPacket packet) { + public void processBackendPacket(ClientboundPlayerListItemPacket packet) { // Packets are already forwarded on, so no need to do that here - for (PlayerListItemPacket.Item item : packet.getItems()) { + for (ClientboundPlayerListItemPacket.Item item : packet.getItems()) { UUID uuid = item.getUuid(); assert uuid != null : "1.7 tab list entry given to modern tab list handler!"; - if (packet.getAction() != PlayerListItemPacket.ADD_PLAYER && !entries.containsKey(uuid)) { + if (packet.getAction() != ClientboundPlayerListItemPacket.ADD_PLAYER + && !entries.containsKey(uuid)) { // Sometimes UPDATE_GAMEMODE is sent before ADD_PLAYER so don't want to warn here continue; } switch (packet.getAction()) { - case PlayerListItemPacket.ADD_PLAYER: { + case ClientboundPlayerListItemPacket.ADD_PLAYER: { // ensure that name and properties are available String name = item.getName(); List properties = item.getProperties(); @@ -144,24 +146,24 @@ public class VelocityTabList implements TabList { .build()); break; } - case PlayerListItemPacket.REMOVE_PLAYER: + case ClientboundPlayerListItemPacket.REMOVE_PLAYER: entries.remove(uuid); break; - case PlayerListItemPacket.UPDATE_DISPLAY_NAME: { + case ClientboundPlayerListItemPacket.UPDATE_DISPLAY_NAME: { VelocityTabListEntry entry = entries.get(uuid); if (entry != null) { entry.setDisplayNameInternal(item.getDisplayName()); } break; } - case PlayerListItemPacket.UPDATE_LATENCY: { + case ClientboundPlayerListItemPacket.UPDATE_LATENCY: { VelocityTabListEntry entry = entries.get(uuid); if (entry != null) { entry.setLatencyInternal(item.getLatency()); } break; } - case PlayerListItemPacket.UPDATE_GAMEMODE: { + case ClientboundPlayerListItemPacket.UPDATE_GAMEMODE: { VelocityTabListEntry entry = entries.get(uuid); if (entry != null) { entry.setGameModeInternal(item.getGameMode()); @@ -177,8 +179,8 @@ public class VelocityTabList implements TabList { void updateEntry(int action, TabListEntry entry) { if (entries.containsKey(entry.getProfile().getId())) { - PlayerListItemPacket.Item packetItem = PlayerListItemPacket.Item.from(entry); - connection.write(new PlayerListItemPacket(action, Collections.singletonList(packetItem))); + connection.write(new ClientboundPlayerListItemPacket(action, + Collections.singletonList(ClientboundPlayerListItemPacket.Item.from(entry)))); } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java index 5c62b281a..257941927 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java @@ -3,7 +3,7 @@ package com.velocitypowered.proxy.tablist; import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.util.GameProfile; -import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket; import java.util.Optional; import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; @@ -43,7 +43,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setDisplayName(net.kyori.adventure.text.@Nullable Component displayName) { this.displayName = displayName; - tabList.updateEntry(PlayerListItemPacket.UPDATE_DISPLAY_NAME, this); + tabList.updateEntry(ClientboundPlayerListItemPacket.UPDATE_DISPLAY_NAME, this); return this; } @@ -59,7 +59,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setLatency(int latency) { this.latency = latency; - tabList.updateEntry(PlayerListItemPacket.UPDATE_LATENCY, this); + tabList.updateEntry(ClientboundPlayerListItemPacket.UPDATE_LATENCY, this); return this; } @@ -75,7 +75,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setGameMode(int gameMode) { this.gameMode = gameMode; - tabList.updateEntry(PlayerListItemPacket.UPDATE_GAMEMODE, this); + tabList.updateEntry(ClientboundPlayerListItemPacket.UPDATE_GAMEMODE, this); return this; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java index aad866bcb..edd753daf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java @@ -4,8 +4,8 @@ import com.google.common.collect.ImmutableList; import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.proxy.connection.MinecraftConnection; -import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; -import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket.Item; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket.Item; import java.util.Collections; import java.util.Map; import java.util.Optional; @@ -46,19 +46,21 @@ public class VelocityTabListLegacy extends VelocityTabList { @Override public void clearAll() { for (TabListEntry value : entries.values()) { - connection.delayedWrite(new PlayerListItemPacket(PlayerListItemPacket.REMOVE_PLAYER, - Collections.singletonList(PlayerListItemPacket.Item.from(value)))); + connection.delayedWrite(new ClientboundPlayerListItemPacket( + ClientboundPlayerListItemPacket.REMOVE_PLAYER, + Collections.singletonList(ClientboundPlayerListItemPacket.Item.from(value)) + )); } entries.clear(); nameMapping.clear(); } @Override - public void processBackendPacket(PlayerListItemPacket packet) { + public void processBackendPacket(ClientboundPlayerListItemPacket packet) { Item item = packet.getItems().get(0); // Only one item per packet in 1.7 switch (packet.getAction()) { - case PlayerListItemPacket.ADD_PLAYER: + case ClientboundPlayerListItemPacket.ADD_PLAYER: if (nameMapping.containsKey(item.getName())) { // ADD_PLAYER also used for updating ping VelocityTabListEntry entry = entries.get(nameMapping.get(item.getName())); if (entry != null) { @@ -74,7 +76,7 @@ public class VelocityTabListLegacy extends VelocityTabList { .build()); } break; - case PlayerListItemPacket.REMOVE_PLAYER: + case ClientboundPlayerListItemPacket.REMOVE_PLAYER: UUID removedUuid = nameMapping.remove(item.getName()); if (removedUuid != null) { entries.remove(removedUuid); @@ -91,12 +93,13 @@ public class VelocityTabListLegacy extends VelocityTabList { void updateEntry(int action, TabListEntry entry) { if (entries.containsKey(entry.getProfile().getId())) { switch (action) { - case PlayerListItemPacket.UPDATE_LATENCY: - case PlayerListItemPacket.UPDATE_DISPLAY_NAME: // Add here because we removed beforehand - connection - // ADD_PLAYER also updates ping - .write(new PlayerListItemPacket(PlayerListItemPacket.ADD_PLAYER, - Collections.singletonList(PlayerListItemPacket.Item.from(entry)))); + case ClientboundPlayerListItemPacket.UPDATE_LATENCY: + case ClientboundPlayerListItemPacket.UPDATE_DISPLAY_NAME: // Add here because we + // removed beforehand + connection.write(new ClientboundPlayerListItemPacket( + ClientboundPlayerListItemPacket.ADD_PLAYER, // ADD_PLAYER also updates ping + Collections.singletonList(ClientboundPlayerListItemPacket.Item.from(entry)) + )); break; default: // Can't do anything else diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java index 57df8e4e0..f9db33c31 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java @@ -6,7 +6,7 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelRegistrar; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; -import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; +import com.velocitypowered.proxy.network.PluginMessageUtil; import java.util.Collection; import java.util.HashSet; import java.util.Map; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java index 774b79045..aa0ebb40b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java @@ -3,8 +3,8 @@ package com.velocitypowered.proxy.util.bossbar; import com.google.common.collect.MapMaker; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.packet.BossBarPacket; +import com.velocitypowered.proxy.network.ProtocolUtils; +import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket; import com.velocitypowered.proxy.util.collect.Enum2IntMap; import com.velocitypowered.proxy.util.concurrent.Once; import java.util.Collections; @@ -107,9 +107,9 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - BossBarPacket pre116Packet = holder.createTitleUpdate( + ClientboundBossBarPacket pre116Packet = holder.createTitleUpdate( newName, ProtocolVersion.MINECRAFT_1_15_2); - BossBarPacket rgbPacket = holder.createTitleUpdate( + ClientboundBossBarPacket rgbPacket = holder.createTitleUpdate( newName, ProtocolVersion.MINECRAFT_1_16); for (ConnectedPlayer player : holder.subscribers) { if (player.getProtocolVersion().gte(ProtocolVersion.MINECRAFT_1_16)) { @@ -126,7 +126,7 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - BossBarPacket packet = holder + ClientboundBossBarPacket packet = holder .createPercentUpdate(newPercent); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); @@ -140,7 +140,7 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - BossBarPacket packet = holder.createColorUpdate(newColor); + ClientboundBossBarPacket packet = holder.createColorUpdate(newColor); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); } @@ -153,7 +153,7 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - BossBarPacket packet = holder + ClientboundBossBarPacket packet = holder .createOverlayUpdate(newOverlay); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); @@ -167,7 +167,7 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - BossBarPacket packet = holder.createFlagsUpdate(); + ClientboundBossBarPacket packet = holder.createFlagsUpdate(); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); } @@ -188,14 +188,14 @@ public class AdventureBossBarManager implements BossBar.Listener { registrationOnce.run(() -> this.bar.addListener(AdventureBossBarManager.this)); } - BossBarPacket createRemovePacket() { - return BossBarPacket.createRemovePacket(this.id); + ClientboundBossBarPacket createRemovePacket() { + return ClientboundBossBarPacket.createRemovePacket(this.id); } - BossBarPacket createAddPacket(ProtocolVersion version) { - BossBarPacket packet = new BossBarPacket(); + ClientboundBossBarPacket createAddPacket(ProtocolVersion version) { + ClientboundBossBarPacket packet = new ClientboundBossBarPacket(); packet.setUuid(this.id); - packet.setAction(BossBarPacket.ADD); + packet.setAction(ClientboundBossBarPacket.ADD); packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(bar.name())); packet.setColor(COLORS_TO_PROTOCOL.get(bar.color())); packet.setOverlay(bar.overlay().ordinal()); @@ -204,49 +204,49 @@ public class AdventureBossBarManager implements BossBar.Listener { return packet; } - BossBarPacket createPercentUpdate(float newPercent) { - BossBarPacket packet = new BossBarPacket(); + ClientboundBossBarPacket createPercentUpdate(float newPercent) { + ClientboundBossBarPacket packet = new ClientboundBossBarPacket(); packet.setUuid(this.id); - packet.setAction(BossBarPacket.UPDATE_PERCENT); + packet.setAction(ClientboundBossBarPacket.UPDATE_PERCENT); packet.setPercent(newPercent); return packet; } - BossBarPacket createColorUpdate(Color color) { - BossBarPacket packet = new BossBarPacket(); + ClientboundBossBarPacket createColorUpdate(Color color) { + ClientboundBossBarPacket packet = new ClientboundBossBarPacket(); packet.setUuid(this.id); - packet.setAction(BossBarPacket.UPDATE_NAME); + packet.setAction(ClientboundBossBarPacket.UPDATE_NAME); packet.setColor(COLORS_TO_PROTOCOL.get(color)); packet.setFlags(serializeFlags(bar.flags())); return packet; } - BossBarPacket createTitleUpdate(Component name, - ProtocolVersion version) { - BossBarPacket packet = new BossBarPacket(); + ClientboundBossBarPacket createTitleUpdate(Component name, + ProtocolVersion version) { + ClientboundBossBarPacket packet = new ClientboundBossBarPacket(); packet.setUuid(this.id); - packet.setAction(BossBarPacket.UPDATE_NAME); + packet.setAction(ClientboundBossBarPacket.UPDATE_NAME); packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(name)); return packet; } - BossBarPacket createFlagsUpdate() { + ClientboundBossBarPacket createFlagsUpdate() { return createFlagsUpdate(bar.flags()); } - BossBarPacket createFlagsUpdate(Set newFlags) { - BossBarPacket packet = new BossBarPacket(); + ClientboundBossBarPacket createFlagsUpdate(Set newFlags) { + ClientboundBossBarPacket packet = new ClientboundBossBarPacket(); packet.setUuid(this.id); - packet.setAction(BossBarPacket.UPDATE_PROPERTIES); + packet.setAction(ClientboundBossBarPacket.UPDATE_PROPERTIES); packet.setColor(COLORS_TO_PROTOCOL.get(this.bar.color())); packet.setFlags(this.serializeFlags(newFlags)); return packet; } - BossBarPacket createOverlayUpdate(Overlay overlay) { - BossBarPacket packet = new BossBarPacket(); + ClientboundBossBarPacket createOverlayUpdate(Overlay overlay) { + ClientboundBossBarPacket packet = new ClientboundBossBarPacket(); packet.setUuid(this.id); - packet.setAction(BossBarPacket.UPDATE_PROPERTIES); + packet.setAction(ClientboundBossBarPacket.UPDATE_PROPERTIES); packet.setOverlay(OVERLAY_TO_PROTOCOL.get(overlay)); return packet; } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java b/proxy/src/test/java/com/velocitypowered/proxy/network/PacketRegistryTest.java similarity index 70% rename from proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java rename to proxy/src/test/java/com/velocitypowered/proxy/network/PacketRegistryTest.java index a2227d22f..e9eb47721 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/network/PacketRegistryTest.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol; +package com.velocitypowered.proxy.network; import static com.google.common.collect.Iterables.getLast; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_11; @@ -15,8 +15,10 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.protocol.packet.HandshakePacket; -import com.velocitypowered.proxy.protocol.packet.StatusPingPacket; +import com.velocitypowered.proxy.network.packet.Packet; +import com.velocitypowered.proxy.network.packet.PacketDirection; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; +import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket; import org.junit.jupiter.api.Test; @@ -24,8 +26,8 @@ class PacketRegistryTest { private StateRegistry.PacketRegistry setupRegistry() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolDirection.CLIENTBOUND); - registry.register(HandshakePacket.class, HandshakePacket.DECODER, + PacketDirection.CLIENTBOUND); + registry.register(ServerboundHandshakePacket.class, ServerboundHandshakePacket.DECODER, new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, false), new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false)); return registry; @@ -36,7 +38,8 @@ class PacketRegistryTest { StateRegistry.PacketRegistry registry = setupRegistry(); Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0); assertNotNull(packet, "Packet was not found in registry"); - assertEquals(HandshakePacket.class, packet.getClass(), "Registry returned wrong class"); + assertEquals(ServerboundHandshakePacket.class, + packet.getClass(), "Registry returned wrong class"); assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12).getPacketId(packet), "Registry did not return the correct packet ID"); @@ -47,7 +50,8 @@ class PacketRegistryTest { StateRegistry.PacketRegistry registry = setupRegistry(); Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0); assertNotNull(packet, "Packet was not found in registry"); - assertEquals(HandshakePacket.class, packet.getClass(), "Registry returned wrong class"); + assertEquals(ServerboundHandshakePacket.class, + packet.getClass(), "Registry returned wrong class"); assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12_1).getPacketId(packet), "Registry did not return the correct packet ID"); assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_14_2).getPacketId(packet), @@ -61,24 +65,27 @@ class PacketRegistryTest { @Test void failOnNoMappings() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolDirection.CLIENTBOUND); + PacketDirection.CLIENTBOUND); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket.DECODER)); + () -> registry.register(ServerboundHandshakePacket.class, + ServerboundHandshakePacket.DECODER)); assertThrows(IllegalArgumentException.class, () -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN) - .getPacketId(new HandshakePacket())); + .getPacketId(new ServerboundHandshakePacket())); } @Test void failOnWrongOrder() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolDirection.CLIENTBOUND); + PacketDirection.CLIENTBOUND); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket.DECODER, + () -> registry.register(ServerboundHandshakePacket.class, + ServerboundHandshakePacket.DECODER, new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false), new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false))); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket.DECODER, + () -> registry.register(ServerboundHandshakePacket.class, + ServerboundHandshakePacket.DECODER, new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false))); } @@ -86,22 +93,25 @@ class PacketRegistryTest { @Test void failOnDuplicate() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolDirection.CLIENTBOUND); - registry.register(HandshakePacket.class, HandshakePacket.DECODER, + PacketDirection.CLIENTBOUND); + registry.register(ServerboundHandshakePacket.class, + ServerboundHandshakePacket.DECODER, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false)); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket.DECODER, + () -> registry.register(ServerboundHandshakePacket.class, + ServerboundHandshakePacket.DECODER, new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12, false))); assertThrows(IllegalArgumentException.class, - () -> registry.register(StatusPingPacket.class, StatusPingPacket.DECODER, + () -> registry.register(ServerboundStatusPingPacket.class, ServerboundStatusPingPacket.DECODER, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_13, false))); } @Test void shouldNotFailWhenRegisterLatestProtocolVersion() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolDirection.CLIENTBOUND); - assertDoesNotThrow(() -> registry.register(HandshakePacket.class, HandshakePacket.DECODER, + PacketDirection.CLIENTBOUND); + assertDoesNotThrow(() -> registry.register(ServerboundHandshakePacket.class, + ServerboundHandshakePacket.DECODER, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false), new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS), false))); @@ -110,20 +120,20 @@ class PacketRegistryTest { @Test void registrySuppliesCorrectPacketsByProtocol() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolDirection.CLIENTBOUND); - registry.register(HandshakePacket.class, HandshakePacket.DECODER, + PacketDirection.CLIENTBOUND); + registry.register(ServerboundHandshakePacket.class, ServerboundHandshakePacket.DECODER, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false), new StateRegistry.PacketMapping(0x02, MINECRAFT_1_13, false)); - assertEquals(HandshakePacket.class, + assertEquals(ServerboundHandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0x00).getClass()); - assertEquals(HandshakePacket.class, + assertEquals(ServerboundHandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0x01).getClass()); - assertEquals(HandshakePacket.class, + assertEquals(ServerboundHandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_12_2).createPacket(0x01).getClass()); - assertEquals(HandshakePacket.class, + assertEquals(ServerboundHandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_13).createPacket(0x02).getClass()); - assertEquals(HandshakePacket.class, + assertEquals(ServerboundHandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_14_2).createPacket(0x02).getClass()); } } \ No newline at end of file diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtilTest.java b/proxy/src/test/java/com/velocitypowered/proxy/network/PluginMessageUtilTest.java similarity index 96% rename from proxy/src/test/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtilTest.java rename to proxy/src/test/java/com/velocitypowered/proxy/network/PluginMessageUtilTest.java index 2c4b162d9..77cde9a7b 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtilTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/network/PluginMessageUtilTest.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network; import static org.junit.jupiter.api.Assertions.assertEquals;