Search in sources :

Example 1 with ProtocolInfo

use of com.viaversion.viaversion.api.connection.ProtocolInfo 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 2 with ProtocolInfo

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

the class MixinDebugHud method getLeftText.

@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
    String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: " + Via.getManager().getConnectionManager().getConnectedClients().size() + ")";
    @SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler().getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
    if (viaDecoder instanceof FabricDecodeHandler) {
        ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
        if (protocol != null) {
            ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
            ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
            line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
        }
    }
    info.getReturnValue().add(line);
}
Also used : FabricDecodeHandler(com.viaversion.fabric.common.handler.FabricDecodeHandler) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) ChannelHandler(io.netty.channel.ChannelHandler) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with ProtocolInfo

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

the class MixinDebugHud method getLeftText.

@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
    String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: " + Via.getManager().getConnectionManager().getConnectedClients().size() + ")";
    @SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler().getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
    if (viaDecoder instanceof FabricDecodeHandler) {
        ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
        if (protocol != null) {
            ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
            ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
            line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
        }
    }
    info.getReturnValue().add(line);
}
Also used : FabricDecodeHandler(com.viaversion.fabric.common.handler.FabricDecodeHandler) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) ChannelHandler(io.netty.channel.ChannelHandler) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with ProtocolInfo

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

the class BungeeServerHandler method checkServerChange.

public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception {
    if (user == null)
        return;
    // Handle server/version change
    if (user.has(BungeeStorage.class)) {
        BungeeStorage storage = user.get(BungeeStorage.class);
        ProxiedPlayer player = storage.getPlayer();
        if (e.getServer() != null) {
            if (!e.getServer().getInfo().getName().equals(storage.getCurrentServer())) {
                // Clear auto-team
                EntityTracker1_9 oldEntityTracker = user.getEntityTracker(Protocol1_9To1_8.class);
                if (oldEntityTracker != null) {
                    if (oldEntityTracker.isAutoTeam() && oldEntityTracker.isTeamExists()) {
                        oldEntityTracker.sendTeamPacket(false, true);
                    }
                }
                String serverName = e.getServer().getInfo().getName();
                storage.setCurrentServer(serverName);
                int protocolId = ProtocolDetectorService.getProtocolId(serverName);
                if (protocolId <= ProtocolVersion.v1_8.getVersion()) {
                    // 1.8 doesn't have BossBar packet
                    if (storage.getBossbar() != null) {
                        // This ensures we can encode it properly as only the 1.9 protocol is currently implemented.
                        if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
                            for (UUID uuid : storage.getBossbar()) {
                                PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.BOSSBAR, null, user);
                                wrapper.write(Type.UUID, uuid);
                                // remove
                                wrapper.write(Type.VAR_INT, 1);
                                wrapper.send(Protocol1_9To1_8.class);
                            }
                        }
                        storage.getBossbar().clear();
                    }
                }
                ProtocolInfo info = user.getProtocolInfo();
                int previousServerProtocol = info.getServerProtocolVersion();
                // Refresh the pipes
                List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), protocolId);
                ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline();
                user.clearStoredObjects();
                pipeline.cleanPipes();
                if (protocolPath == null) {
                    // TODO Check Bungee Supported Protocols? *shrugs*
                    protocolId = info.getProtocolVersion();
                } else {
                    List<Protocol> protocols = new ArrayList<>(protocolPath.size());
                    for (ProtocolPathEntry entry : protocolPath) {
                        protocols.add(entry.protocol());
                    }
                    pipeline.add(protocols);
                }
                info.setServerProtocolVersion(protocolId);
                // Add version-specific base Protocol
                pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(protocolId));
                // Workaround 1.13 server change
                int id1_13 = ProtocolVersion.v1_13.getVersion();
                boolean toNewId = previousServerProtocol < id1_13 && protocolId >= id1_13;
                boolean toOldId = previousServerProtocol >= id1_13 && protocolId < id1_13;
                if (previousServerProtocol != -1 && (toNewId || toOldId)) {
                    Collection<String> registeredChannels = (Collection<String>) getRegisteredChannels.invoke(e.getPlayer().getPendingConnection());
                    if (!registeredChannels.isEmpty()) {
                        Collection<String> newChannels = new HashSet<>();
                        for (Iterator<String> iterator = registeredChannels.iterator(); iterator.hasNext(); ) {
                            String channel = iterator.next();
                            String oldChannel = channel;
                            if (toNewId) {
                                channel = InventoryPackets.getNewPluginChannelId(channel);
                            } else {
                                channel = InventoryPackets.getOldPluginChannelId(channel);
                            }
                            if (channel == null) {
                                iterator.remove();
                                continue;
                            }
                            if (!oldChannel.equals(channel)) {
                                iterator.remove();
                                newChannels.add(channel);
                            }
                        }
                        registeredChannels.addAll(newChannels);
                    }
                    PluginMessage brandMessage = (PluginMessage) getBrandMessage.invoke(e.getPlayer().getPendingConnection());
                    if (brandMessage != null) {
                        String channel = brandMessage.getTag();
                        if (toNewId) {
                            channel = InventoryPackets.getNewPluginChannelId(channel);
                        } else {
                            channel = InventoryPackets.getOldPluginChannelId(channel);
                        }
                        if (channel != null) {
                            brandMessage.setTag(channel);
                        }
                    }
                }
                user.put(storage);
                user.setActive(protocolPath != null);
                // Init all protocols TODO check if this can get moved up to the previous for loop, and doesn't require the pipeline to already exist.
                for (Protocol protocol : pipeline.pipes()) {
                    protocol.init(user);
                }
                EntityTracker1_9 newTracker = user.getEntityTracker(Protocol1_9To1_8.class);
                if (newTracker != null) {
                    if (Via.getConfig().isAutoTeam()) {
                        String currentTeam = null;
                        for (Team team : player.getScoreboard().getTeams()) {
                            if (team.getPlayers().contains(info.getUsername())) {
                                currentTeam = team.getName();
                            }
                        }
                        // Reinitialize auto-team
                        newTracker.setAutoTeam(true);
                        if (currentTeam == null) {
                            // Send auto-team as it was cleared above
                            newTracker.sendTeamPacket(true, true);
                            newTracker.setCurrentTeam("viaversion");
                        } else {
                            // Auto-team will be sent when bungee send remove packet
                            newTracker.setAutoTeam(Via.getConfig().isAutoTeam());
                            newTracker.setCurrentTeam(currentTeam);
                        }
                    }
                }
                Object wrapper = channelWrapper.get(player);
                setVersion.invoke(wrapper, protocolId);
                Object entityMap = getEntityMap.invoke(null, protocolId);
                entityRewrite.set(player, entityMap);
            }
        }
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) BungeeStorage(com.viaversion.viaversion.bungee.storage.BungeeStorage) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ProtocolPipeline(com.viaversion.viaversion.api.protocol.ProtocolPipeline) PluginMessage(net.md_5.bungee.protocol.packet.PluginMessage) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) Team(net.md_5.bungee.api.score.Team) StorableObject(com.viaversion.viaversion.api.connection.StorableObject) Protocol(com.viaversion.viaversion.api.protocol.Protocol)

