Skip to content

Use relative timestamps#61

Open
TrippleAWap wants to merge 2 commits intoCloudburstMC:developfrom
TrippleAWap:develop
Open

Use relative timestamps#61
TrippleAWap wants to merge 2 commits intoCloudburstMC:developfrom
TrippleAWap:develop

Conversation

@TrippleAWap
Copy link

Closer follow the logic of MCBE's RakNet implementation.

Closer follow the logic of MCBE's RakNet implementation.
@irrld
Copy link
Contributor

irrld commented Jan 6, 2026

This is incorrect, you need to handle the pong timestamp as well.

Additionally, this is not required. The client simply sends what it has received so we can calculate round trip time by subtracting it from the current time. This makes things more complex without any reason.

@TrippleAWap
Copy link
Author

You're correct this isn't required but the RakNet implementation used in MCBE populates the ping and pong field with a timestamp which is relative to the system or process start time (varies across platforms.)
image
image

@TrippleAWap
Copy link
Author

You're correct this isn't required but the RakNet implementation used in MCBE populates the ping and pong field with a timestamp which is relative to the system or process start time (varies across platforms.) image image

The 1st provided picture was actually after the pong but you should get the idea.

@TrippleAWap
Copy link
Author

This is incorrect, you need to handle the pong timestamp as well.

Additionally, this is not required. The client simply sends what it has received so we can calculate round trip time by subtracting it from the current time. This makes things more complex without any reason.

Also calculating round trip time would be essentially the same, we'd just be subtracting timestamp.

@irrld
Copy link
Contributor

irrld commented Jan 6, 2026

Are you sure that getPing returns the correct ping?

@irrld
Copy link
Contributor

irrld commented Jan 6, 2026

we'd just be subtracting timestamp.

Yes but you are not subtracting the same timestamp. And why do two extra subtraction operations when it already works? There is no point for this, it just adds extra complexity.

@irrld
Copy link
Contributor

irrld commented Jan 6, 2026

The correct solution is not this. Correct solution would be to use System.nanoTime() / 1_000_000, because the System.currentTimeMillis() change with the system time. Actual raknet behavior probably is using monotonic time, not subtracting start time like this.

@TrippleAWap
Copy link
Author

This is exactly the same except we're using RakUtils.timestamp() instead of System.currentTimeMillis() not much of a change but I would like to follow the MCBE's implementation as close as possible.

@irrld
Copy link
Contributor

irrld commented Jan 6, 2026

I think you should remove the start timestamp part, nanoTime is already what you want

@TrippleAWap
Copy link
Author

TrippleAWap commented Jan 6, 2026

It isn't though, as seen in the screenshot provided the client and bedrock dedicated server both provide timestamps relative to the system or process start time.
image

@TrippleAWap TrippleAWap changed the title Use relative timestamp for ConnectedPong Use relative timestamps Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants