The mclib
package provides utilities for interacting with Minecraft servers using the Server List Ping (SLP) protocol.
It includes functionality to query Minecraft servers for status and latency information.
To use this package in your Go project, simply install it:
go get github.com/sch8ill/mclib
MCServer
represents a Minecraft server with its address and client. It provides methods to retrieve server status and
perform a status ping.
package main
import (
"github.com/sch8ill/mclib/server"
)
func main() {
srv, err := server.New("example.com:25565")
if err != nil {
// handle error
}
}
res, err := srv.StatusPing()
if err != nil {
// handle error
}
fmt.Printf("version: %s\n", res.Version.Name)
fmt.Printf("protocol: %d\n", res.Version.Protocol)
fmt.Printf("online players: %d\n", res.Players.Online)
fmt.Printf("max players: %d\n", res.Players.Max)
fmt.Printf("sample players: %+q\n", res.Players.Sample)
fmt.Printf("description: %s\n", res.Description.String())
fmt.Printf("latency: %dms\n", res.Latency)
// ...
latency, err := srv.ping()
if err != nil {
// handle error
}
fmt.Printf("latency: %dms\n", latency)
requires:
make
go >= 1.20
build:
make build && mv build/mcli mcli
mclib
also provides a simple command line interface:
-addr string
the server address (default "localhost")
-srv
whether a srv lookup should be made (default true)
-timeout duration
the connection timeout (default 5s)
For example:
mcli --addr hypixel.net --timeout 10s
This package is licensed under the MIT License.