How to count and limit (packets/second)/connection?

Discussion in 'BungeeCord Plugin Development' started by Msql, Feb 18, 2020.

  1. How to count and limit (packets/second)/connection?
    I want to prevent players from spamming packets with hacked clients.
    I know that viaversion has packet-limit feature but it is unuseable on bungeecord (it laggs CPU as hell when player joins to the server due to all injections).
    Do someone know good solution how to limit packets per player/ip? Is it possible to do it with iptable rule?
  2. You can hook into the player's channel pipeline with an extended ChannelDuplexHandler and increment the counter when the void channelRead(ChannelHandlerContext, Object) is fired.
    • Useful Useful x 1
  3. Can you give example code, please? I will be very gratefull
  4. Do this when a player joins your server
    Code (Text):
    ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler() {
                public void channelRead(ChannelHandlerContext context, Object packet) throws Exception {


                    super.channelRead(context, packet);

            ChannelPipeline pipeline;
            pipeline = ((CraftPlayer) playerInstance).getHandle();
            if (pipeline == null)
            String handlerName = "my_handler_name";
            if (pipeline.get(handlerName) != null)
            pipeline.addBefore("packet_handler", handlerName, channelDuplexHandler);
    • Friendly Friendly x 1
  5. Thanks a lot! I will try this tomorrow :)!

    Edit: Wait, CraftPlayer in bungee?
    #5 Msql, Feb 19, 2020
    Last edited: Feb 19, 2020
  6. The provided solution is for Spigot. He is asking about BungeeCord.

    About BungeeCord you can get the Player's ChannelWrapper by some huuuge casting, then inject the ChannelDuplexHandler before "inbound-boss" and call the whole into the ConnectionInitEvent.
    • Agree Agree x 1
  7. Can you give example too, please? I have never used netty classes and it looks strange to me. I will be very grateful.
    #7 Msql, Feb 19, 2020
    Last edited: Feb 28, 2020
  8. "Can I get spoon fed please?"