Skip to content

Commit

Permalink
Add pipeline events
Browse files Browse the repository at this point in the history
  • Loading branch information
astei committed Apr 19, 2023
1 parent 80720b2 commit 5896b60
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.velocitypowered.natives.compression.VelocityCompressor;
import com.velocitypowered.natives.util.Natives;
import io.netty.channel.Channel;
import me.steinborn.krypton.mod.shared.misc.KryptonPipelineEvent;
import me.steinborn.krypton.mod.shared.network.compression.MinecraftCompressDecoder;
import me.steinborn.krypton.mod.shared.network.compression.MinecraftCompressEncoder;
import net.minecraft.network.ClientConnection;
Expand Down Expand Up @@ -46,6 +47,8 @@ public void setCompressionThreshold(int compressionThreshold, boolean validate,
if (isKryptonOrVanillaCompressor(this.channel.pipeline().get("compress"))) {
this.channel.pipeline().remove("compress");
}

this.channel.pipeline().fireUserEventTriggered(KryptonPipelineEvent.COMPRESSION_DISABLED);
} else {
MinecraftCompressDecoder decoder = (MinecraftCompressDecoder) channel.pipeline()
.get("decompress");
Expand All @@ -54,6 +57,8 @@ public void setCompressionThreshold(int compressionThreshold, boolean validate,
if (decoder != null && encoder != null) {
decoder.setThreshold(compressionThreshold);
encoder.setThreshold(compressionThreshold);

this.channel.pipeline().fireUserEventTriggered(KryptonPipelineEvent.COMPRESSION_THRESHOLD_UPDATED);
} else {
VelocityCompressor compressor = Natives.compress.get().create(4);

Expand All @@ -62,9 +67,10 @@ public void setCompressionThreshold(int compressionThreshold, boolean validate,

channel.pipeline().addBefore("decoder", "decompress", decoder);
channel.pipeline().addBefore("encoder", "compress", encoder);

this.channel.pipeline().fireUserEventTriggered(KryptonPipelineEvent.COMPRESSION_ENABLED);
}
}

this.handleViaCompression();

ci.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.velocitypowered.natives.encryption.VelocityCipher;
import com.velocitypowered.natives.util.Natives;
import io.netty.channel.Channel;
import me.steinborn.krypton.mod.shared.misc.KryptonPipelineEvent;
import me.steinborn.krypton.mod.shared.network.ClientConnectionEncryptionExtension;
import me.steinborn.krypton.mod.shared.network.pipeline.MinecraftCipherDecoder;
import me.steinborn.krypton.mod.shared.network.pipeline.MinecraftCipherEncoder;
Expand All @@ -27,6 +28,8 @@ public void setupEncryption(SecretKey key) throws GeneralSecurityException {
this.encrypted = true;
this.channel.pipeline().addBefore("splitter", "decrypt", new MinecraftCipherDecoder(decryption));
this.channel.pipeline().addBefore("prepender", "encrypt", new MinecraftCipherEncoder(encryption));

this.channel.pipeline().fireUserEventTriggered(KryptonPipelineEvent.ENCRYPTION_ENABLED);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.steinborn.krypton.mod.shared.misc;

public enum KryptonPipelineEvent {
COMPRESSION_ENABLED,
COMPRESSION_THRESHOLD_UPDATED,
COMPRESSION_DISABLED,
ENCRYPTION_ENABLED,
}

0 comments on commit 5896b60

Please sign in to comment.