Skip to content

Commit

Permalink
Add passthrough-default-server-ping
Browse files Browse the repository at this point in the history
  • Loading branch information
BBaoVanC committed Dec 27, 2024
1 parent 1db8c8c commit 5854a65
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -371,6 +375,10 @@ public PingPassthroughMode getPingPassthrough() {
return pingPassthrough;
}

public boolean isPassthroughDefaultServerPing() {
return passthroughDefaultServerPing;
}

public boolean isPlayerAddressLoggingEnabled() {
return enablePlayerAddressLogging;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -533,6 +543,7 @@ public static VelocityConfiguration read(Path path) throws IOException {
forwardingSecret,
kickExisting,
pingPassthroughMode,
passthroughDefaultServerPing,
enablePlayerAddressLogging,
new Servers(serversConfig),
new ForcedHosts(forcedHostsConfig),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ public CompletableFuture<ServerPing> 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<String> serversToTry = server.getConfiguration().getForcedHosts().getOrDefault(
virtualHostStr, server.getConfiguration().getAttemptConnectionOrder());
return attemptPingPassthrough(connection, passthroughMode, serversToTry, shownVersion);
Expand Down
6 changes: 6 additions & 0 deletions proxy/src/main/resources/default-velocity.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ip address withheld> in logs
enable-player-address-logging = true

Expand Down

0 comments on commit 5854a65

Please sign in to comment.