Skip to content

Commit

Permalink
Virtual thread for User Authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Jan 1, 2025
1 parent 9495a5b commit fd881f5
Show file tree
Hide file tree
Showing 76 changed files with 48 additions and 2 deletions.
46 changes: 46 additions & 0 deletions patches/server/0063-Virtual-thread-for-User-Authenticator.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <[email protected]>
Date: Tue, 31 Dec 2024 00:00:00 -0800
Subject: [PATCH] Virtual thread for User Authenticator


diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 0afd30a9a4eb7de7e58e1b91342cca51c771f300..e442fd1b80dd57d4420cab4da69ec3598ffc22d3 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -76,7 +76,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
// CraftBukkit end
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
static final Logger LOGGER = LogUtils.getLogger();
- private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads
+ private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setThreadFactory(org.dreeam.leaf.config.modules.opt.VT4UserAuthenticator.enabled ? Thread.ofVirtual().factory() : java.util.concurrent.Executors.defaultThreadFactory()).setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads // Leaf - Virtual thread for User Authenticator
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
private final byte[] challenge;
final MinecraftServer server;
diff --git a/src/main/java/org/dreeam/leaf/config/modules/opt/VT4UserAuthenticator.java b/src/main/java/org/dreeam/leaf/config/modules/opt/VT4UserAuthenticator.java
new file mode 100644
index 0000000000000000000000000000000000000000..751549c6ddacc40b64dc230064f5eeb6b1a2efca
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/VT4UserAuthenticator.java
@@ -0,0 +1,21 @@
+package org.dreeam.leaf.config.modules.opt;
+
+import org.dreeam.leaf.config.ConfigModules;
+import org.dreeam.leaf.config.EnumConfigCategory;
+
+public class VT4UserAuthenticator extends ConfigModules {
+
+ public String getBasePath() {
+ return EnumConfigCategory.PERF.getBaseKeyName();
+ }
+
+ public static boolean enabled = true;
+
+ @Override
+ public void onLoaded() {
+ enabled = config.getBoolean(getBasePath() + ".use-virtual-thread-for-user-authenticator", enabled,
+ config.pickStringRegionBased(
+ "Use the new Virtual Thread introduced in JDK 21 for User Authenticator.",
+ "是否为用户验证器使用虚拟线程."));
+ }
+}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ index 1e3dc0cf613a621bbf0873bcffb01c69aa119e92..a42eb55c2f26a0048ea688655c5bb1df
implementation("org.jline:jline-terminal-ffm:3.27.1") // use ffm on java 22+
implementation("org.jline:jline-terminal-jni:3.27.1") // fall back to jni on java 21
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 0afd30a9a4eb7de7e58e1b91342cca51c771f300..2e0461ae8eb5531a01a97d44db3e5387ded6e1fb 100644
index e442fd1b80dd57d4420cab4da69ec3598ffc22d3..52fdc27ae63c2524e316620d905af7cd97112482 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -92,6 +92,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ index 252aef3ffe0fecd47ebea1ed7df48e14fa873eb9..5b4599927effca11293b367c5bac4541
RandomSource fork();

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 3665fa73fb0bd788335a8bbbdaa8f5aba0b45d8b..4543116afc9a86961377b9e2d20868c9e73c698d 100644
index ee64667e5c33afd68d4458bffd858c66db4c1421..8ac2b3a17d1a9df6695c8034b71544704be23036 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -184,7 +184,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit fd881f5

Please sign in to comment.