From 24cd1f4da09c99306f1597d1403fb4f786bff5b0 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 23 Jun 2020 17:05:01 -0400 Subject: [PATCH] Allow showing ping requests in the console. The default is false, but this can be enabled in the configuration if desired. --- .../proxy/config/VelocityConfiguration.java | 14 ++++++++++++++ .../connection/client/StatusSessionHandler.java | 12 ++++++++++++ 2 files changed, 26 insertions(+) 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 921556676..bac98ed1b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -423,6 +423,10 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi return advanced.isBungeePluginMessageChannel(); } + public boolean isShowPingRequests() { + return advanced.isShowPingRequests(); + } + @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -679,6 +683,10 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi @ConfigKey("bungee-plugin-message-channel") private boolean bungeePluginMessageChannel = true; + @Comment("Shows ping requests to the proxy from clients.") + @ConfigKey("show-ping-requests") + private boolean showPingRequests = false; + private Advanced() { } @@ -692,6 +700,7 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi this.proxyProtocol = toml.getBoolean("proxy-protocol", false); this.tcpFastOpen = toml.getBoolean("tcp-fast-open", false); this.bungeePluginMessageChannel = toml.getBoolean("bungee-plugin-message-channel", true); + this.showPingRequests = toml.getBoolean("show-ping-requests", false); } } @@ -727,6 +736,10 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi return bungeePluginMessageChannel; } + public boolean isShowPingRequests() { + return showPingRequests; + } + @Override public String toString() { return "Advanced{" @@ -738,6 +751,7 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi + ", proxyProtocol=" + proxyProtocol + ", tcpFastOpen=" + tcpFastOpen + ", bungeePluginMessageChannel=" + bungeePluginMessageChannel + + ", showPingRequests=" + showPingRequests + '}'; } } 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 44ac9c2a5..4b3627ec9 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 @@ -25,9 +25,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class StatusSessionHandler implements MinecraftSessionHandler { + private static final Logger logger = LogManager.getLogger(StatusSessionHandler.class); + private final VelocityServer server; private final MinecraftConnection connection; private final InboundConnection inbound; @@ -39,6 +43,14 @@ public class StatusSessionHandler implements MinecraftSessionHandler { this.inbound = inbound; } + @Override + public void activated() { + if (server.getConfiguration().isShowPingRequests()) { + logger.info("{} is pinging the server with version {}", this.inbound, + this.connection.getProtocolVersion()); + } + } + private ServerPing constructLocalPing(ProtocolVersion version) { VelocityConfiguration configuration = server.getConfiguration(); return new ServerPing(