mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Book Size Limits
Puts some limits on the size of books.
This commit is contained in:
parent
3ee33decb8
commit
01d23876a6
1 changed files with 57 additions and 0 deletions
57
Spigot-Server-Patches/Book-Size-Limits.patch
Normal file
57
Spigot-Server-Patches/Book-Size-Limits.patch
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
From 0000000000000000000000000000000000000000 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 bc74ea2f09..ea18ba5880 100644
|
||||||
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
||||||
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
||||||
|
@@ -0,0 +0,0 @@ public class PaperConfig {
|
||||||
|
velocitySecretKey = secret.getBytes(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ public static int maxBookPageSize = 640;
|
||||||
|
+ public static double maxBookTotalSizeMultiplier = 0.9D;
|
||||||
|
+ 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 3427e95e60..c4136640d2 100644
|
||||||
|
--- a/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 {
|
||||||
|
}
|
||||||
|
|
||||||
|
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().length;
|
||||||
|
+ 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;
|
||||||
|
+ }
|
||||||
|
+ byteAllowed += (maxBookPageSize * multiplier);
|
||||||
|
+ multiplier *= multiplier;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ // Paper end
|
||||||
|
// CraftBukkit start
|
||||||
|
PlayerConnectionUtils.ensureMainThread(packetplayinbedit, this, this.player.getWorldServer());
|
||||||
|
if (this.lastBookTick + 20 > MinecraftServer.currentTick) {
|
||||||
|
--
|
Loading…
Reference in a new issue