From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Tue, 5 Oct 2021 20:04:21 +0200 Subject: [PATCH] Add config option for logging player ip addresses diff --git a/src/main/java/net/minecraft/network/protocol/PacketUtils.java b/src/main/java/net/minecraft/network/protocol/PacketUtils.java index c8012de68b997d6270ba4a5d79bc93c09ff4354f..1429f938c36d5a3a33e71837f440b2303d60cfe7 100644 --- a/src/main/java/net/minecraft/network/protocol/PacketUtils.java +++ b/src/main/java/net/minecraft/network/protocol/PacketUtils.java @@ -51,10 +51,11 @@ public class PacketUtils { packet.handle(listener); } catch (Exception exception) { net.minecraft.network.Connection networkmanager = listener.getConnection(); + String playerIP = io.papermc.paper.configuration.GlobalConfiguration.get().logging.logPlayerIpAddresses ? String.valueOf(networkmanager.getRemoteAddress()) : ""; // Paper if (networkmanager.getPlayer() != null) { - LOGGER.error("Error whilst processing packet {} for {}[{}]", packet, networkmanager.getPlayer().getScoreboardName(), networkmanager.getRemoteAddress(), exception); + LOGGER.error("Error whilst processing packet {} for {}[{}]", packet, networkmanager.getPlayer().getScoreboardName(), playerIP, exception); // Paper } else { - LOGGER.error("Error whilst processing packet {} for connection from {}", packet, networkmanager.getRemoteAddress(), exception); + LOGGER.error("Error whilst processing packet {} for connection from {}", packet, playerIP, exception); // Paper } net.minecraft.network.chat.Component error = net.minecraft.network.chat.Component.literal("Packet processing error"); networkmanager.send(new net.minecraft.network.protocol.game.ClientboundDisconnectPacket(error), (future) -> { diff --git a/src/main/java/net/minecraft/server/network/LegacyQueryHandler.java b/src/main/java/net/minecraft/server/network/LegacyQueryHandler.java index 37cd7b44559e5705b31296df87c94d2ab200138d..37e52ea9ab694b466358981bc2a3c99f28a70c7d 100644 --- a/src/main/java/net/minecraft/server/network/LegacyQueryHandler.java +++ b/src/main/java/net/minecraft/server/network/LegacyQueryHandler.java @@ -185,7 +185,7 @@ public class LegacyQueryHandler extends ChannelInboundHandlerAdapter { buf.release(); this.buf = null; - LOGGER.debug("Ping: (1.6) from {}", ctx.channel().remoteAddress()); + LOGGER.debug("Ping: (1.6) from {}", io.papermc.paper.configuration.GlobalConfiguration.get().logging.logPlayerIpAddresses ? ctx.channel().remoteAddress() : ""); // Paper InetSocketAddress virtualHost = com.destroystokyo.paper.network.PaperNetworkClient.prepareVirtualHost(host, port); com.destroystokyo.paper.event.server.PaperServerListPingEvent event = com.destroystokyo.paper.network.PaperLegacyStatusClient.processRequest( diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java index 2985271132c9ae822dcb0d7a7e6f0c268d1736cc..cfdbcd024de6ad0f9d4e83b2f912b36ef3299458 100644 --- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java +++ b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java @@ -206,7 +206,7 @@ public class ServerConnectionListener { throw new ReportedException(CrashReport.forThrowable(exception, "Ticking memory connection")); } - ServerConnectionListener.LOGGER.warn("Failed to handle packet for {}", networkmanager.getRemoteAddress(), exception); + ServerConnectionListener.LOGGER.warn("Failed to handle packet for {}", io.papermc.paper.configuration.GlobalConfiguration.get().logging.logPlayerIpAddresses ? String.valueOf(networkmanager.getRemoteAddress()) : "", exception); // Paper MutableComponent ichatmutablecomponent = Component.literal("Internal server error"); networkmanager.send(new ClientboundDisconnectPacket(ichatmutablecomponent), PacketSendListener.thenRun(() -> { diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java index 547abc18f1e03945977bd38947d9db5e201045c4..303981c9b873eee07052fbe607690d12074cd1d1 100644 --- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java @@ -241,7 +241,10 @@ public class ServerLoginPacketListenerImpl implements TickablePacketListener, Se } public String getUserName() { - return this.gameProfile != null ? this.gameProfile + " (" + this.connection.getRemoteAddress() + ")" : String.valueOf(this.connection.getRemoteAddress()); + // Paper start + String ip = io.papermc.paper.configuration.GlobalConfiguration.get().logging.logPlayerIpAddresses ? String.valueOf(this.connection.getRemoteAddress()) : ""; + return this.gameProfile != null ? this.gameProfile + " (" + ip + ")" : String.valueOf(ip); + // Paper end } @Nullable diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java index dda357b4f52030435c012f10b11f1ccb3f6688be..1548df4057b34fe6bad2c51fb5a77ce118b36566 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -241,7 +241,7 @@ public abstract class PlayerList { final String s1; if (connection.getRemoteAddress() != null) { - s1 = connection.getRemoteAddress().toString(); + s1 = io.papermc.paper.configuration.GlobalConfiguration.get().logging.logPlayerIpAddresses ? connection.getRemoteAddress().toString() : ""; // Paper } else { s1 = "local"; }