1.8.8 [1.8.x - 1.16.x] Precise Timer

Discussion in 'Spigot Plugin Development' started by Kavatch, Oct 18, 2020.

  1. Hey,

    so I want to time some of the player's actions precisely. Therefor I made a timer, which starts by saving the start time (System.currentTimeMillis()) and which stops by the calculating the start time - the current time.
    But since my server started to grow international I found out that some players get an unfair advantage when the have a high ping. For example if I start the timer as soon as the place a block players with a low ping get a good representation of the start time, but someone with a ping of 700 will get an almost 1 second advantage.
    Is there any way to make a timer independent of the ping?

    I have tried to log the packets a player send and then get the time from that. However I sometimes get major time differences.
    I used the following packets: Position, Flying, Look and Position Look. And I worked! ... sometimes :/

    So now I am out of ideas. Maybe someone else has a idea for me or knows what I did wrong with my current methodes.

    Thanks :)
     
  2. Heirteir

    Heirteir Previously Vibemaster

    Start the timer for both players when one starts an action?

    Or if they are both doing it at separates times start the timer when they get teleported you shouldn't be depending your timer start on what they're doing, but on something server-side.
     
  3. No, each player gets an own timer. An good example is a JumpAndRun plugin. Each player can start when ever they want. But the Interact event for the pressure plate at the start will give the player with the high ping an advantage.

    But instead of the InteractEvent I am using the BlockPlaceEvent. Which they can "trigger" whenever they want. So I cant start a timer with something on the server side. At least I dont know any event that I could use.
     
  4. Heirteir

    Heirteir Previously Vibemaster

    Only other thing I could think of is to increment the time based on how many packets are sent in. Like for each move packet sent in after they send the PacketPlayInBlockPlace packet add 50ms to the timer.
     
  5. Thats exactly what I have tried.
    I used these packets (ProtocolLib):
    - PacketType.Play.Client.POSITION
    - PacketType.Play.Client.FLYING
    - PacketType.Play.Client.LOOK
    - PacketType.Play.Client.POSITION_LOOK

    and started the logging as soon as I relieve the first PacketType.Play.Client.BLOCK_PLACE packet.

    But sometimes (I am unable to reproduce the bug) the time is 10 seconds or more higher than it should be.
     
  6. Does anyone else has a idea? ^^