Skip to main content

SA:MP Query Mechanism

Introduction​

The SA:MP Query Mechanism is nothing more than the mechanism for transmitting server statistics and information, such as name, ping, language, online players, etc...

In this article I will document how this mechanism works, as well as teach you how to use it without needing the original client.

Queries​

Queries are pure UDP packets sent to the server address containing serialized data.

You may ask yourself: "But how does the server interpret query packets differently than those from the RakNet protocol?", and the answer is simple: in the low RakNet socket layer, packets that contain 53 41 4D 50 or translated into characters "SAMP" at the beginning, are treated in a different way. View Code

Serialized Data​

The data transmitted in the packet is: "SAMP" + IP octets + first port byte* + second port byte + OPCODE

If you have doubts about why to extract and what IP octets and port bytes are, see: Link.

Byte sizeName
4"SAMP"
4IP Octets
1Port & 0xFF
1Port >> 8 & 0xFF
1OPCODE

Example in C

OPCODE​

OPCODE's are package identifiers, and each one represents a different request.

  • OPCODE "i" or 0x69: This stands for information. This gets the amount of players in the server, the map name, and all the stuff like that. It's really useful for describing your server without changing anything.

  • OPCODE "r" or 0x72: This stands for rules. 'Rules' when it comes to SA:MP includes the instagib, the gravity, weather, the website URL, and so on

  • OPCODE "c" or 0x63: It stands for client list, this sends back to the server the players' name, and then the players' score. Just imagine it as a basic overview of all the players.

  • OPCODE "d" or 0x64: This stands for detailed player information. With this, you can get everything from the ping to the player, the player ID (useful for admin scripts), the score again, and also the username.

  • OPCODE "x" or 0x78: This is an RCON command, and it's completely different from all of the other packets.