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