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

Make sure to deny 1.12.2 and below clients in "modern" IP forwarding.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-08-27 00:25:30 -04:00
Ursprung b5ebb4541f
Commit c2fa5d3ff1
3 geänderte Dateien mit 18 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -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;

Datei anzeigen

@ -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;

Datei anzeigen

@ -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);
}
})