Example 5 with ProtocolInfo

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

the class PlayerSneakListener method playerToggleSneak.

@EventHandler(ignoreCancelled = true)
public void playerToggleSneak(PlayerToggleSneakEvent event) {
    Player player = event.getPlayer();
    UserConnection userConnection = getUserConnection(player);
    if (userConnection == null)
        return;
    ProtocolInfo info = userConnection.getProtocolInfo();
    if (info == null)
        return;
    int protocolVersion = info.getProtocolVersion();
    if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getVersion()) {
        setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT);
        if (event.isSneaking())
            sneakingUuids.add(player.getUniqueId());
        else
            sneakingUuids.remove(player.getUniqueId());
        if (!useCache)
            return;
        if (event.isSneaking())
            sneaking.put(player, true);
        else
            sneaking.remove(player);
    } else if (is1_9Fix && protocolVersion >= ProtocolVersion.v1_9.getVersion()) {
        setHeight(player, event.isSneaking() ? HEIGHT_1_9 : STANDING_HEIGHT);
        if (!useCache)
            return;
        if (event.isSneaking())
            sneaking.put(player, false);
        else
            sneaking.remove(player);
    }
}
Also used : Player(org.bukkit.entity.Player) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)17 ProtocolVersion (com.viaversion.viaversion.api.protocol.version.ProtocolVersion)9 FabricDecodeHandler (com.viaversion.fabric.common.handler.FabricDecodeHandler)7 ChannelHandler (io.netty.channel.ChannelHandler)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)3 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)3 ProtocolPathEntry (com.viaversion.viaversion.api.protocol.ProtocolPathEntry)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 UUID (java.util.UUID)2 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)2 ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)1 UserData (com.github.dirtpowered.dirtmv.data.user.UserData)1 PlayerMovementTracker (com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.PlayerMovementTracker)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 AddressParser (com.viaversion.fabric.common.AddressParser)1 NativeVersionProvider (com.viaversion.fabric.common.platform.NativeVersionProvider)1 StorableObject (com.viaversion.viaversion.api.connection.StorableObject)1