Solved Know if a player lagging

Discussion in 'Spigot Plugin Development' started by MasqueOu, Mar 23, 2020.

  1. MasqueOu

    MasqueOu Previously MAKSHOUW

    What's up everyone !

    I would like to know if it was possible to detect if a lagging player, some friends told me that it was possible with the packets, I don't know which one, what about?

    By the way, if you have some tips to know if the lagging server too, it would help me too, other than with the TPS, it could be more reliable! :)

    Thanks to you !
  2. Simply get the player's ping, if the ping is above 300 then the player is a lil bit laggy, if above 500 then the player is lagging
    Code (Java):
    Player player;
            CraftPlayer cp = (CraftPlayer)player;
            int ping = cp.getHandle().ping;
            if (ping > 1000) {
                // extremely lag
            } else if (ping > 500) {
                // got some lag back
            } else if (ping > 300) {
                // lil bit lag
  3. The only thing I know, is that you can get the server's ticks per second by doing this
    Code (Java):
  4. MasqueOu

    MasqueOu Previously MAKSHOUW

    Hey, thanks for response !

    I know we can see the ping with a NMS method.. But, now, i would like a detection for all lagging, not specialy a high ping detector..

    Thanks u :) !
  5. If a player has a high ping he's automatically "lagging".
  6. MasqueOu

    MasqueOu Previously MAKSHOUW

    Not especially, someone can get packet loss and have a good ping...

    Lagging, like reloading resource pack, pc crash, etc

    Sorry for my english, i'am french haha..
  7. Let's not forget that the client can sort of spoof this... I mean, not sure purpose of this is, but just remember there are client hacks such as blink I believe which purposefully "lag" the connection.
    • Like Like x 1
  8. If you rly want to go in depth... most of us alrrady know shat happens when someone crashes,he gets stuck in the air,there is the problem,nothing gets in or out from the server,i assume minecraft sends a packet every few sec to confirm that the player is still connected,if not a certain timer starts to throw the "timeout kick"

    Look deeper in that error
  9. The obvious answer would be ping, but you're right that sometimes ping doesn't exactly help in the short term when a player experiences lost packets. My first thought would be to somehow keep track of the last time the player sent a packet and see if it's over a certain limit. The player will send a PlayerMovement packet every 20 ticks even when stationary, so you could check if the player has not sent a packet within the last 20 ticks, and if they haven't the player is definitely lagging. To do this you would most likely have to use ProtocolLib or TinyProtocol, though.
    • Agree Agree x 1
  10. Great ideas where thrown in here,
    Let me throw now stuff in here:

    If you are making an AntiCheat and I assume you are since I dont see much more usage for that, here is what I recommend doing:

    - Check the players ping its is important BUT don't use bukkit's ping since its easily spoofed by most clients, calculate your own ping using packets, if you did it right it should be very close to bukkits ping maybe off by 1 or 2 ms but mostly the same, also if you want to support more then one version but still get the bukkit ping you can use reflection even thougn I calculate it myself with packets since reflection is slow
    - Check the server TPS, the TPS is your way to check server sided lag, you can get it from NMS as mentioned above but you can also calculate it yourself if you want to support more then one version

    Now if you code your checks properly you should be good to go using those things but if you still want to be extra safe there are more easy ways I can share of checking if the player is glitching into blocks (like walking into anvils in 1.8.X) which actually causes too many anticheats to false, and more stuff like that

    for stellrow's idea, you can use flying packets for that but you really need to be carful when making such system since then one mistake and people would be able to make a dissabler for your anticheat using this

    When loading a resource pack your game freezes for a short time in most cases for no more then one second, if the client stops sending packets only for one second it should not be that big of a deal, but if you really want to know that check if the client sends any special packet when player changes resource pack, im pretty sure there is a packet for that so really just listen to it

    You can DM me if you want any more indept info about this methods
    #10 Nort721, Mar 23, 2020
    Last edited: Mar 23, 2020
    • Winner Winner x 1
  11. MasqueOu

    MasqueOu Previously MAKSHOUW

    Thank you very much for these ideas, I will put them into practice! ♥