Skip to content

Fix SA-MP ping query payload#410

Merged
AmyrAhmady merged 1 commit into
openmultiplayer:masterfrom
edgyaf:master
May 30, 2026
Merged

Fix SA-MP ping query payload#410
AmyrAhmady merged 1 commit into
openmultiplayer:masterfrom
edgyaf:master

Conversation

@edgyaf
Copy link
Copy Markdown
Contributor

@edgyaf edgyaf commented May 30, 2026

Servers using dataforest's DDoS protection always appear offline in the open.mp launcher, even though they display perfectly fine in the SA-MP launcher. This PR adjusts the payload so that it is not rejected.

Some affected servers:

  • 143.20.37.52:7777
  • 31.59.58.187:7777
  • 185.213.240.246:7777

Before:
image

After:
image

Note: I don’t work with the stack that is used here, so the changes were made through Codex.

Description from clanker:

This fixes SA-MP server ping queries to follow the documented SA-MP query protocol.

Previously, the launcher sent the p ping query with four zero bytes as the payload. According to the SA-MP query mechanism, the ping packet should include four pseudo-random bytes after the p query type. Some servers, including ones behind DataForest DDoS protection, appear to reject or ignore the all-zero ping payload even though they still respond to other query types such as info, rules, and players.

The change replaces the hardcoded zero payload with a four-byte value generated from the current system time. The existing ping send/receive flow is otherwise unchanged, keeping the fix minimal while making the ping packet match the expected SA-MP format.

@TanF12
Copy link
Copy Markdown

TanF12 commented May 30, 2026

Nice one, but the maths in the nanosecond conversion is flawed.

Casting the duration.as_nanos() to a u32 means the maximum value it can hold before wrapping back to zero is 4,294,967,295. As these are nanoseconds, the timer will overflow every ~4 seconds. Therefore, if a packet takes longer than 4.3 seconds to roundtrip (like during a lag spike for example), the maths could wrap around and calculate an absurd ping.

I'd change it to milliseconds if I were you.

https://doc.rust-lang.org/beta/std/time/struct.Duration.html#method.as_millis

Also, I should warn that SystemTime is theoretically subject to NTP clock adjustments and can jump backwards. But it should be fine for now.

Also, you might be able to just an RNG like rand to generate random 4 bytes, which would be a lot simpler and more robust than the logic here

Actually, this is fine. I just double-checked it and the 4 byte payload echoed by the server is completely ignored, so the overflow is irrelevant

@AmyrAhmady AmyrAhmady merged commit 00aec2a into openmultiplayer:master May 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants