PaperMC / Velocity

The modern, next-generation Minecraft server proxy.
https://papermc.io/software/velocity
GNU General Public License v3.0
1.68k stars 583 forks source link

Believe Plugin Forwarding isn't working. #1328

Closed dirazi closed 1 month ago

dirazi commented 1 month ago

PaperMC 1.20.4 Velocity 3.3 bungee-plugin-message-channel = true

While trying to setup a proxy, I found any plugin that was used on the backend that attempted to change the backend server the user was connected to didn't work... (Akropolis, DeluxeHub, FancyNPCs) Only plugin I've made work is VelocityGUI and that's because it runs on the proxy side.

Made a simple plugin to change the backend server And a simple listener for the proxy to verify data is being sent

Backend Plugin ` private static final String BUNGEE_CHANNEL = "dirazi:main";

@Override
public void onEnable() {
    getLogger().info("Dirazi's ProxyConnect enabled!");

    //Plugin Messaging
    Messenger messenger = getServer().getMessenger();
    messenger.registerOutgoingPluginChannel(this, BUNGEE_CHANNEL);

    getCommand("connect").setExecutor((sender, command, label, args) -> {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            if (args.length > 0) {
                String targetServer = args[0];
                connectPlayerToServer(player, targetServer);
            } else {
                player.sendMessage("Usage: /connect <server>");
            }
        }
        return true;
    });
}

@Override
public void onDisable() {
    getLogger().info("Dirazi's ProxyConnect disabled.");
}

private void connectPlayerToServer(Player player, String server) {
    Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
        try {
            byte[] serverNameBytes = server.getBytes();
            player.sendPluginMessage(this, BUNGEE_CHANNEL, serverNameBytes);
            player.sendMessage("Connecting to " + server + "...");
        } catch (Exception e) {
            player.sendMessage("Failed to connect to " + server);
            e.printStackTrace();
        }
    });
}`

Proxy Listener

` public static final MinecraftChannelIdentifier IDENTIFIER = MinecraftChannelIdentifier.from("dirazi:main");

private final ProxyServer proxyServer;
private final Logger logger;

@Inject
public ProxyBungeeListener(ProxyServer proxyServer, Logger logger) {
    this.proxyServer = proxyServer;
    this.logger = logger;
}
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
    proxyServer.getChannelRegistrar().register(IDENTIFIER);
    logger.info("Custom messaging channel registered: " + IDENTIFIER.getId());
}

@Subscribe
public void onPluginMessageFromBackend(PluginMessageEvent event) {
    if (!(event.getSource() instanceof ServerConnection)) {
        return;
    }
    ServerConnection backend = (ServerConnection) event.getSource();

    // Ensure the identifier is what you expect before trying to handle the data
    if (!event.getIdentifier().equals(IDENTIFIER)) {
        return;
    }

    ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
    // handle packet data
    String message = in.readUTF();
    logger.info("Received message from a messenger: " + message);
}`

When using /connect on the backend server, a message pops up saying "Connecting to server..." like it should However no redirection is done and no logger is set off on the proxy side to indicate a message was received.

powercasgamer commented 1 month ago

If you're using the bungee channel on Velocity you need to disable this option. Also make sure you dn't have a plugin like F3Name. You should always use your own channel

dirazi commented 1 month ago

If you're using the bungee channel on Velocity you need to disable this option. Also make sure you dn't have a plugin like F3Name. You should always use your own channel

Wow... I've been trying to chase this for a week. You're a saint.

Removed CustomF3Brand from the proxy and it works as intended.

Why is that?

powercasgamer commented 1 month ago

They override a packet listener which breaks plugin messages. You should open up a issue on their GitHub or contact it's developer.

dirazi commented 1 month ago

They override a packet listener which breaks plugin messages. You should open up a issue on their GitHub or contact it's developer.

https://github.com/LoreSchaeffer/CustomF3Brand/issues/7

Thank you for the information!