Search in sources :

Example 11 with UserConnection

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

the class VersionedPacketTransformerImpl method transformPacket.

private void transformPacket(PacketWrapper packet) throws Exception {
    // If clientbound: Constructor given inputProtocolVersion → Client version
    // If serverbound: Constructor given inputProtocolVersion → Server version
    PacketType packetType = packet.getPacketType();
    UserConnection connection = packet.user();
    boolean clientbound = packetType.direction() == Direction.CLIENTBOUND;
    int serverProtocolVersion = clientbound ? this.inputProtocolVersion : connection.getProtocolInfo().getServerProtocolVersion();
    int clientProtocolVersion = clientbound ? connection.getProtocolInfo().getProtocolVersion() : this.inputProtocolVersion;
    // Construct protocol pipeline
    List<ProtocolPathEntry> path = Via.getManager().getProtocolManager().getProtocolPath(clientProtocolVersion, serverProtocolVersion);
    List<Protocol> protocolList = null;
    if (path != null) {
        protocolList = new ArrayList<>(path.size());
        for (ProtocolPathEntry entry : path) {
            protocolList.add(entry.protocol());
        }
    } else if (serverProtocolVersion != clientProtocolVersion) {
        throw new RuntimeException("No protocol path between client version " + clientProtocolVersion + " and server version " + serverProtocolVersion);
    }
    if (protocolList != null) {
        // Reset reader and apply pipeline
        packet.resetReader();
        try {
            packet.apply(packetType.direction(), State.PLAY, 0, protocolList, clientbound);
        } catch (Exception e) {
            throw new Exception("Exception trying to transform packet between client version " + clientProtocolVersion + " and server version " + serverProtocolVersion + ". Are you sure you used the correct input version and packet write types?", e);
        }
    }
}
Also used : ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) ServerboundPacketType(com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType) PacketType(com.viaversion.viaversion.api.protocol.packet.PacketType) ClientboundPacketType(com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType) Protocol(com.viaversion.viaversion.api.protocol.Protocol) UserConnection(com.viaversion.viaversion.api.connection.UserConnection)

Example 12 with UserConnection

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

the class ConnectionManagerImpl method getConnectedClientId.

@Override
@Nullable
public UUID getConnectedClientId(UserConnection connection) {
    if (connection.getProtocolInfo() == null)
        return null;
    UUID uuid = connection.getProtocolInfo().getUuid();
    UserConnection client = clients.get(uuid);
    if (connection.equals(client)) {
        // This is frontend
        return uuid;
    }
    return null;
}
Also used : UUID(java.util.UUID) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 13 with UserConnection

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

the class CommonBoss method sendPacket.

private void sendPacket(UpdateAction action) {
    for (UserConnection conn : new ArrayList<>(connections.values())) {
        PacketWrapper wrapper = getPacket(action, conn);
        sendPacketConnection(conn, wrapper);
    }
}
Also used : PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ArrayList(java.util.ArrayList) UserConnection(com.viaversion.viaversion.api.connection.UserConnection)

Example 14 with UserConnection

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

the class ViaIdleThread method run.

@Override
public void run() {
    for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
        ProtocolInfo protocolInfo = info.getProtocolInfo();
        if (protocolInfo == null || !protocolInfo.getPipeline().contains(Protocol1_9To1_8.class))
            continue;
        MovementTracker movementTracker = info.get(MovementTracker.class);
        if (movementTracker == null)
            continue;
        long nextIdleUpdate = movementTracker.getNextIdlePacket();
        if (nextIdleUpdate <= System.currentTimeMillis() && info.getChannel().isOpen()) {
            Via.getManager().getProviders().get(MovementTransmitterProvider.class).sendPlayer(info);
        }
    }
}
Also used : MovementTransmitterProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) MovementTracker(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker)

Example 15 with UserConnection

use of com.viaversion.viaversion.api.connection.UserConnection in project LiquidBouncePlus by WYSI-Foundation.

the class ProviderLoader method load.

@Override
public void load() {
    Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
    Via.getManager().getProviders().use(VersionProvider.class, new BaseVersionProvider() {

        @Override
        public int getClosestServerProtocol(UserConnection connection) throws Exception {
            if (connection.isClientSide())
                return ViaForge.getInstance().getVersion();
            return super.getClosestServerProtocol(connection);
        }
    });
}
Also used : BungeeMovementTransmitter(com.viaversion.viaversion.bungee.providers.BungeeMovementTransmitter) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) BaseVersionProvider(com.viaversion.viaversion.protocols.base.BaseVersionProvider)

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