mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-03 17:29:56 +01:00
27c7749f42
- Re-removes Bukkit#getServerName - This was (hopefully?) only added back for Timings v2. It should be kept in that scope. - Intend to let PlayerViewDistance API slip. Given the scope of the changes in this area it seems best to let this slip past initial release. It can be re-added when there is additional time to focus on it and the changed systems it relies on. If it is fixed prior to release this is implemented as a single shim patch that can be dropped.
82 lines
3.7 KiB
Diff
82 lines
3.7 KiB
Diff
From 1e27d6d336f262e46c0b8eeaaab92d8d3d71b4ae Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Fri, 16 Nov 2018 23:08:50 -0500
|
|
Subject: [PATCH] Book Size Limits
|
|
|
|
Puts some limits on the size of books.
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
index a79cba50e..e5e41c662 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
@@ -375,4 +375,11 @@ public class PaperConfig {
|
|
velocitySecretKey = secret.getBytes(StandardCharsets.UTF_8);
|
|
}
|
|
}
|
|
+
|
|
+ public static int maxBookPageSize = 2560;
|
|
+ public static double maxBookTotalSizeMultiplier = 0.98D;
|
|
+ private static void maxBookSize() {
|
|
+ maxBookPageSize = getInt("settings.book-size.page-max", maxBookPageSize);
|
|
+ maxBookTotalSizeMultiplier = getDouble("settings.book-size.total-multiplier", maxBookTotalSizeMultiplier);
|
|
+ }
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index e7d3a5479..6096f309b 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -14,6 +14,7 @@ import java.util.Iterator;
|
|
import java.util.Optional;
|
|
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;
|
|
@@ -783,6 +784,42 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
|
|
@Override
|
|
public void a(PacketPlayInBEdit packetplayinbedit) {
|
|
+ // Paper start
|
|
+ ItemStack testStack = packetplayinbedit.b();
|
|
+ if (!server.isPrimaryThread() && !testStack.isEmpty() && testStack.getTag() != null) {
|
|
+ NBTTagList pageList = testStack.getTag().getList("pages", 8);
|
|
+ long byteTotal = 0;
|
|
+ int maxBookPageSize = com.destroystokyo.paper.PaperConfig.maxBookPageSize;
|
|
+ double multiplier = Math.max(0.3D, Math.min(1D, com.destroystokyo.paper.PaperConfig.maxBookTotalSizeMultiplier));
|
|
+ long byteAllowed = maxBookPageSize;
|
|
+ for (int i = 0; i < pageList.size(); ++i) {
|
|
+ String testString = pageList.getString(i);
|
|
+ int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
|
|
+ byteTotal += byteLength;
|
|
+ int length = testString.length();
|
|
+ int multibytes = 0;
|
|
+ if (byteLength != length) {
|
|
+ for (char c : testString.toCharArray()) {
|
|
+ if (c > 127) {
|
|
+ multibytes++;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ byteAllowed += (maxBookPageSize * Math.min(1, Math.max(0.1D, (double) length / 255D))) * multiplier;
|
|
+
|
|
+ if (multibytes > 1) {
|
|
+ // penalize MB
|
|
+ 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
|
|
// CraftBukkit start
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinbedit, this, this.player.getWorldServer());
|
|
if (this.lastBookTick + 20 > MinecraftServer.currentTick) {
|
|
--
|
|
2.21.0
|
|
|