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 aba1069d29389c07012ba9365fa6ae1d88fdf73c..23c81b3a96056f0b755735ad75fc81af9b046475 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), net.minecraft.network.PacketSendListener.thenRun(() -> networkmanager.disconnect(error))); diff --git a/src/main/java/net/minecraft/server/network/LegacyQueryHandler.java b/src/main/java/net/minecraft/server/network/LegacyQueryHandler.java index 21393ad40095a4049e5b6871169b2db7aa92d13c..e6553b936dac1eb25a310d1a33acb0b1a5e646d2 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 e5e2f763d9b4b955df79ea0c4c79565be1fe59f0..2beddfc0532c3835d50724551e3d46cb0d7d2290 100644 --- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java +++ b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java @@ -207,7 +207,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 471e21f9e1f3ad6302e647d26a44b521fece223b..69498183a7637cd2dbb859c670e661f8722a090f 100644 --- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java @@ -206,7 +206,10 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, } 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 } @Override diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java index 399d5c1147b1cdacf571aa3cd5840af6f6e55374..299676157b16ed9e93f5cf9804ab75514b694f49 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 { String s1 = "local"; if (connection.getRemoteAddress() != null) { - s1 = connection.getRemoteAddress().toString(); + s1 = io.papermc.paper.configuration.GlobalConfiguration.get().logging.logPlayerIpAddresses ? connection.getRemoteAddress().toString() : ""; // Paper } // Spigot start - spawn location event