fix encryption

This commit is contained in:
Bixilon 2020-09-03 18:42:13 +02:00
parent 7697f027b4
commit ed6c339eb8
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -17,6 +17,7 @@ import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.packets.clientbound.interfaces.PacketCompressionInterface;
import de.bixilon.minosoft.protocol.packets.clientbound.login.PacketEncryptionRequest;
import de.bixilon.minosoft.protocol.packets.clientbound.login.PacketLoginSuccess;
import de.bixilon.minosoft.protocol.packets.serverbound.login.PacketEncryptionResponse;
import de.bixilon.minosoft.protocol.protocol.*;
@ -126,6 +127,8 @@ public class Network {
// enable encryption
secretKey = ((PacketEncryptionResponse) packet).getSecretKey();
enableEncryption(secretKey);
// wake up other thread
socketRThread.interrupt();
}
}
} catch (IOException | InterruptedException ignored) {
@ -208,6 +211,14 @@ public class Network {
connection.setConnectionState(ConnectionStates.PLAY);
} else if (packetInstance instanceof PacketCompressionInterface) {
compressionThreshold = ((PacketCompressionInterface) packetInstance).getThreshold();
} else if (packetInstance instanceof PacketEncryptionRequest) {
// wait until response is ready
connection.handle(packetInstance);
try {
Thread.sleep(Integer.MAX_VALUE);
} catch (InterruptedException ignored) {
}
continue;
}
connection.handle(packetInstance);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {