mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
optimize LinearPalette; remove useless log4shell patch
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Sat, 1 Feb 2025 19:28:34 +0300
|
||||
Subject: [PATCH] Block Log4Shell exploit
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index a8b2c19cc9803058b421b07c739166afdf291e47..3a27b544da8227511b546c55963e7112df0a9f63 100644
|
||||
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -2515,6 +2515,7 @@ public class ServerGamePacketListenerImpl
|
||||
}
|
||||
|
||||
private void tryHandleChat(String message, Runnable handler, boolean sync) { // CraftBukkit
|
||||
+ if (ServerGamePacketListenerImpl.isLog4ShellExploit(message)) return; // DivineMC - Block Log4Shell exploit
|
||||
if (isChatMessageIllegal(message)) {
|
||||
this.disconnectAsync(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper - add proper async disconnect
|
||||
} else if (this.player.isRemoved() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { // CraftBukkit - dead men tell no tales
|
||||
@@ -2547,6 +2548,15 @@ public class ServerGamePacketListenerImpl
|
||||
}
|
||||
}
|
||||
|
||||
+ // DivineMC start - Block Log4Shell exploit
|
||||
+ public static boolean isLog4ShellExploit(String message) {
|
||||
+ java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(".*\\$\\{[^}]*}.*");
|
||||
+ java.util.regex.Matcher matcher = pattern.matcher(message);
|
||||
+
|
||||
+ return matcher.find();
|
||||
+ }
|
||||
+ // DivineMC end - Block Log4Shell exploit
|
||||
+
|
||||
public static boolean isChatMessageIllegal(String message) {
|
||||
for (int i = 0; i < message.length(); i++) {
|
||||
if (!StringUtil.isAllowedChatCharacter(message.charAt(i))) {
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Option to disable disconnect.spam
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index 3a27b544da8227511b546c55963e7112df0a9f63..d5ed595bce6846590230634f8887e1f8e9b0a062 100644
|
||||
index a8b2c19cc9803058b421b07c739166afdf291e47..8f4bca6a99b35e869e34f0fa216c13189cd7b384 100644
|
||||
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -844,7 +844,7 @@ public class ServerGamePacketListenerImpl
|
||||
@@ -34,7 +34,7 @@ index 3a27b544da8227511b546c55963e7112df0a9f63..d5ed595bce6846590230634f8887e1f8
|
||||
&& parseResults.getExceptions().values().stream().anyMatch(e -> e instanceof io.papermc.paper.brigadier.TagParseCommandSyntaxException)) {
|
||||
this.disconnect(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM);
|
||||
return;
|
||||
@@ -2639,6 +2640,7 @@ public class ServerGamePacketListenerImpl
|
||||
@@ -2629,6 +2630,7 @@ public class ServerGamePacketListenerImpl
|
||||
// this.chatSpamThrottler.increment();
|
||||
if (!this.chatSpamThrottler.isIncrementAndUnderThreshold()
|
||||
// CraftBukkit end
|
||||
@@ -42,7 +42,7 @@ index 3a27b544da8227511b546c55963e7112df0a9f63..d5ed595bce6846590230634f8887e1f8
|
||||
&& !this.server.getPlayerList().isOp(this.player.getGameProfile())
|
||||
&& !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
|
||||
this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - kick event cause & add proper async disconnect
|
||||
@@ -3396,7 +3398,7 @@ public class ServerGamePacketListenerImpl
|
||||
@@ -3386,7 +3388,7 @@ public class ServerGamePacketListenerImpl
|
||||
public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) {
|
||||
// Paper start - auto recipe limit
|
||||
if (!org.bukkit.Bukkit.isPrimaryThread()) {
|
||||
@@ -6,7 +6,7 @@ Subject: [PATCH] Option to allow weird movement and disable teleporting
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index d5ed595bce6846590230634f8887e1f8e9b0a062..798482a332c4be045d5c409a20cd120c12b3460e 100644
|
||||
index 8f4bca6a99b35e869e34f0fa216c13189cd7b384..3ba558634558b4524245a2b29786237f5e38ef42 100644
|
||||
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -607,7 +607,7 @@ public class ServerGamePacketListenerImpl
|
||||
@@ -0,0 +1,63 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Mon, 7 Jul 2025 04:21:38 +0300
|
||||
Subject: [PATCH] Small optimization to LinearPalette
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/level/chunk/LinearPalette.java b/net/minecraft/world/level/chunk/LinearPalette.java
|
||||
index 2073f6ff41aa570102621d183ee890b076267d54..93cb815032fada7b8abc7301a7005114eea8384d 100644
|
||||
--- a/net/minecraft/world/level/chunk/LinearPalette.java
|
||||
+++ b/net/minecraft/world/level/chunk/LinearPalette.java
|
||||
@@ -12,7 +12,7 @@ public class LinearPalette<T> implements Palette<T>, ca.spottedleaf.moonrise.pat
|
||||
private final T[] values;
|
||||
private final PaletteResize<T> resizeHandler;
|
||||
private final int bits;
|
||||
- private int size;
|
||||
+ private volatile int size; // DivineMC - Small optimization to LinearPalette
|
||||
|
||||
// Paper start - optimise palette reads
|
||||
@Override
|
||||
@@ -49,11 +49,14 @@ public class LinearPalette<T> implements Palette<T>, ca.spottedleaf.moonrise.pat
|
||||
|
||||
@Override
|
||||
public int idFor(T state) {
|
||||
- for (int i = 0; i < this.size; i++) {
|
||||
- if (this.values[i] == state) {
|
||||
+ // DivineMC start - Small optimization to LinearPalette
|
||||
+ final T[] values = this.values;
|
||||
+ for (int i = 0; i < values.length; i++) {
|
||||
+ if (values[i] == state) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+ // DivineMC end - Small optimization to LinearPalette
|
||||
|
||||
int ix = this.size;
|
||||
if (ix < this.values.length) {
|
||||
@@ -67,17 +70,23 @@ public class LinearPalette<T> implements Palette<T>, ca.spottedleaf.moonrise.pat
|
||||
|
||||
@Override
|
||||
public boolean maybeHas(Predicate<T> filter) {
|
||||
- for (int i = 0; i < this.size; i++) {
|
||||
- if (filter.test(this.values[i])) {
|
||||
+ // DivineMC start - Small optimization to LinearPalette
|
||||
+ final T[] values = this.values;
|
||||
+ final int currentSize = this.size;
|
||||
+
|
||||
+ for (int i = 0; i < currentSize; i++) {
|
||||
+ T value = values[i];
|
||||
+ if (value != null && filter.test(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+ // DivineMC end - Small optimization to LinearPalette
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
- public T valueFor(int id) {
|
||||
+ public synchronized T valueFor(int id) { // DivineMC - Small optimization to LinearPalette
|
||||
if (id >= 0 && id < this.size) {
|
||||
return this.values[id];
|
||||
} else {
|
||||
Reference in New Issue
Block a user