Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Handle player login thread in pool #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions Spigot-Server-Patches/0085-Handle-player-login-thread-in-pool.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
From a704613a1d0079fd9508d8bd3017d4f86a782570 Mon Sep 17 00:00:00 2001
From: caoli5288 <[email protected]>
Date: Fri, 7 Aug 2015 12:47:53 +0800
Subject: [PATCH] Handle player login thread in pool


diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
index bd254de..77dbe23 100644
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
@@ -4,7 +4,16 @@ import java.security.PrivateKey;
import java.util.Arrays;
import java.util.Random;
import java.util.UUID;
-import java.util.concurrent.atomic.AtomicInteger;
+// PaperSpigot start
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+/* import java.util.concurrent.atomic.AtomicInteger; */
+// PaperSpigot end
+
+
import javax.crypto.SecretKey;

import net.minecraft.util.com.google.common.base.Charsets;
@@ -13,12 +22,12 @@ import net.minecraft.util.com.mojang.authlib.properties.Property;
import net.minecraft.util.io.netty.util.concurrent.Future;
import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.util.org.apache.commons.lang3.Validate;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class LoginListener implements PacketLoginInListener {

- private static final AtomicInteger b = new AtomicInteger(0);
private static final Logger c = LogManager.getLogger();
private static final Random random = new Random();
private final byte[] e = new byte[4];
@@ -30,6 +39,14 @@ public class LoginListener implements PacketLoginInListener {
private String j;
private SecretKey loginKey;
public String hostname = ""; // CraftBukkit - add field
+
+ // PaperSpigot start
+ private static final ExecutorService POOL = new ThreadPoolExecutor(2,
+ Runtime.getRuntime().availableProcessors() * 2,
+ 60, TimeUnit.SECONDS,
+ new LinkedBlockingQueue(),
+ new ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").build());
+ // PaperSpigot end

public LoginListener(MinecraftServer minecraftserver, NetworkManager networkmanager) {
this.g = EnumProtocolState.HELLO;
@@ -140,7 +157,10 @@ public class LoginListener implements PacketLoginInListener {
this.g = EnumProtocolState.KEY;
this.networkManager.handle(new PacketLoginOutEncryptionBegin(this.j, this.server.K().getPublic(), this.e), new GenericFutureListener[0]);
} else {
- (new ThreadPlayerLookupUUID(this, "User Authenticator #" + b.incrementAndGet())).start(); // Spigot
+ // PaperSpigot start
+ // (new ThreadPlayerLookupUUID(this, "User Authenticator #" + b.incrementAndGet())).start(); // Spigot
+ POOL.execute(new ThreadPlayerLookupUUID(this)); // PaperSpigot
+ // PaperSpigot end
}
}

@@ -154,7 +174,10 @@ public class LoginListener implements PacketLoginInListener {
this.loginKey = packetlogininencryptionbegin.a(privatekey);
this.g = EnumProtocolState.AUTHENTICATING;
this.networkManager.a(this.loginKey);
- (new ThreadPlayerLookupUUID(this, "User Authenticator #" + b.incrementAndGet())).start();
+ // PaperSpigot start
+ // (new ThreadPlayerLookupUUID(this, "User Authenticator #" + b.incrementAndGet())).start();
+ POOL.execute(new ThreadPlayerLookupUUID(this));
+ // PaperSpigot end
}
}

@@ -191,4 +214,4 @@ public class LoginListener implements PacketLoginInListener {
static EnumProtocolState a(LoginListener loginlistener, EnumProtocolState enumprotocolstate) {
return loginlistener.g = enumprotocolstate;
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java b/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java
index 1b2620c..689910d 100644
--- a/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java
+++ b/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java
@@ -12,14 +12,21 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerPreLoginEvent;
// CraftBukkit end

-class ThreadPlayerLookupUUID extends Thread {
+// PaperSpigot start
+// class ThreadPlayerLookupUUID extends Thread {
+class ThreadPlayerLookupUUID implements Runnable {
+// PaperSpigot end

final LoginListener a;

- ThreadPlayerLookupUUID(LoginListener loginlistener, String s) {
- super(s);
+ // PaperSpigot start
+ // ThreadPlayerLookupUUID(LoginListener loginlistener, String s) {
+ // super(s);
+ // }
+ ThreadPlayerLookupUUID(LoginListener loginlistener) {
this.a = loginlistener;
}
+ // PaperSpigot end

public void run() {
GameProfile gameprofile = LoginListener.a(this.a);
@@ -106,4 +113,4 @@ class ThreadPlayerLookupUUID extends Thread {
LoginListener.e().info("UUID of player " + LoginListener.a(this.a).getName() + " is " + LoginListener.a(this.a).getId());
LoginListener.a(this.a, EnumProtocolState.READY_TO_ACCEPT);
}
-}
+}
\ No newline at end of file
--
2.4.3