Server queries: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Progress save)
m (Progress update.)
Line 181: Line 181:
=== Response format ===
=== Response format ===


==== [[Goldsource]] servers ====
==== [[Goldsource]] Server ====


{{Warning|This is obsolete.  GoldSource servers (except for HLTV ones?) now report using the same protocol as Source servers.  To differentiate between (for example) Counter-Strike and Counter-Strike: Source, or other games with the same gamedir, use the Steam AppId.}}
{{Warning|This is obsolete.  GoldSource servers (except for HLTV ones?) now report using the same protocol as Source servers.  To differentiate between (for example) Counter-Strike and Counter-Strike: Source, or other games with the same gamedir, use the Steam AppId.}}
Line 194: Line 194:
| Name || [[string]] || Name of the server.
| Name || [[string]] || Name of the server.
|-
|-
| Map || [[string]] || Current map the server has loaded.
| Map || [[string]] || Map the server has currently loaded.
|-
|-
| Folder || [[string]] || Name of the folder containing the game files.
| Folder || [[string]] || Name of the folder containing the game files.
Line 212: Line 212:
| Visibility || [[byte]] || Indicates whether the server requires a password: <ul><li>0 for public</li><li>1 for private</li></ul>
| Visibility || [[byte]] || Indicates whether the server requires a password: <ul><li>0 for public</li><li>1 for private</li></ul>
|-
|-
| Mod || [[byte]] || Indicates whether the game is a mod: <ul><li>0 for [[Half-Life]]</li><li>1 for [[Half-Life]] mod</li></ul>
| Mod || [[byte]] || Indicates whether the game is a mod: <ul><li>0 for [[Half-Life]]</li><li>1 for Half-Life mod</li></ul>
|-
|-
| colspan="3" | These fields are only present in the response if "Mod" is 1:
| colspan="3" | These fields are only present in the response if "Mod" is 1:
Line 233: Line 233:
|}
|}
|-
|-
| VAC || [[byte]] || Specifies whether the server uses VAC: <ul><li>0 for unsecured</li><li>1 for secured</li></ul>
| [[VAC]] || [[byte]] || Specifies whether the server uses VAC: <ul><li>0 for unsecured</li><li>1 for secured</li></ul>
|-
|-
| Bots || [[byte]] || Number of bots on the server.
| Bots || [[byte]] || Number of bots on the server.
Line 239: Line 239:


