From 33f333d8cc75aa468023311b2239f2043014cb0c Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 13 Oct 2018 02:34:53 -0400 Subject: [PATCH] Clean up FML/handshake stuff from virtual host. --- .../proxy/connection/client/HandshakeSessionHandler.java | 7 ++++++- .../proxy/connection/client/InitialInboundConnection.java | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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 dd5edcfe7..74e73cc0b 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 @@ -61,7 +61,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(Handshake handshake) { - InitialInboundConnection ic = new InitialInboundConnection(connection, handshake); + InitialInboundConnection ic = new InitialInboundConnection(connection, cleanVhost(handshake.getServerAddress()), handshake); switch (handshake.getNextStatus()) { case StateRegistry.STATUS_ID: connection.setState(StateRegistry.STATUS); @@ -109,6 +109,11 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } } + private String cleanVhost(String hostname) { + int zeroIdx = hostname.indexOf('\0'); + return zeroIdx == -1 ? hostname : hostname.substring(0, zeroIdx); + } + @Override public void handleGeneric(MinecraftPacket packet) { 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 1518eb5d5..411a3faa9 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 @@ -9,10 +9,12 @@ import java.util.Optional; class InitialInboundConnection implements InboundConnection { private final MinecraftConnection connection; + private final String cleanedAddress; private final Handshake handshake; - InitialInboundConnection(MinecraftConnection connection, Handshake handshake) { + InitialInboundConnection(MinecraftConnection connection, String cleanedAddress, Handshake handshake) { this.connection = connection; + this.cleanedAddress = cleanedAddress; this.handshake = handshake; } @@ -23,7 +25,7 @@ class InitialInboundConnection implements InboundConnection { @Override public Optional getVirtualHost() { - return Optional.of(InetSocketAddress.createUnresolved(handshake.getServerAddress(), handshake.getPort())); + return Optional.of(InetSocketAddress.createUnresolved(cleanedAddress, handshake.getPort())); } @Override