Search in sources :

Example 1 with UserConnection

use of com.viaversion.viaversion.api.connection.UserConnection in project DirtMultiversion by DirtPowered.

the class DetectionHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object object) {
    ByteBuf buffer = (ByteBuf) object;
    try {
        short packetId = buffer.readUnsignedByte();
        if (packetId != 0x02 && packetId != 0xFE) {
            ctx.channel().pipeline().addAfter(ChannelConstants.DETECTION_HANDLER, ChannelConstants.NETTY_LENGTH_DECODER, new VarIntFrameDecoder()).addAfter(ChannelConstants.NETTY_LENGTH_DECODER, ChannelConstants.NETTY_LENGTH_ENCODER, new VarIntFrameEncoder()).addAfter(ChannelConstants.NETTY_LENGTH_ENCODER, ChannelConstants.NETTY_PACKET_DECODER, new NettyPacketDecoder(main, userData, PacketDirection.TO_SERVER)).addAfter(ChannelConstants.NETTY_PACKET_DECODER, ChannelConstants.NETTY_PACKET_ENCODER, new NettyPacketEncoder());
            if (main.getConfiguration().enableViaVersion()) {
                UserConnection userConnection = new UserConnectionImpl(ctx.channel());
                new ProtocolPipelineImpl(userConnection);
                ctx.channel().pipeline().addBefore(ChannelConstants.NETTY_PACKET_DECODER, ChannelConstants.VIA_DECODER, new ViaDecodeHandler(userConnection));
                ctx.channel().pipeline().addBefore(ChannelConstants.NETTY_PACKET_DECODER, ChannelConstants.VIA_ENCODER, new ViaEncodeHandler(userConnection));
            }
        } else {
            ctx.channel().pipeline().addAfter(ChannelConstants.DETECTION_HANDLER, ChannelConstants.LEGACY_PING, new LegacyPingVersionHandler(userData)).addAfter(ChannelConstants.LEGACY_PING, ChannelConstants.LEGACY_DECODER, new PacketDecoder(main, PacketDirection.TO_SERVER, userData)).addAfter(ChannelConstants.LEGACY_DECODER, ChannelConstants.LEGACY_ENCODER, new PacketEncoder());
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        buffer.resetReaderIndex();
        ctx.channel().pipeline().remove(this);
        ctx.fireChannelRead(object);
    }
}
Also used : PacketEncoder(com.github.dirtpowered.dirtmv.network.server.codec.PacketEncoder) ViaDecodeHandler(com.github.dirtpowered.dirtmv.viaversion.handler.ViaDecodeHandler) ProtocolPipelineImpl(com.viaversion.viaversion.protocol.ProtocolPipelineImpl) PacketDecoder(com.github.dirtpowered.dirtmv.network.server.codec.PacketDecoder) ViaEncodeHandler(com.github.dirtpowered.dirtmv.viaversion.handler.ViaEncodeHandler) ByteBuf(io.netty.buffer.ByteBuf) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) UserConnectionImpl(com.viaversion.viaversion.connection.UserConnectionImpl) LegacyPingVersionHandler(com.github.dirtpowered.dirtmv.network.server.codec.LegacyPingVersionHandler)

Example 2 with UserConnection

use of com.viaversion.viaversion.api.connection.UserConnection in project DirtMultiversion by DirtPowered.

the class ViaPlugin method tick.

