From 5854a650264bac0af404e3dab4e435f610b5b71b Mon Sep 17 00:00:00 2001 From: BBaoVanC Date: Thu, 10 Feb 2022 17:51:04 -0600 Subject: [PATCH] Add passthrough-default-server-ping --- .../proxy/config/VelocityConfiguration.java | 15 +++++++++++++-- .../connection/util/ServerListPingHandler.java | 6 ++++++ proxy/src/main/resources/default-velocity.toml | 6 ++++++ 3 files changed, 25 insertions(+), 2 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 9c2e1e8280..55e3bc624f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -78,6 +78,8 @@ public class VelocityConfiguration implements ProxyConfig { private boolean onlineModeKickExistingPlayers = false; @Expose private PingPassthroughMode pingPassthrough = PingPassthroughMode.DISABLED; + @Expose + private boolean passthroughDefaultServerPing = true; private final Servers servers; private final ForcedHosts forcedHosts; @Expose @@ -105,8 +107,9 @@ private VelocityConfiguration(String bind, String motd, int showMaxPlayers, bool boolean preventClientProxyConnections, boolean announceForge, PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret, boolean onlineModeKickExistingPlayers, PingPassthroughMode pingPassthrough, - boolean enablePlayerAddressLogging, Servers servers, ForcedHosts forcedHosts, - Advanced advanced, Query query, Metrics metrics, boolean forceKeyAuthentication) { + boolean passthroughDefaultServerPing, boolean enablePlayerAddressLogging, Servers servers, + ForcedHosts forcedHosts, Advanced advanced, Query query, Metrics metrics, + boolean forceKeyAuthentication) { this.bind = bind; this.motd = motd; this.showMaxPlayers = showMaxPlayers; @@ -117,6 +120,7 @@ private VelocityConfiguration(String bind, String motd, int showMaxPlayers, bool this.forwardingSecret = forwardingSecret; this.onlineModeKickExistingPlayers = onlineModeKickExistingPlayers; this.pingPassthrough = pingPassthrough; + this.passthroughDefaultServerPing = passthroughDefaultServerPing; this.enablePlayerAddressLogging = enablePlayerAddressLogging; this.servers = servers; this.forcedHosts = forcedHosts; @@ -371,6 +375,10 @@ public PingPassthroughMode getPingPassthrough() { return pingPassthrough; } + public boolean isPassthroughDefaultServerPing() { + return passthroughDefaultServerPing; + } + public boolean isPlayerAddressLoggingEnabled() { return enablePlayerAddressLogging; } @@ -503,6 +511,8 @@ public static VelocityConfiguration read(Path path) throws IOException { final PingPassthroughMode pingPassthroughMode = config.getEnumOrElse("ping-passthrough", PingPassthroughMode.DISABLED); + final boolean passthroughDefaultServerPing = config.getOrElse("passthrough-default-server-ping", true); + final String bind = config.getOrElse("bind", "0.0.0.0:25565"); final int maxPlayers = config.getIntOrElse("show-max-players", 500); final boolean onlineMode = config.getOrElse("online-mode", true); @@ -533,6 +543,7 @@ public static VelocityConfiguration read(Path path) throws IOException { forwardingSecret, kickExisting, pingPassthroughMode, + passthroughDefaultServerPing, enablePlayerAddressLogging, new Servers(serversConfig), new ForcedHosts(forcedHostsConfig), diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java index 951d609861..8726df92f5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java @@ -153,6 +153,12 @@ public CompletableFuture getInitialPing(VelocityInboundConnection co String virtualHostStr = connection.getVirtualHost().map(InetSocketAddress::getHostString) .map(str -> str.toLowerCase(Locale.ROOT)) .orElse(""); + + if (!configuration.isPassthroughDefaultServerPing() + && !configuration.getForcedHosts().containsKey(virtualHostStr)) { + return CompletableFuture.completedFuture(constructLocalPing(shownVersion)); + } + List serversToTry = server.getConfiguration().getForcedHosts().getOrDefault( virtualHostStr, server.getConfiguration().getAttemptConnectionOrder()); return attemptPingPassthrough(connection, passthroughMode, serversToTry, shownVersion); diff --git a/proxy/src/main/resources/default-velocity.toml b/proxy/src/main/resources/default-velocity.toml index e402305cc1..62cadfe5ae 100644 --- a/proxy/src/main/resources/default-velocity.toml +++ b/proxy/src/main/resources/default-velocity.toml @@ -66,6 +66,12 @@ kick-existing-players = false # configuration is used if no servers could be contacted. ping-passthrough = "DISABLED" +# If enabled (default is true), then the proxy will pass all pings, including ones on hosts not +# listed in forced-hosts, to the default backend server(s). +# Otherwise, the proxy will use its own MOTD and version to reply to pings on other hosts. +# Note that this option has no effect if ping-passthrough is set to DISABLED. +passthrough-default-server-ping = true + # If not enabled (default is true) player IP addresses will be replaced by in logs enable-player-address-logging = true