RCON Package
This package provides an interface for interacting with Minecraft servers via RCON (Remote Console).
Features
- Connect to Minecraft servers using RCON protocol
- Execute commands on the server
- Set weather, time, and difficulty
- Health checking and connection management
- Timeout support for operations
- Environment variable based configuration
Usage
import "tipsy.codes/charles/mc-god/v2/internal/pkg/rcon"
// Create a new client using environment variables
client, err := rcon.NewFromEnv()
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Execute a command
response, err := client.Execute("list")
if err != nil {
log.Fatal(err)
}
fmt.Println(response)
// Set weather to clear
err = client.SetWeather("clear")
if err != nil {
log.Fatal(err)
}
Environment Variables
The package expects these environment variables to be set:
RCON_ADDRESS- The address of the Minecraft server (e.g., "localhost:25575")RCON_PASSWORD- The RCON password for authentication
Testing
rconmock.go contains a mock rcon server that accepts and logs requests from the user. It can be configured to return errors, or success (empty body strings). It logs the recieved message bodies.
The protocol is described at https://developer.valvesoftware.com/wiki/Source_RCON_Protocol.