No volatile read for compression/encryption

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-26 17:02:05 +02:00
parent f07ab21d3e
commit 236683c986

View File

@ -52,8 +52,8 @@ public class PlayerSocketConnection extends PlayerConnection {
private final SocketChannel channel;
private SocketAddress remoteAddress;
private volatile boolean encrypted = false;
private volatile boolean compressed = false;
private boolean encrypted = false;
private boolean compressed = false;
//Could be null. Only used for Mojang Auth
private byte[] nonce = new byte[4];
@ -174,10 +174,12 @@ public class PlayerSocketConnection extends PlayerConnection {
*/
public void setEncryptionKey(@NotNull SecretKey secretKey) {
Check.stateCondition(encrypted, "Encryption is already enabled!");
synchronized (bufferLock) {
this.decryptCipher = MojangCrypt.getCipher(2, secretKey);
this.encryptCipher = MojangCrypt.getCipher(1, secretKey);
this.encrypted = true;
}
}
/**
* Enables compression and add a new codec to the pipeline.
@ -189,8 +191,10 @@ public class PlayerSocketConnection extends PlayerConnection {
final int threshold = MinecraftServer.getCompressionThreshold();
Check.stateCondition(threshold == 0, "Compression cannot be enabled because the threshold is equal to 0");
writeAndFlush(new SetCompressionPacket(threshold));
synchronized (bufferLock) {
this.compressed = true;
}
}
/**
* Writes a packet to the connection channel.