From 3e053d63b42aa142c7086241940052eb90354628 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 21 Feb 2020 18:36:10 -0500 Subject: [PATCH] Allow ping passthrough for descriptions too --- .../proxy/config/PingPassthroughMode.java | 1 + .../proxy/config/VelocityConfiguration.java | 19 +++++++++++-------- .../client/StatusSessionHandler.java | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/PingPassthroughMode.java b/proxy/src/main/java/com/velocitypowered/proxy/config/PingPassthroughMode.java index 89ed3ad8e..1ef700f57 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/PingPassthroughMode.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/PingPassthroughMode.java @@ -3,5 +3,6 @@ package com.velocitypowered.proxy.config; public enum PingPassthroughMode { DISABLED, MODS, + DESCRIPTION, ALL } 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 467363daf..7ab59d446 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -90,14 +90,17 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi @Comment({ "Should Velocity pass server list ping requests to a backend server?", "Available options:", - "- \"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.", - " 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." + "- \"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.", + " 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.", + "- \"description\": Uses the description and mod list from the backend server. The first", + " server in the try (or forced host) list that responds is used for the", + " description and mod list.", + "- \"all\": Passes everything from the backend server into the response. The Velocity", + " configuration is used if no servers could be contacted." }) @ConfigKey("ping-passthrough") private PingPassthroughMode pingPassthrough = PingPassthroughMode.DISABLED; 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 613271733..5fbbac0de 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 @@ -97,6 +97,24 @@ public class StatusSessionHandler implements MinecraftSessionHandler { } return fallback; }); + case DESCRIPTION: + return pingResponses.thenApply(responses -> { + // Find the first non-fallback. If it includes a modlist, add it too. + for (ServerPing response : responses) { + if (response == fallback) { + continue; + } + + return new ServerPing( + fallback.getVersion(), + fallback.getPlayers().orElse(null), + response.getDescription(), + fallback.getFavicon().orElse(null), + response.getModinfo().orElse(null) + ); + } + return fallback; + }); default: // Not possible, but covered for completeness. return CompletableFuture.completedFuture(fallback);