I know that the Minecraft client can query the server for number of players and maximum players, even when the server properties has enable-query
set to false
, but how do I do this outside of the client? I am trying to implement this as part of a mobile (Android) app.
1 Answer
This is actually quite well-detailed at this page. Please note that I am going to detail the common protocol introduced in version 1.7. Additionally, a new protocol was introduced in 1.9pre4 that contains additional information not found in the previous protocol. Let me detail how to get the basic server information in 1.7+:
Send a "handshake" packet with the layout:
- 0x00 (Packet ID)
- 0x04 (Protocol Version)
- Length of server address. This is a VarInt, which means that it has a variable length. The last bit of each byte that would normally indicate the sign instead indicates if the next byte is part of the VarInt.
- Server address (Host Name or IP Address)
- Server port (as a Short, Big-endian)
- 0x01 (Next State)
Send a blank "Status Request" packet with the layout:
- 0x00 (Packet ID)
Reading the response, you will get a JSON-encoded object with the following format:
- Version
- Name
- Protocol
- Players
- Max
- Online
- Sample
- Description
- Text
- Favicon
- Mime-type;encoding,
- Version
Since you are writing this for Android, I presume you are using Java. Luckily for you, there is already an open-source Java project that details these steps already made for you. Even better, it shows proper use of VarInt when formatting your packets.