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 0b8eadafd..0cd9d2da0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -69,7 +69,10 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof MinecraftPacket) { - sessionHandler.handle((MinecraftPacket) msg); + MinecraftPacket pkt = (MinecraftPacket) msg; + if (!pkt.handle(sessionHandler)) { + sessionHandler.handleGeneric((MinecraftPacket) msg); + } } else if (msg instanceof ByteBuf) { try { sessionHandler.handleUnknown((ByteBuf) msg); 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 146ec86da..e0d66367f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java @@ -1,10 +1,11 @@ package com.velocitypowered.proxy.connection; import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.packet.*; import io.netty.buffer.ByteBuf; public interface MinecraftSessionHandler { - void handle(MinecraftPacket packet); + void handleGeneric(MinecraftPacket packet); default void handleUnknown(ByteBuf buf) { // No-op: we'll release the buffer later. @@ -33,4 +34,30 @@ public interface MinecraftSessionHandler { default void writabilityChanged() { } + + default boolean handle(BossBar packet) { return false; } + default boolean handle(Chat packet) { return false; } + default boolean handle(ClientSettings packet) { return false; } + default boolean handle(Disconnect packet) { return false; } + default boolean handle(EncryptionRequest packet) { return false; } + default boolean handle(EncryptionResponse packet) { return false; } + default boolean handle(Handshake packet) { return false; } + default boolean handle(HeaderAndFooter packet) { return false; } + default boolean handle(JoinGame packet) { return false; } + default boolean handle(KeepAlive packet) { return false; } + default boolean handle(LegacyHandshake packet) { return false; } + default boolean handle(LegacyPing packet) { return false; } + default boolean handle(LoginPluginMessage packet) { return false; } + default boolean handle(LoginPluginResponse packet) { return false; } + default boolean handle(PluginMessage packet) { return false; } + default boolean handle(Respawn packet) { return false; } + default boolean handle(ServerLogin packet) { return false; } + default boolean handle(ServerLoginSuccess packet) { return false; } + default boolean handle(SetCompression packet) { return false; } + default boolean handle(StatusPing packet) { return false; } + default boolean handle(StatusRequest packet) { return false; } + default boolean handle(StatusResponse packet) { return false; } + default boolean handle(TabCompleteRequest packet) { return false; } + default boolean handle(TabCompleteResponse packet) { return false; } + default boolean handle(TitlePacket packet) { return false; } } 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 556605935..518873f52 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 @@ -30,7 +30,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } @Override - public void handle(MinecraftPacket packet) { + public void handleGeneric(MinecraftPacket packet) { if (!serverConn.getPlayer().isActive()) { // Connection was left open accidentally. Close it so as to avoid "You logged in from another location" // errors. 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 4672ad990..b83671155 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 @@ -36,7 +36,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } @Override - public void handle(MinecraftPacket packet) { + public void handleGeneric(MinecraftPacket packet) { if (packet instanceof EncryptionRequest) { throw new IllegalStateException("Backend server is online-mode!"); } else if (packet instanceof LoginPluginMessage) { 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 0fbdf3328..9857c9272 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 @@ -49,7 +49,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } @Override - public void handle(MinecraftPacket packet) { + public void handleGeneric(MinecraftPacket packet) { VelocityServerConnection serverConnection = player.getConnectedServer(); if (serverConnection == null) { // No server connection yet, probably transitioning. 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 e50b006e6..efe8ec74d 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 @@ -35,39 +35,53 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public void handle(MinecraftPacket packet) { - if (packet instanceof LegacyPing || packet instanceof LegacyHandshake) { - connection.setProtocolVersion(ProtocolConstants.LEGACY); - handleLegacy(packet); - return; - } + public boolean handle(LegacyPing packet) { + connection.setProtocolVersion(ProtocolConstants.LEGACY); + VelocityConfiguration configuration = server.getConfiguration(); + ServerPing ping = new ServerPing( + new ServerPing.Version(ProtocolConstants.MAXIMUM_GENERIC_VERSION, "Velocity " + ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING), + new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(), ImmutableList.of()), + configuration.getMotdComponent(), + null, + null + ); + ProxyPingEvent event = new ProxyPingEvent(new LegacyInboundConnection(connection), ping); + server.getEventManager().fire(event) + .thenRunAsync(() -> { + // The disconnect packet is the same as the server response one. + connection.closeWith(LegacyDisconnect.fromPingResponse(LegacyPingResponse.from(event.getPing()))); + }, connection.eventLoop()); + return true; + } - if (!(packet instanceof Handshake)) { - throw new IllegalArgumentException("Did not expect packet " + packet.getClass().getName()); - } + @Override + public boolean handle(LegacyHandshake packet) { + connection.closeWith(LegacyDisconnect.from(TextComponent.of("Your client is old, please upgrade!", TextColor.RED))); + return true; + } - InitialInboundConnection ic = new InitialInboundConnection(connection, (Handshake) packet); - - Handshake handshake = (Handshake) packet; + @Override + public boolean handle(Handshake handshake) { + InitialInboundConnection ic = new InitialInboundConnection(connection, handshake); switch (handshake.getNextStatus()) { case StateRegistry.STATUS_ID: connection.setState(StateRegistry.STATUS); connection.setProtocolVersion(handshake.getProtocolVersion()); connection.setSessionHandler(new StatusSessionHandler(server, connection, ic)); - break; + return true; case StateRegistry.LOGIN_ID: connection.setState(StateRegistry.LOGIN); connection.setProtocolVersion(handshake.getProtocolVersion()); if (!ProtocolConstants.isSupported(handshake.getProtocolVersion())) { connection.closeWith(Disconnect.create(TranslatableComponent.of("multiplayer.disconnect.outdated_client"))); - return; + return true; } InetAddress address = ((InetSocketAddress) connection.getChannel().remoteAddress()).getAddress(); if (!server.getIpAttemptLimiter().attempt(address)) { connection.closeWith(Disconnect.create(TextComponent.of("You are logging in too fast, try again later."))); - return; + return true; } // Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13) and store that in the connection @@ -77,7 +91,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { // Make sure legacy forwarding is not in use on this connection. Make sure that we do _not_ reject Forge if (handshake.getServerAddress().contains("\0") && !isForge) { connection.closeWith(Disconnect.create(TextComponent.of("Running Velocity behind Velocity is unsupported."))); - return; + return true; } // If the proxy is configured for modern forwarding, we must deny connections from 1.12.2 and lower, @@ -85,41 +99,25 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && handshake.getProtocolVersion() < ProtocolConstants.MINECRAFT_1_13) { connection.closeWith(Disconnect.create(TextComponent.of("This server is only compatible with 1.13 and above."))); - return; + return true; } server.getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic)); connection.setSessionHandler(new LoginSessionHandler(server, connection, ic)); - break; + return true; default: throw new IllegalArgumentException("Invalid state " + handshake.getNextStatus()); } } @Override - public void handleUnknown(ByteBuf buf) { - throw new IllegalStateException("Unknown data " + ByteBufUtil.hexDump(buf)); + public void handleGeneric(MinecraftPacket packet) { + } - private void handleLegacy(MinecraftPacket packet) { - if (packet instanceof LegacyPing) { - VelocityConfiguration configuration = server.getConfiguration(); - ServerPing ping = new ServerPing( - new ServerPing.Version(ProtocolConstants.MAXIMUM_GENERIC_VERSION, "Velocity " + ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING), - new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(), ImmutableList.of()), - configuration.getMotdComponent(), - null, - null - ); - ProxyPingEvent event = new ProxyPingEvent(new LegacyInboundConnection(connection), ping); - server.getEventManager().fire(event) - .thenRunAsync(() -> { - // The disconnect packet is the same as the server response one. - connection.closeWith(LegacyDisconnect.fromPingResponse(LegacyPingResponse.from(event.getPing()))); - }, connection.eventLoop()); - } else if (packet instanceof LegacyHandshake) { - connection.closeWith(LegacyDisconnect.from(TextComponent.of("Your client is old, please upgrade!", TextColor.RED))); - } + @Override + public void handleUnknown(ByteBuf buf) { + throw new IllegalStateException("Unknown data " + ByteBufUtil.hexDump(buf)); } private static class LegacyInboundConnection implements InboundConnection { 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 c25298bef..36044c720 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 @@ -11,7 +11,7 @@ public class InitialConnectSessionHandler implements MinecraftSessionHandler { } @Override - public void handle(MinecraftPacket packet) { + public void handleGeneric(MinecraftPacket packet) { // No-op: will never handle packets } 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 b6455c8c8..fb1e813c8 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 @@ -59,7 +59,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } @Override - public void handle(MinecraftPacket packet) { + public void handleGeneric(MinecraftPacket packet) { if (packet instanceof LoginPluginResponse) { LoginPluginResponse lpr = (LoginPluginResponse) packet; if (lpr.getId() == playerInfoId) { 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 b34ee3bfb..0dce13c7a 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 @@ -29,7 +29,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { } @Override - public void handle(MinecraftPacket packet) { + public void handleGeneric(MinecraftPacket packet) { Preconditions.checkArgument(packet instanceof StatusPing || packet instanceof StatusRequest, "Unrecognized packet type " + packet.getClass().getName()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/MinecraftPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/MinecraftPacket.java index 2b1aa66c4..1118b7625 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/MinecraftPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/MinecraftPacket.java @@ -1,9 +1,12 @@ package com.velocitypowered.proxy.protocol; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import io.netty.buffer.ByteBuf; public interface MinecraftPacket { void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion); void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion); + + boolean handle(MinecraftSessionHandler handler); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java index c300e1b40..4b34f51e7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -150,4 +151,9 @@ public class BossBar implements MinecraftPacket { break; } } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java index 749854506..2437ff099 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java @@ -1,6 +1,7 @@ package com.velocitypowered.proxy.protocol.packet; import com.google.common.base.Preconditions; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -63,6 +64,11 @@ public class Chat implements MinecraftPacket { } } + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } + public static Chat createClientbound(Component component) { return createClientbound(component, CHAT); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java index 0637cf3fe..a0db1c064 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -111,4 +112,9 @@ public class ClientSettings implements MinecraftPacket { ProtocolUtils.writeVarInt(buf, mainHand); } } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java index f6dfd877a..1eb7188c8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java @@ -1,6 +1,7 @@ package com.velocitypowered.proxy.protocol.packet; import com.google.common.base.Preconditions; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -43,6 +44,11 @@ public class Disconnect implements MinecraftPacket { ProtocolUtils.writeString(buf, reason); } + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } + public static Disconnect create(Component component) { Preconditions.checkNotNull(component, "component"); return new Disconnect(ComponentSerializers.JSON.serialize(component)); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java index 32b8321ff..4f80cc3a4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -48,4 +49,9 @@ public class EncryptionRequest implements MinecraftPacket { ProtocolUtils.writeByteArray(buf, publicKey); ProtocolUtils.writeByteArray(buf, verifyToken); } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java index 0df20b1ae..cbefccf34 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -46,4 +47,9 @@ public class EncryptionResponse implements MinecraftPacket { ProtocolUtils.writeByteArray(buf, sharedSecret); ProtocolUtils.writeByteArray(buf, verifyToken); } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java index aef59ec2b..37fcc83a7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -68,4 +69,9 @@ public class Handshake implements MinecraftPacket { 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/HeaderAndFooter.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java index 6ee851d65..a87719574 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants.Direction; import io.netty.buffer.ByteBuf; @@ -51,6 +52,11 @@ public class HeaderAndFooter implements MinecraftPacket { writeString(buf, footer); } + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } + public static HeaderAndFooter create(Component header, Component footer) { ComponentSerializer json = ComponentSerializers.JSON; return new HeaderAndFooter(json.serialize(header), json.serialize(footer)); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java index 69aaa92da..25981a711 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -112,4 +113,9 @@ public class JoinGame implements MinecraftPacket { ProtocolUtils.writeString(buf, levelType); buf.writeBoolean(reducedDebugInfo); } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java index 1e491b61b..0de51ab9c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -42,4 +43,9 @@ public class KeepAlive implements MinecraftPacket { ProtocolUtils.writeVarInt(buf, (int) randomId); } } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyHandshake.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyHandshake.java index f6588674f..33249abf5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyHandshake.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyHandshake.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import io.netty.buffer.ByteBuf; @@ -14,4 +15,9 @@ public class LegacyHandshake implements MinecraftPacket { public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { 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/LegacyPing.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPing.java index 847160869..51f46a4b4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPing.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPing.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import io.netty.buffer.ByteBuf; @@ -14,4 +15,9 @@ public class LegacyPing implements MinecraftPacket { public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { 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/LoginPluginMessage.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java index 1b9e61037..948269012 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -61,4 +62,9 @@ public class LoginPluginMessage implements MinecraftPacket { ProtocolUtils.writeString(buf, channel); buf.writeBytes(data); } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java index 6ff252cfe..55fb339d0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -61,4 +62,9 @@ public class LoginPluginResponse implements MinecraftPacket { buf.writeBoolean(success); buf.writeBytes(data); } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java index 7b8d17f12..d57598b8f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -46,4 +47,9 @@ public class PluginMessage implements MinecraftPacket { ProtocolUtils.writeString(buf, channel); buf.writeBytes(data); } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java index 8de02919c..4aca25ed2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -78,4 +79,9 @@ public class Respawn implements MinecraftPacket { buf.writeByte(gamemode); ProtocolUtils.writeString(buf, levelType); } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java index a9cb0ac68..c399df684 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -32,4 +33,9 @@ public class ServerLogin implements MinecraftPacket { public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { 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/ServerLoginSuccess.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java index 1bf35edd7..8c0272ba3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -46,4 +47,9 @@ public class ServerLoginSuccess implements MinecraftPacket { ProtocolUtils.writeString(buf, uuid.toString()); 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/SetCompression.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java index 8157bf4ec..f1c3bbf4a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -38,4 +39,9 @@ public class SetCompression implements MinecraftPacket { public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { ProtocolUtils.writeVarInt(buf, threshold); } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPing.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPing.java index 65bf532e3..28bbcbe7d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPing.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPing.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import io.netty.buffer.ByteBuf; @@ -16,4 +17,9 @@ public class StatusPing implements MinecraftPacket { public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { 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/StatusRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequest.java index 33e1e1411..e119bb574 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequest.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import io.netty.buffer.ByteBuf; @@ -25,4 +26,9 @@ public class StatusRequest implements MinecraftPacket { public String toString() { return "StatusRequest"; } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java index 7c397fa83..e915fe812 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -32,4 +33,9 @@ public class StatusResponse implements MinecraftPacket { public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { ProtocolUtils.writeString(buf, status); } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java index a3636f85c..9448a898d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -79,4 +80,9 @@ public class TabCompleteRequest implements MinecraftPacket { buf.writeLong(position); } } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java index 0a528acd8..d58fae70d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -37,4 +38,9 @@ public class TabCompleteResponse implements MinecraftPacket { ProtocolUtils.writeString(buf, offer); } } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java index de1398060..2be5443e7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java @@ -1,6 +1,7 @@ package com.velocitypowered.proxy.protocol.packet; import com.google.common.base.Preconditions; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -134,4 +135,9 @@ public class TitlePacket implements MinecraftPacket { ", fadeOut=" + fadeOut + '}'; } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/ping/PingSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/server/ping/PingSessionHandler.java index 0bce28b74..7427cee6c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/ping/PingSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/ping/PingSessionHandler.java @@ -42,7 +42,7 @@ public class PingSessionHandler implements MinecraftSessionHandler { } @Override - public void handle(MinecraftPacket packet) { + public void handleGeneric(MinecraftPacket packet) { Preconditions.checkState(packet instanceof StatusResponse, "Did not get status response back from connection"); // All good!