@Override
public void tick() {
    for (UserData userData : api.getAllConnections()) {
        ProtocolStorage s = userData.getProtocolStorage();
        if (!s.hasObject(PlayerMovementTracker.class))
            return;
        PlayerMovementTracker movementTracker = s.get(PlayerMovementTracker.class);
        if ((System.currentTimeMillis() - movementTracker.getLastLocationUpdate()) >= 50) {
            if (userData.getUniqueId() == null)
                return;
            UserConnection userConnection = connectionManager.getConnectedClient(userData.getUniqueId());
            if (userConnection == null)
                return;
            ProtocolInfo protocolInfo = userConnection.getProtocolInfo();
            if (protocolInfo == null)
                return;
            if (protocolInfo.getPipeline().contains(Protocol1_9To1_8.class) && protocolInfo.getState() == State.PLAY) {
                PacketWrapper wrapper = new PacketWrapperImpl(0x03, null, userConnection);
                wrapper.write(Type.BOOLEAN, true);
                try {
                    wrapper.sendToServer(Protocol1_9To1_8.class, true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) UserData(com.github.dirtpowered.dirtmv.data.user.UserData) PacketWrapperImpl(com.viaversion.viaversion.protocol.packet.PacketWrapperImpl) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) PlayerMovementTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.PlayerMovementTracker) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8)

Example 3 with UserConnection

use of com.viaversion.viaversion.api.connection.UserConnection in project ViaFabric by ViaVersion.

the class MixinServerNetworkIoChInit method onInitChannel.

@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
    if (channel instanceof SocketChannel) {
        UserConnection user = new UserConnectionImpl(channel);
        new ProtocolPipelineImpl(user);
        channel.pipeline().addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user));
        channel.pipeline().addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user));
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) UserConnectionImpl(com.viaversion.viaversion.connection.UserConnectionImpl) ProtocolPipelineImpl(com.viaversion.viaversion.protocol.ProtocolPipelineImpl) FabricDecodeHandler(com.viaversion.fabric.common.handler.FabricDecodeHandler) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) FabricEncodeHandler(com.viaversion.fabric.common.handler.FabricEncodeHandler) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with UserConnection

use of com.viaversion.viaversion.api.connection.UserConnection in project ViaFabric by ViaVersion.

the class MixinServerNetworkIoChInit method onInitChannel.

@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
    if (channel instanceof SocketChannel) {
        UserConnection user = new UserConnectionImpl(channel);
        new ProtocolPipelineImpl(user);
        channel.pipeline().addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user));
        channel.pipeline().addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user));
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) UserConnectionImpl(com.viaversion.viaversion.connection.UserConnectionImpl) ProtocolPipelineImpl(com.viaversion.viaversion.protocol.ProtocolPipelineImpl) FabricDecodeHandler(com.viaversion.fabric.common.handler.FabricDecodeHandler) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) FabricEncodeHandler(com.viaversion.fabric.common.handler.FabricEncodeHandler) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with UserConnection

use of com.viaversion.viaversion.api.connection.UserConnection in project ViaFabric by ViaVersion.

the class MixinServerNetworkIoChInit method onInitChannel.

@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
    if (channel instanceof SocketChannel) {
        UserConnection user = new UserConnectionImpl(channel);
        new ProtocolPipelineImpl(user);
        channel.pipeline().addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user));
        channel.pipeline().addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user));
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) UserConnectionImpl(com.viaversion.viaversion.connection.UserConnectionImpl) ProtocolPipelineImpl(com.viaversion.viaversion.protocol.ProtocolPipelineImpl) FabricDecodeHandler(com.viaversion.fabric.common.handler.FabricDecodeHandler) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) FabricEncodeHandler(com.viaversion.fabric.common.handler.FabricEncodeHandler) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

UserConnection (com.viaversion.viaversion.api.connection.UserConnection)37 UserConnectionImpl (com.viaversion.viaversion.connection.UserConnectionImpl)20 ProtocolPipelineImpl (com.viaversion.viaversion.protocol.ProtocolPipelineImpl)20 SocketChannel (io.netty.channel.socket.SocketChannel)16 Inject (org.spongepowered.asm.mixin.injection.Inject)15 FabricDecodeHandler (com.viaversion.fabric.common.handler.FabricDecodeHandler)14 FabricEncodeHandler (com.viaversion.fabric.common.handler.FabricEncodeHandler)14 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)5 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)3 EventHandler (net.md_5.bungee.event.EventHandler)3 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)2 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)2 Via (com.viaversion.viaversion.api.Via)2 StorableObject (com.viaversion.viaversion.api.connection.StorableObject)2 BlockChangeRecord (com.viaversion.viaversion.api.minecraft.BlockChangeRecord)2 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)2 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)2 ProtocolPathEntry (com.viaversion.viaversion.api.protocol.ProtocolPathEntry)2 ClientboundPacketType (com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType)2 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)2