mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
cleanup some netty client code
This commit is contained in:
parent
74e52823f5
commit
406cbf3d59
@ -84,9 +84,9 @@ class NettyClient(
|
|||||||
|
|
||||||
override fun setupEncryption(encrypt: Cipher, decrypt: Cipher) {
|
override fun setupEncryption(encrypt: Cipher, decrypt: Cipher) {
|
||||||
if (encrypted) throw IllegalStateException("Already encrypted!")
|
if (encrypted) throw IllegalStateException("Already encrypted!")
|
||||||
val channel = requireChannel()
|
val pipeline = requireChannel().pipeline()
|
||||||
channel.pipeline().addBefore(LengthEncoder.NAME, PacketEncryptor.NAME, PacketEncryptor(encrypt))
|
pipeline.addBefore(LengthEncoder.NAME, PacketEncryptor.NAME, PacketEncryptor(encrypt))
|
||||||
channel.pipeline().addBefore(LengthDecoder.NAME, PacketDecryptor.NAME, PacketDecryptor(decrypt))
|
pipeline.addBefore(LengthDecoder.NAME, PacketDecryptor.NAME, PacketDecryptor(decrypt))
|
||||||
encrypted = true
|
encrypted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,23 +95,19 @@ class NettyClient(
|
|||||||
val pipeline = channel.pipeline()
|
val pipeline = channel.pipeline()
|
||||||
if (threshold < 0) {
|
if (threshold < 0) {
|
||||||
// disable
|
// disable
|
||||||
if (pipeline.get(PacketDeflater.NAME) != null) {
|
pipeline.remove(PacketDeflater.NAME)
|
||||||
channel.pipeline().remove(PacketDeflater.NAME)
|
pipeline.remove(PacketInflater.NAME)
|
||||||
}
|
|
||||||
if (pipeline.get(PacketInflater.NAME) != null) {
|
|
||||||
channel.pipeline().remove(PacketInflater.NAME)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// enable or update
|
// enable or update
|
||||||
val inflater = channel.pipeline()[PacketInflater.NAME]?.nullCast<PacketInflater>()
|
val inflater = pipeline[PacketInflater.NAME]?.nullCast<PacketInflater>()
|
||||||
if (inflater == null) {
|
if (inflater == null) {
|
||||||
channel.pipeline().addAfter(LengthDecoder.NAME, PacketInflater.NAME, PacketInflater(connection.version!!.maxPacketLength))
|
pipeline.addAfter(LengthDecoder.NAME, PacketInflater.NAME, PacketInflater(connection.version!!.maxPacketLength))
|
||||||
}
|
}
|
||||||
val deflater = channel.pipeline()[PacketDeflater.NAME]?.nullCast<PacketDeflater>()
|
val deflater = pipeline[PacketDeflater.NAME]?.nullCast<PacketDeflater>()
|
||||||
if (deflater != null) {
|
if (deflater == null) {
|
||||||
deflater.threshold = threshold
|
pipeline.addAfter(LengthEncoder.NAME, PacketDeflater.NAME, PacketDeflater(threshold))
|
||||||
} else {
|
} else {
|
||||||
channel.pipeline().addAfter(LengthEncoder.NAME, PacketDeflater.NAME, PacketDeflater(threshold))
|
deflater.threshold = threshold
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user