1.7 KiB
1.7 KiB
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
Methods
New(address, password)- Create a new RCON clientExecute(command)- Execute a command on the serverSetWeather(weather)- Set the weather (clear, rain, thunder)SetTime(timeValue)- Set the time (day, night, noon, midnight, or numeric)SetDifficulty(difficulty)- Set the difficulty level (peaceful, easy, normal, hard)GetServerInfo()- Get server version informationClose()- Close the RCON connectionHealthCheck()- Verify the connection is workingExecuteWithTimeout()- Execute command with timeoutConnectWithTimeout()- Connect with timeoutGetEnvCredentials()- Get credentials from environmentNewFromEnv()- Create client from environment variables