{{Note|HLTV servers may respond with a late request that is either incomplete or incorrect if the number of slots is 255.}}
{{Note|HLTV servers may respond with a late request that is either incomplete or incorrect if the number of slots is 255.}}
==== [[Source]] Server ====
{{Note|Both [[SiN 1 Multiplayer]] and [[Rag Doll Kung Fu]] utilise this response protocol.}}
{| class=standard-table
! Data !! Type !! Comment
|-
| Header || [[byte]] || Always equal to 'I' (0x49.)
|-
| Protocol || [[byte]] || Protocol version used by the server.
|-
| Name || [[string]] || Name of the server.
|-
| Map || [[string]] || Map the server has currently loaded.
|-
| Folder || [[string]] || Name of the folder containing the game files.
|-
| Game || [[string]] || Full name of the game.
|-
| ID || [[short]] || [[Steam Application ID]] of game.
|-
| Players || [[byte]] || Number of players on the server.
|-
| Max. Players || [[byte]] || Maximum number of players the server reports it can hold.
|-
| Bots || [[byte]] || Number of bots on the server.
|-
| Server type || [[byte]] || Indicates the type of server: <ul><li>'D' for a dedicated server</li><li>'L' for a non-dedicated server</li><li>'P' for a [[SourceTV]] server</li></ul>
|-
| Environment || [[byte]] || Indicates the operating system of the server: <ul><li>'L' for Linux</li><li>'W' for Windows</li></ul>
|-
| Visibility || [[byte]] || Indicates whether the server requires a password: <ul><li>0 for public</li><li>1 for private</li></ul>
|-
| [[VAC]] || [[byte]] || Specifies whether the server uses VAC: <ul><li>0 for unsecured</li><li>1 for secured</li></ul>
|-
| colspan="3" | These fields only exist in a response if the server is running [[The Ship]]:
{| style="margin:10px;"
! Data || Type || Comment
|-
| Mode || [[byte]] || Indicates the game mode: <ul><li>0 for Hunt</li><li>1 for Elimination</li><li>2 for Duel</li><li>3 for Deathmatch</li><li>4 for VIP Team</li><li>5 for Team Elimination</li></ul>
|-
| Witnesses || [[byte]] || The number of witnesses necessary to have a player arrested.
|-
| Duration || [[byte]] || Time (in seconds) before a player is arrested while being witnessed.
|}
|-
| Version || [[string]] || Version of the game installed on the server.
|-
| Extra Data Flag (EDF) || [[byte]] || If present, this specifies which additional data fields will be included.
|-
| colspan="3" | '''Only if''' <code>if ( EDF & 0x80 )</code> proves true:
{| style="margin:10px"
! Data || Type || Comment
|-
| Port || [[short]] || The server's game port number.
|}
|-
| colspan="3" | '''Only if''' <code>if ( EDF & 0x10 )</code> proves true:
{| style="margin:10px"
! Data || Type || Comment
|-
| [[SteamID]] || [[long]] long || Server's SteamID.
|}
|-
| colspan="3" | '''Only if''' <code>if ( EDF & 0x40 )</code> proves true:
{| style="margin:10px"
! Data || Type || Comment
|-
| Port || [[short]] || Spectator port number for [[SourceTV]].
|-
| Name || [[string]] || Name of the spectator server for SourceTV.
|}
|-
| colspan="3" | '''Only if''' <code>if ( EDF & 0x20 )</code> proves true:
{| style="margin:10px"
! Data || Type || Comment
|-
| Keywords || [[string]] || Tags that describe the game according to the server (for future use.)
|}
|-
| colspan="3" | '''Only if''' <code>if ( EDF & 0x01 )</code> proves true:
{| style="margin:10px"
! Data || Type || Comment
|-
| GameID || [[long]] long || The server's 64-bit GameID.
|}
|}
{{Note|[[Rag Doll Kung Fu]] servers always return 0 for "Server type."}}
<br>
Example reply for [[Counter Strike: Source]]:
{|style="background:transparent;"
|
FF FF FF FF 49 02 67 61 6D 65 32 78 73 2E 63 6F    ÿÿÿÿI.game2xs.co
6D 20 43 6F 75 6E 74 65 72 2D 53 74 72 69 6B 65    m Counter-Strike
20 53 6F 75 72 63 65 20 23 31 00 64 65 5F 64 75    Source #1.de_du
73 74 00 63 73 74 72 69 6B 65 00 43 6F 75 6E 74    st.cstrike.Count
65 72 2D 53 74 72 69 6B 65 3A 20 53 6F 75 72 63    er-Strike: Sourc
65 00 F0 00 05 10 04 64 6C 00 00 31 2E 30 2E 30    e......dl..1.0.0
2E 32 32 00                                        .22.
|}
Example reply for [[The Ship]]:
{|style="background:transparent;"
|
FF FF FF FF 49 07 53 68 69 70 20 53 65 72 76 65    ÿÿÿÿI.Ship Serve
72 00 62 61 74 61 76 69 65 72 00 73 68 69 70 00    r.batavier.ship.
54 68 65 20 53 68 69 70 00 60 09 01 05 00 6C 77    The Ship.`....lw
00 00 01 03 03 31 2E 30 2E 30 2E 34 00            .....1.0.0.4.
|}
Example reply for [[SiN 1 Multiplayer]]:
{|style="background:transparent;"
|
FF FF FF FF 49 2F 53 65 6E 73 65 6D 61 6E 6E 20    ÿÿÿÿI/Sensemann
53 69 4E 20 44 4D 00 70 61 72 61 64 6F 78 00 53    SiN DM.paradox.S
69 4E 20 31 00 53 69 4E 20 31 00 1D 05 00 10 00    iN 1.SiN 1......
6C 77 00 00 31 2E 30 2E 30 2E 30 00                lw..1.0.0.0.
|}
Example reply for [[Rag Doll Kung Fu]]:
{|style="background:transparent;"
|
FF FF FF FF 49 FC 54 68 65 20 44 75 64 65 27 73    ÿÿÿÿIüThe Dude's
20 64 6F 6A 6F 00 53 6F 63 63 65 72 00 52 44 4B      dojo.Soccer.RDK
46 53 6F 63 63 65 72 00 52 61 67 44 6F 6C 6C 4B    FSoccer.RagDollK
75 6E 67 46 75 3A 20 53 6F 63 63 65 72 00 EA 03    ungFu: Soccer.ê.
01 04 00 00 77 00 00 32 2E 33 2E 30 2E 30 00        ....w..2.3.0.0.
|}


== A2S_SERVERQUERY_GETCHALLENGE ==
== A2S_SERVERQUERY_GETCHALLENGE ==

Revision as of 18:58, 28 December 2012

Under construction.png
This page is actively undergoing a major edit.
As a courtesy, please do not edit this while this message is displayed.
If this page has not been edited for at least several hours to a few days, please remove this template. This message is intended to help reduce edit conflicts; please remove it between editing sessions to allow others to edit the page.

The person who added this notice will be listed in its edit history should you wish to contact them.

Template:Otherlang2

You can query information from a running game server using UDP/IP packets. This document describes the packet formats and protocol to access this data.

Data Types

All server queries consist of five basic types of data packed together into a data stream. All types are little endian, which is the default on most languages on x86 CPUs. Java users should use ByteBuffer to convert.

Name Description
byte 8 bit character or unsigned integer
short 16 bit signed integer
long 32 bit signed integer
float 32 bit floating point
long long 64 bit unsigned integer
string variable-length byte field, encoded in UTF-8, terminated by 0x00

Protocol

Steam uses a packet size of 1400 bytes + IP/UDP headers. If a request or response needs more packets for the data it starts the packets with an additional header.

Simple Response

Data Type Comment
Header long Always equal to -1 (0xFFFFFFFF). Means it isn't split.
Payload

Multi-packet Response

Goldsource Server

Data Type Comment
Header long Always equal to -2 (0xFFFFFFFE). Means the packet is split.
ID long Unique number assigned by server per answer.
Packet number byte Upper 4 bits represent the number of the current packet (starting at 0) and bottom 4 bits represent the total number of packets (2 to 15).
Payload

Source Server

Data Type Comment
Header long Always equal to -2 (0xFFFFFFFE). Means the packet is split.
ID long Same as the Goldsource server meaning. However, if the Wikipedia icon most significant bit is 1, then the response was compressed with bzip2 before being cut and sent. Refer to compression procedure below.
Total byte The total number of packets in the response.
Number byte The number of the packet. Starts at 0.
Size short (Orange Box Engine and above only.) Maximum size of packet before packet switching occurs. The default value is 1248 bytes (0x04E0), but the server administrator can decrease this. For older engine versions: the maximum and minimum size of the packet was unchangeable.
This is only present in the first packet of the response and only if the response is being compressed.
Data Type Comment
Size long Size of the whole response once it is decompressed.
CRC32 sum long CRC32 checksum of uncompressed response.

To uncompress this response: collect and assemble all the packets of the answer, then pass that into a function like BZ2_bzBuffToBuffDecompress() in C, bzdecompress() in PHP, or bz2.decompress() in Python.

Payload

Because UDP packets can arrive in different order or delayed, every packet should be verified by its "ID" and "Number"! Every request or response with or without this header is continued with an integer -1 (0xFFFFFFFF) and the user data. So by reading the first 4 bytes you can decide whether the data is split (-2) or in one packet (-1).

Warning.pngWarning:TF2 currently does not split replies, expect A2S_PLAYER and A2S_RULES to be simply cut off after 1260 bytes.

Requests

The server responds to 5 queries:

A2A_PING
Ping the server.
A2S_SERVERQUERY_GETCHALLENGE
Returns a challenge number for use in the player and rules query.
A2S_INFO
Basic information about the server.
A2S_PLAYER
Details about each player on the server.
A2S_RULES
The rules the server is using.

Queries should be sent in UDP packets to the listen port of the server.

A2A_PING

Ping the server to see if it exists, this can be used to calculate the latency to the server.

Warning.pngWarning:According to an official, Valve mailing list posted on the Talk Page, A2A_PING is no longer supported on Counter Strike: Source and Team Fortress 2 servers at this time, and is considered a deprecated feature.

Request format

Data Type Value
Header byte 'i' (0x69)
FF FF FF FF 69                                     ÿÿÿÿi           

Response format

Goldsource Server

Data Type Value
Header byte 'j' (0x6A)
Payload string Null
FF FF FF FF 6A 00                                  ÿÿÿÿj.           

Source Server

Data Type Value
Heading byte 'j' (0x6A)
Payload string '00000000000000'
FF FF FF FF 6A 30 30 30 30 30 30 30 30 30 30 30    ÿÿÿÿj00000000000
30 30 30 00                                        000.

A2S_INFO

Retrieves information about the server including, but not limited to: its name, the map currently being played, and the number of players.

Request format

Data Type Value
Header byte 'T' (0x54)
Payload string "Source Engine Query"
FF FF FF FF 54 53 6F 75 72 63 65 20 45 6E 67 69   ÿÿÿÿTSource Engi
6E 65 20 51 75 65 72 79 00                        ne Query

Response format

Goldsource Server

Warning.pngWarning:This is obsolete. GoldSource servers (except for HLTV ones?) now report using the same protocol as Source servers. To differentiate between (for example) Counter-Strike and Counter-Strike: Source, or other games with the same gamedir, use the Steam AppId.
Data Type Comment
Header byte Always equal to 'm' (0x6D.)
Address string IP address and port of the server.
Name string Name of the server.
Map string Map the server has currently loaded.
Folder string Name of the folder containing the game files.
Game string Full name of the game.
Players byte Number of players on the server.
Max. Players byte Maximum number of players the server reports it can hold.
Protocol byte Protocol version used by the server.
Server type byte Indicates the type of server:
  • 'D' for dedicated server
  • 'L' for non-dedicated server
  • 'P' for a HLTV server
Environment byte Indicates the operating system of the server:
  • 'L' for Linux
  • 'W' for Windows
Visibility byte Indicates whether the server requires a password:
  • 0 for public
  • 1 for private
Mod byte Indicates whether the game is a mod:
These fields are only present in the response if "Mod" is 1:
Data Type Comment
Link string URL to mod website.
Download Link string URL to download the mod.
NULL byte NULL byte (0x00)
Version long Version of mod installed on server.
Size long Space (in bytes) the mod takes up.
Type byte Indicates the type of mod:
  • 0 for single and multiplayer mod
  • 1 for multiplayer only mod
DLL byte Indicates whether mod uses its own DLL:
  • 0 if it uses the Half-Life DLL
  • 1 if it uses its own DLL
VAC byte Specifies whether the server uses VAC:
  • 0 for unsecured
  • 1 for secured
Bots byte Number of bots on the server.
Note.pngNote:HLTV servers may respond with a late request that is either incomplete or incorrect if the number of slots is 255.

Source Server

Note.pngNote:Both SiN 1 Multiplayer and Rag Doll Kung Fu utilise this response protocol.
Data Type Comment
Header byte Always equal to 'I' (0x49.)
Protocol byte Protocol version used by the server.
Name string Name of the server.
Map string Map the server has currently loaded.
Folder string Name of the folder containing the game files.
Game string Full name of the game.
ID short Steam Application ID of game.
Players byte Number of players on the server.
Max. Players byte Maximum number of players the server reports it can hold.
Bots byte Number of bots on the server.
Server type byte Indicates the type of server:
  • 'D' for a dedicated server
  • 'L' for a non-dedicated server
  • 'P' for a SourceTV server
Environment byte Indicates the operating system of the server:
  • 'L' for Linux
  • 'W' for Windows
Visibility byte Indicates whether the server requires a password:
  • 0 for public
  • 1 for private
VAC byte Specifies whether the server uses VAC:
  • 0 for unsecured
  • 1 for secured
These fields only exist in a response if the server is running The Ship:
Data Type Comment
Mode byte Indicates the game mode:
  • 0 for Hunt
  • 1 for Elimination
  • 2 for Duel
  • 3 for Deathmatch
  • 4 for VIP Team
  • 5 for Team Elimination
Witnesses byte The number of witnesses necessary to have a player arrested.
Duration byte Time (in seconds) before a player is arrested while being witnessed.
Version string Version of the game installed on the server.
Extra Data Flag (EDF) byte If present, this specifies which additional data fields will be included.
Only if if ( EDF & 0x80 ) proves true:
Data Type Comment
Port short The server's game port number.
Only if if ( EDF & 0x10 ) proves true:
Data Type Comment
SteamID long long Server's SteamID.
Only if if ( EDF & 0x40 ) proves true:
Data Type Comment
Port short Spectator port number for SourceTV.
Name string Name of the spectator server for SourceTV.
Only if if ( EDF & 0x20 ) proves true:
Data Type Comment
Keywords string Tags that describe the game according to the server (for future use.)
Only if if ( EDF & 0x01 ) proves true:
Data Type Comment
GameID long long The server's 64-bit GameID.
Note.pngNote:Rag Doll Kung Fu servers always return 0 for "Server type."


Example reply for Counter Strike: Source:

FF FF FF FF 49 02 67 61 6D 65 32 78 73 2E 63 6F    ÿÿÿÿI.game2xs.co
6D 20 43 6F 75 6E 74 65 72 2D 53 74 72 69 6B 65    m Counter-Strike
20 53 6F 75 72 63 65 20 23 31 00 64 65 5F 64 75     Source #1.de_du
73 74 00 63 73 74 72 69 6B 65 00 43 6F 75 6E 74    st.cstrike.Count
65 72 2D 53 74 72 69 6B 65 3A 20 53 6F 75 72 63    er-Strike: Sourc
65 00 F0 00 05 10 04 64 6C 00 00 31 2E 30 2E 30    e......dl..1.0.0
2E 32 32 00                                        .22.

Example reply for The Ship:

FF FF FF FF 49 07 53 68 69 70 20 53 65 72 76 65    ÿÿÿÿI.Ship Serve
72 00 62 61 74 61 76 69 65 72 00 73 68 69 70 00    r.batavier.ship.
54 68 65 20 53 68 69 70 00 60 09 01 05 00 6C 77    The Ship.`....lw
00 00 01 03 03 31 2E 30 2E 30 2E 34 00             .....1.0.0.4.

Example reply for SiN 1 Multiplayer:

FF FF FF FF 49 2F 53 65 6E 73 65 6D 61 6E 6E 20    ÿÿÿÿI/Sensemann 
53 69 4E 20 44 4D 00 70 61 72 61 64 6F 78 00 53    SiN DM.paradox.S
69 4E 20 31 00 53 69 4E 20 31 00 1D 05 00 10 00    iN 1.SiN 1......
6C 77 00 00 31 2E 30 2E 30 2E 30 00                lw..1.0.0.0.

Example reply for Rag Doll Kung Fu:

FF FF FF FF 49 FC 54 68 65 20 44 75 64 65 27 73     ÿÿÿÿIüThe Dude's
20 64 6F 6A 6F 00 53 6F 63 63 65 72 00 52 44 4B      dojo.Soccer.RDK
46 53 6F 63 63 65 72 00 52 61 67 44 6F 6C 6C 4B     FSoccer.RagDollK
75 6E 67 46 75 3A 20 53 6F 63 63 65 72 00 EA 03     ungFu: Soccer.ê.
01 04 00 00 77 00 00 32 2E 33 2E 30 2E 30 00        ....w..2.3.0.0.

A2S_SERVERQUERY_GETCHALLENGE

Request format

Challenge values are required for A2S_PLAYER and A2S_RULES requests, you can use this request to get one.

Note.pngNote:You can also send A2S_PLAYER and A2S_RULES queries with a challenge value of -1 (0xFF FF FF FF) and they will respond with a challenge value to use (using the response format below).
Warning.pngWarning:As of September 29, 2009, the implementation of this query does not function in Goldsource nor Left4Dead2 servers. Use the method described above as a workaround. For more, see the Talk Page
FF FF FF FF 57

Response format

Data Type Comment
Type byte Should be equal to 'A' (0x41)
Challenge long The challenge number to use

Example response:

FF FF FF FF 41 32 42 59 45

A2S_PLAYER

Request format

FF FF FF FF 55 <4 byte challenge number>

The challenge number can either be set to -1 (0xFF FF FF FF) to have the server response with S2C_CHALLENGE, or use the value from a previous A2S_SERVERQUERY_GETCHALLENGE request.

Response format

The players response has two sections, the initial header:

Data Type Comment
Type byte Should be equal to 'D' (0x44)
Num Players byte The number of players reported in this response

Then for each player the following fields are sent:

Data Type Comment
Index byte The index into [0.. Num Players] for this entry
Player Name string Player's name
Kills long Number of kills this player has
Time connected float The time in seconds this player has been connected
Note.pngNote: Java users can read the player score as an int and reverse the bytes with Integer.reverseBytes(int i).
Warning.pngWarning:As of September 29, 2009, Left4Dead2 returns an index of zero for all players.

A2S_RULES

Request format

FF FF FF FF 56 <4 byte challenge number>

The challenge number can either be set to -1 (0xFF FF FF FF) to have the server reply with S2C_CHALLENGE, or use the value from a previous A2S_SERVERQUERY_GETCHALLENGE request.

Response format

The rules response has two sections, the initial header:

Data Type Comment
Type byte Should be equal to 'E' (0x45)
Num Rules short The number of rules reported in this response

Then for each rule the following fields are sent:

Data Type Comment
Rule Name string The name of the rule
Rule Value string The rule's value

Implementations

See Also