From 62c6adb2041b3e483408f429f38cbf3606700dd3 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 6 Aug 2019 03:26:55 -0400 Subject: [PATCH] Consider forced hosts in ping passthrough --- .../proxy/config/VelocityConfiguration.java | 5 +++-- .../proxy/connection/client/StatusSessionHandler.java | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 7891d778c..6d8c24f4d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -93,8 +93,9 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi "- \"disabled\": No pass-through will be done. The velocity.toml and server-icon.png", " will determine the initial server list ping response.", "- \"mods\": Passes only the mod list from your backend server into the response.", - " This is the recommended replacement for announce-forge = true. If no backend", - " servers can be contacted, Velocity will not display any mod information.", + " The first server in your try list (or forced host) with a mod list will be", + " used. If no backend servers can be contacted, Velocity will not display any", + " mod information.", "- \"all\": Passes everything from the backend server into the response. The Velocity", " configuration is used if no servers could be contacted." }) 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 12d54e06a..613271733 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 @@ -20,7 +20,9 @@ import com.velocitypowered.proxy.protocol.packet.StatusRequest; import com.velocitypowered.proxy.protocol.packet.StatusResponse; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import io.netty.buffer.ByteBuf; +import java.net.InetSocketAddress; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -110,8 +112,11 @@ public class StatusSessionHandler implements MinecraftSessionHandler { if (passthrough == PingPassthroughMode.DISABLED) { return CompletableFuture.completedFuture(constructLocalPing(shownVersion)); } else { - return attemptPingPassthrough(configuration.getPingPassthrough(), - configuration.getAttemptConnectionOrder(), shownVersion); + String virtualHostStr = inbound.getVirtualHost().map(InetSocketAddress::getHostString) + .orElse(""); + List serversToTry = server.getConfiguration().getForcedHosts().getOrDefault( + virtualHostStr, server.getConfiguration().getAttemptConnectionOrder()); + return attemptPingPassthrough(configuration.getPingPassthrough(), serversToTry, shownVersion); } }