diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 1b7beb9b8..95a05d7bb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -57,7 +57,7 @@ public class VelocityServer implements ProxyServer { .registerTypeHierarchyAdapter(Favicon.class, new FaviconSerializer()) .create(); - private final ConnectionManager cm = new ConnectionManager(); + private final ConnectionManager cm = new ConnectionManager(this); private VelocityConfiguration configuration; private NettyHttpClient httpClient; private KeyPair serverKeyPair; 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 d88fc0f9f..fab30d067 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 @@ -6,6 +6,7 @@ import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent; import com.velocitypowered.api.event.proxy.ProxyPingEvent; import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.proxy.VelocityServer; +import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; @@ -26,9 +27,11 @@ import java.util.Optional; public class HandshakeSessionHandler implements MinecraftSessionHandler { private final MinecraftConnection connection; + private final VelocityServer server; - public HandshakeSessionHandler(MinecraftConnection connection) { + public HandshakeSessionHandler(MinecraftConnection connection, VelocityServer server) { this.connection = Preconditions.checkNotNull(connection, "connection"); + this.server = server; } @Override @@ -74,6 +77,14 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { return; } + // If the proxy is configured for modern forwarding, we must deny connections from 1.12.2 and lower, + // otherwise IP information will never get forwarded. + 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; + } + VelocityServer.getServer().getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic)); connection.setSessionHandler(new LoginSessionHandler(connection, ic)); break; 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 732b8b331..1d283e7a0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -2,6 +2,7 @@ package com.velocitypowered.proxy.network; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.velocitypowered.natives.util.Natives; +import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; import com.velocitypowered.proxy.protocol.ProtocolConstants; @@ -53,8 +54,10 @@ public final class ConnectionManager { private final TransportType transportType; private final EventLoopGroup bossGroup; private final EventLoopGroup workerGroup; + private final VelocityServer server; - public ConnectionManager() { + public ConnectionManager(VelocityServer server) { + this.server = server; this.transportType = TransportType.bestType(); this.bossGroup = transportType.createEventLoopGroup(true); this.workerGroup = transportType.createEventLoopGroup(false); @@ -83,7 +86,7 @@ public final class ConnectionManager { final MinecraftConnection connection = new MinecraftConnection(ch); connection.setState(StateRegistry.HANDSHAKE); - connection.setSessionHandler(new HandshakeSessionHandler(connection)); + connection.setSessionHandler(new HandshakeSessionHandler(connection, server)); ch.pipeline().addLast(Connections.HANDLER, connection); } })