Stop creating a thread for each auth request

This commit is contained in:
themode 2020-12-28 00:18:25 +01:00
parent 28c5e39f8b
commit 5975f8d838

View File

@ -15,12 +15,10 @@ import org.jetbrains.annotations.NotNull;
import javax.crypto.SecretKey;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.CompletableFuture;
public class EncryptionResponsePacket implements ClientPreplayPacket {
private final static String THREAD_NAME = "Mojang Auth Thread";
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
private byte[] sharedSecret;
private byte[] verifyToken;
@ -33,9 +31,7 @@ public class EncryptionResponsePacket implements ClientPreplayPacket {
}
final NettyPlayerConnection nettyConnection = (NettyPlayerConnection) connection;
new Thread(THREAD_NAME + " #" + UNIQUE_THREAD_ID.incrementAndGet()) {
public void run() {
CompletableFuture.runAsync(() -> {
try {
final String loginUsername = nettyConnection.getLoginUsername();
if (!Arrays.equals(nettyConnection.getNonce(), getNonce())) {
@ -63,8 +59,7 @@ public class EncryptionResponsePacket implements ClientPreplayPacket {
} catch (AuthenticationUnavailableException e) {
e.printStackTrace();
}
}
}.start();
});
}
@Override