mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 12:42:05 -07:00
Address some issues with book limits (#1798)
The multibyte calculation has been fixed, now we actually work out which characters take more than a byte. Diminishing returns has been modified, previously the multiplier would zero itself out due to floating point limitations
This commit is contained in:
@@ -22,9 +22,18 @@ index fef899ae0..468aff713 100644
|
|||||||
+ }
|
+ }
|
||||||
}
|
}
|
||||||
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
index 7ae374085..bbdf729c3 100644
|
index cb6d1deb8..8d06b23ea 100644
|
||||||
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
|
@@ -0,0 +0,0 @@ import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
+
|
||||||
|
+import org.apache.commons.lang3.StringEscapeUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
@@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,24 +50,28 @@ index 7ae374085..bbdf729c3 100644
|
|||||||
+ String testString = pageList.getString(i);
|
+ String testString = pageList.getString(i);
|
||||||
+ int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
|
+ int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
|
||||||
+ byteTotal += byteLength;
|
+ byteTotal += byteLength;
|
||||||
+ if (byteTotal > byteAllowed) {
|
|
||||||
+ PlayerConnection.LOGGER.warn(this.player.getName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size());
|
|
||||||
+ minecraftServer.postToMainThread(() -> this.disconnect("Book too large!"));
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
+ int length = testString.length();
|
+ int length = testString.length();
|
||||||
+ int multibytes = byteLength == length ? byteLength : (int) Math.round((double) byteLength / (double) length);
|
+ int multibytes = 0;
|
||||||
+ for (int x = 1; x < multibytes; x++) {
|
+ if (byteLength != length) {
|
||||||
+ multiplier *= multiplier;
|
+ for (char c : testString.toCharArray()) {
|
||||||
|
+ if (c > 127) {
|
||||||
|
+ multibytes++;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ byteAllowed += (maxBookPageSize * Math.min(1, Math.max(0.1D, (double) length / 255D))) * multiplier;
|
+ byteAllowed += (maxBookPageSize * Math.min(1, Math.max(0.1D, (double) length / 255D))) * multiplier;
|
||||||
+ multiplier *= multiplier;
|
|
||||||
+
|
+
|
||||||
+ if (multibytes > 1) {
|
+ if (multibytes > 1) {
|
||||||
+ // penalize MB some more
|
+ // penalize MB
|
||||||
+ byteAllowed -= length;
|
+ byteAllowed -= multibytes;
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
|
+
|
||||||
|
+ if (byteTotal > byteAllowed) {
|
||||||
|
+ PlayerConnection.LOGGER.warn(this.player.getName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size());
|
||||||
|
+ minecraftServer.postToMainThread(() -> this.disconnect("Book too large!"));
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
@@ -10,7 +10,7 @@ it impossible to properly cancel the event or modify the book meta
|
|||||||
cancelled writing
|
cancelled writing
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
index 74c570615..9741d3b23 100644
|
index 8d06b23ea..a8a6e236e 100644
|
||||||
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
@@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
@@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
||||||
|
Reference in New Issue
Block a user