From a9df92d30862ee7a1b4470cd76073eacf2050e76 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 19 Jul 2020 19:46:10 +0200 Subject: [PATCH 1/2] Add logging to command executions by players --- .../proxy/connection/client/ClientPlaySessionHandler.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index bacb098e1..87b0e849b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -129,6 +129,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { server.getCommandManager().callCommandEvent(player, msg.substring(1)) .thenComposeAsync(event -> processCommandExecuteResult(originalCommand, event.getResult())) + .whenCompleteAsync((ignored, throwable) -> { + logger.info("{} -> executed command /{}", player.getUsername(), originalCommand); + }) .exceptionally(e -> { logger.info("Exception occurred while running command for {}", player.getUsername(), e); From da92d83b14e46a72fbc3b7d83554ce31f5e88e96 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 19 Jul 2020 21:49:12 +0200 Subject: [PATCH 2/2] Make the logging of commands configurable --- .../proxy/config/VelocityConfiguration.java | 11 +++++++++++ .../connection/client/ClientPlaySessionHandler.java | 4 +++- proxy/src/main/resources/default-velocity.toml | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) 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 32f5ca918..3df14c674 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -342,6 +342,10 @@ public class VelocityConfiguration implements ProxyConfig { return advanced.isShowPingRequests(); } + public boolean isLogCommandExecutions() { + return advanced.isLogCommandExecutions(); + } + @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -577,6 +581,7 @@ public class VelocityConfiguration implements ProxyConfig { private boolean tcpFastOpen = false; private boolean bungeePluginMessageChannel = true; private boolean showPingRequests = false; + private boolean logCommandExecutions = false; private Advanced() { } @@ -592,6 +597,7 @@ public class VelocityConfiguration implements ProxyConfig { this.tcpFastOpen = config.getOrElse("tcp-fast-open", false); this.bungeePluginMessageChannel = config.getOrElse("bungee-plugin-message-channel", true); this.showPingRequests = config.getOrElse("show-ping-requests", false); + this.logCommandExecutions = config.getOrElse("log-command-executions", false); } } @@ -631,6 +637,10 @@ public class VelocityConfiguration implements ProxyConfig { return showPingRequests; } + public boolean isLogCommandExecutions() { + return logCommandExecutions; + } + @Override public String toString() { return "Advanced{" @@ -643,6 +653,7 @@ public class VelocityConfiguration implements ProxyConfig { + ", tcpFastOpen=" + tcpFastOpen + ", bungeePluginMessageChannel=" + bungeePluginMessageChannel + ", showPingRequests=" + showPingRequests + + ", logCommandExecutions=" + logCommandExecutions + '}'; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 87b0e849b..b58ebf1be 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -130,7 +130,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { .thenComposeAsync(event -> processCommandExecuteResult(originalCommand, event.getResult())) .whenCompleteAsync((ignored, throwable) -> { - logger.info("{} -> executed command /{}", player.getUsername(), originalCommand); + if (server.getConfiguration().isLogCommandExecutions()) { + logger.info("{} -> executed command /{}", player.getUsername(), originalCommand); + } }) .exceptionally(e -> { logger.info("Exception occurred while running command for {}", diff --git a/proxy/src/main/resources/default-velocity.toml b/proxy/src/main/resources/default-velocity.toml index a83ddba94..139adec76 100644 --- a/proxy/src/main/resources/default-velocity.toml +++ b/proxy/src/main/resources/default-velocity.toml @@ -117,6 +117,9 @@ bungee-plugin-message-channel = true # Shows ping requests to the proxy from clients. show-ping-requests = false +# Enables the logging of commands +log-command-executions = false + [query] # Whether to enable responding to GameSpy 4 query responses or not. enabled = false