13
0
geforkt von Mirrors/Velocity

Add some internal injection points for the benefit of ViaVersion

See #524 for more details
Dieser Commit ist enthalten in:
Andrew Steinborn 2021-06-14 13:59:56 -04:00
Ursprung 93724b7b33
Commit c979c61155
2 geänderte Dateien mit 31 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -39,16 +39,19 @@ import com.velocitypowered.proxy.connection.client.StatusSessionHandler;
import com.velocitypowered.proxy.network.Connections; import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.VelocityConnectionEvent;
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftCompressorAndLengthEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCompressorAndLengthEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder;
import com.velocitypowered.proxy.util.except.QuietDecoderException; import com.velocitypowered.proxy.util.except.QuietDecoderException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
@ -355,6 +358,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
public void setProtocolVersion(ProtocolVersion protocolVersion) { public void setProtocolVersion(ProtocolVersion protocolVersion) {
ensureInEventLoop(); ensureInEventLoop();
boolean changed = this.protocolVersion != protocolVersion;
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
if (protocolVersion != ProtocolVersion.LEGACY) { if (protocolVersion != ProtocolVersion.LEGACY) {
this.channel.pipeline().get(MinecraftEncoder.class).setProtocolVersion(protocolVersion); this.channel.pipeline().get(MinecraftEncoder.class).setProtocolVersion(protocolVersion);
@ -364,6 +368,10 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
this.channel.pipeline().remove(MINECRAFT_ENCODER); this.channel.pipeline().remove(MINECRAFT_ENCODER);
this.channel.pipeline().remove(MINECRAFT_DECODER); this.channel.pipeline().remove(MINECRAFT_DECODER);
} }
if (changed) {
channel.pipeline().fireUserEventTriggered(VelocityConnectionEvent.PROTOCOL_VERSION_CHANGED);
}
} }
public @Nullable MinecraftSessionHandler getSessionHandler() { public @Nullable MinecraftSessionHandler getSessionHandler() {
@ -398,8 +406,14 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
ensureInEventLoop(); ensureInEventLoop();
if (threshold == -1) { if (threshold == -1) {
channel.pipeline().remove(COMPRESSION_DECODER); final ChannelHandler removedDecoder = channel.pipeline().remove(COMPRESSION_DECODER);
channel.pipeline().remove(COMPRESSION_ENCODER); final ChannelHandler removedEncoder = channel.pipeline().remove(COMPRESSION_ENCODER);
if (removedDecoder != null && removedEncoder != null) {
channel.pipeline().addBefore(MINECRAFT_DECODER, FRAME_ENCODER,
MinecraftVarintLengthEncoder.INSTANCE);
channel.pipeline().fireUserEventTriggered(VelocityConnectionEvent.COMPRESSION_DISABLED);
}
} else { } else {
MinecraftCompressDecoder decoder = (MinecraftCompressDecoder) channel.pipeline() MinecraftCompressDecoder decoder = (MinecraftCompressDecoder) channel.pipeline()
.get(COMPRESSION_DECODER); .get(COMPRESSION_DECODER);
@ -418,6 +432,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
channel.pipeline().remove(FRAME_ENCODER); channel.pipeline().remove(FRAME_ENCODER);
channel.pipeline().addBefore(MINECRAFT_DECODER, COMPRESSION_DECODER, decoder); channel.pipeline().addBefore(MINECRAFT_DECODER, COMPRESSION_DECODER, decoder);
channel.pipeline().addBefore(MINECRAFT_ENCODER, COMPRESSION_ENCODER, encoder); channel.pipeline().addBefore(MINECRAFT_ENCODER, COMPRESSION_ENCODER, encoder);
channel.pipeline().fireUserEventTriggered(VelocityConnectionEvent.COMPRESSION_ENABLED);
} }
} }
} }
@ -440,6 +456,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
.addBefore(FRAME_DECODER, CIPHER_DECODER, new MinecraftCipherDecoder(decryptionCipher)); .addBefore(FRAME_DECODER, CIPHER_DECODER, new MinecraftCipherDecoder(decryptionCipher));
channel.pipeline() channel.pipeline()
.addBefore(FRAME_ENCODER, CIPHER_ENCODER, new MinecraftCipherEncoder(encryptionCipher)); .addBefore(FRAME_ENCODER, CIPHER_ENCODER, new MinecraftCipherEncoder(encryptionCipher));
channel.pipeline().fireUserEventTriggered(VelocityConnectionEvent.ENCRYPTION_ENABLED);
} }
public @Nullable MinecraftConnectionAssociation getAssociation() { public @Nullable MinecraftConnectionAssociation getAssociation() {

Datei anzeigen

@ -0,0 +1,11 @@
package com.velocitypowered.proxy.protocol;
/**
* Describes various events fired during the course of a connection.
*/
public enum VelocityConnectionEvent {
COMPRESSION_ENABLED,
COMPRESSION_DISABLED,
ENCRYPTION_ENABLED,
PROTOCOL_VERSION_CHANGED
}