From 9ce4294e6e64f6b0a89eea90bd32c6592668e88c Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 30 Dec 2018 03:52:50 -0500 Subject: [PATCH] Fix forced hosts with SRV records. --- .../client/HandshakeSessionHandler.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 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 64d24aba4..b47e23590 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 @@ -139,8 +139,19 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } private String cleanVhost(String hostname) { - int zeroIdx = hostname.indexOf('\0'); - return zeroIdx == -1 ? hostname : hostname.substring(0, zeroIdx); + // Clean out any anything after any zero byte + String cleaned = hostname; + int zeroIdx = cleaned.indexOf('\0'); + if (zeroIdx > -1) { + cleaned = hostname.substring(0, zeroIdx); + } + + // If we connect through an SRV record, there will be a period at the end (DNS usually elides + // this ending octet). + if (cleaned.endsWith(".")) { + cleaned = cleaned.substring(0, cleaned.length() - 1); + } + return cleaned; } @Override