From 15c4f72cf03198b57a360539978a36461732fd9d Mon Sep 17 00:00:00 2001 From: Newwind Date: Thu, 25 Jul 2024 13:00:37 +0200 Subject: [PATCH] Make interaction leniency distance configurable The server validates incoming interaction packets by ensuring the player sending them is inside their interaction range. For this, the server adds a magic value, by default 1.0, to the original interaction range to account for latency issues. This value however may be too low in high latency environments. The patch exposes a new configuration option to configure said value. --- .../ServerGamePacketListenerImpl.java.patch | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch index 559f08239d..2a63fb1114 100644 --- a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch @@ -1558,12 +1558,10 @@ } return optional; -@@ -1564,8 +2394,119 @@ - } - +@@ -1566,6 +2396,117 @@ return false; -+ } -+ + } + + // CraftBukkit start - add method + public void chat(String s, PlayerChatMessage original, boolean async) { + if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { @@ -1656,8 +1654,8 @@ + this.server.console.sendMessage(s); + } + } - } - ++ } ++ + @Deprecated // Paper + public void handleCommand(String s) { // Paper - private -> public + // Paper start - Remove all this old duplicated logic @@ -1842,10 +1840,12 @@ this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params)); this.addPendingMessage(message); } -@@ -1703,6 +2740,18 @@ - return this.connection.getRemoteAddress(); - } +@@ -1701,7 +2738,19 @@ + public SocketAddress getRemoteAddress() { + return this.connection.getRemoteAddress(); ++ } ++ + // Spigot Start + public SocketAddress getRawAddress() + { @@ -1855,12 +1855,11 @@ + } + // Paper end - Unix domain socket support + return this.connection.channel.remoteAddress(); -+ } + } + // Spigot End -+ + public void switchToConfig() { this.waitingForSwitchToConfig = true; - this.removePlayerFromWorld(); @@ -1718,9 +2767,17 @@ @Override public void handleInteract(ServerboundInteractPacket packet) { @@ -1879,9 +1878,12 @@ this.player.resetLastActionTime(); this.player.setShiftKeyDown(packet.isUsingSecondaryAction()); -@@ -1733,20 +2790,59 @@ +@@ -1731,22 +2788,61 @@ - if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) { + AABB axisalignedbb = entity.getBoundingBox(); + +- if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) { ++ if (this.player.canInteractWithEntity(axisalignedbb, io.papermc.paper.configuration.GlobalConfiguration.get().misc.clientInteractionLeniencyDistance.or(3.0D))) { // Paper - configurable lenience value for interact range packet.dispatch(new ServerboundInteractPacket.Handler() { - private void performInteraction(InteractionHand hand, ServerGamePacketListenerImpl.EntityInteraction action) { - ItemStack itemstack = ServerGamePacketListenerImpl.this.player.getItemInHand(hand);