Files
mc-status/README.md
2025-06-16 10:22:44 -04:00

118 lines
3.4 KiB
Markdown

# Minecraft Server Status Checker
This project provides two Go programs to query the status of Minecraft servers: one for Bedrock Edition (`statusBedrock.go`) and one for Java Edition (`status.go`). Both programs use the `mcstatus-io/mcutil` library to fetch server information and output the results in formatted JSON.
## Features
- Query Minecraft server status for Bedrock or Java Edition.
- Configurable hostname and port via command-line flags.
- Timeout handling to prevent hanging on unresponsive servers.
- Formatted JSON output for easy parsing or reading.
- Lightweight and simple to use.
## Prerequisites
- [Go](https://golang.org/dl/) (version 1.16 or later recommended)
- Internet access to query the Minecraft server
- The `mcstatus-io/mcutil` library (automatically installed via `go get`)
## Installation
1. Clone or download this repository:
```bash
git clone https://git.ssh.surf/hypermc/mc-status.git
cd mc-status
```
2. Install the required Go module:
```bash
go get github.com/mcstatus-io/mcutil/v4
```
3. Ensure your Go environment is set up correctly (`go mod init` if needed).
## Usage
### Bedrock Edition (`statusBedrock.go`)
This program queries a Minecraft Bedrock Edition server.
1. Compile the program:
```bash
go build statusBedrock.go
```
2. Run the program with default settings (queries `my-mc.link:25565`):
```bash
./statusBedrock
```
3. Customize the hostname and port using flags:
```bash
./statusBedrock -host=example.com -port=19132
```
### Java Edition (`status.go`)
This program queries a Minecraft Java Edition server.
1. Compile the program:
```bash
go build status.go
```
2. Run the program with default settings (queries `my-mc.link:25565`):
```bash
./status.go
```
3. Customize the hostname and port using flags:
```bash
./status.go -host=example.com -port=25565
```
### Example Output
Running either program will output the server status in JSON format. For example:
```json
{
"version": {
"name": "1.20.1",
"protocol": 763
},
"players": {
"online": 5,
"max": 20
},
"description": {
"text": "Welcome to My Minecraft Server!"
},
"favicon": "data:image/png;base64,...",
"ping": 45
}
```
### Command-Line Flags
Both programs support the following flags:
- `-host`: Specifies the server hostname (default: `my-mc.link`).
- `-port`: Specifies the server port (default: `25565` for Java, often `19132` for Bedrock).
## Notes
- The Bedrock program (`statusBedrock.go`) uses a 20-second timeout, while the Java program (`status.go`) uses a 5-second timeout. Adjust these in the source code if needed.
- Ensure the server is online and accessible. Firewalls or network issues may cause errors.
- The `mcstatus-io/mcutil` library handles the protocol details, supporting modern Minecraft server versions.
## Troubleshooting
- **Error: "context deadline exceeded"**: The server is unreachable or took too long to respond. Check the hostname, port, and server status.
- **Error: "json: cannot unmarshal"**: The server response was malformed. Ensure the server is running a compatible version.
- **Dependency issues**: Run `go mod tidy` to resolve missing or outdated dependencies.
## Acknowledgments
- Thanks to [mcstatus-io](https://github.com/mcstatus-io) for the `mcutil` library.
- Inspired by the need for simple, reliable Minecraft server status tools.