Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sch8ill committed Mar 20, 2024
1 parent 86fc544 commit c7b4176
Showing 1 changed file with 57 additions and 36 deletions.
93 changes: 57 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

---

The `mclib` package provides utilities for interacting with Minecraft servers using the Server List Ping (SLP) protocol.
The `mclib` package provides utilities for interacting with Minecraft servers using
the [Minecraft protocol](https://wiki.vg/Protocol).
It includes functionality to query Minecraft servers for status and latency information.
`mclib` is also capable of determining the software a server is running on by using fingerprinting techniques.

---

## Installation

Expand All @@ -20,57 +24,70 @@ go get github.com/sch8ill/mclib

## Usage

### MCServer

`MCServer` represents a Minecraft server with its address and client. It provides methods to retrieve server status and
perform a status ping.

#### Creating an MCServer Instance
### StatusPing

```go
package main

import (
"github.com/sch8ill/mclib/server"
"fmt"

"github.com/sch8ill/mclib"
)

func main() {
srv, err := server.New("example.com:25565")
if err != nil {
// handle error
}
client, _ := mclib.NewClient("2b2t.org")
res, _ := client.StatusPing()

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)
}
```

#### StatusPing

```go
res, err := srv.StatusPing()
if err != nil {
// handle error
}
#### output

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)
// ...
```text
version: Velocity 1.7.2-1.20.4
protocol: 47
online players: 571
max players: 1
sample players: [{"Fit" "fdee323e-7f0c-4c15-8d1c-0f277442342a"}]
description: 2B Updated to 1.19! 2T
latency: 8ms
```

#### Ping
### Fingerprint

```go
latency, err := srv.ping()
if err != nil {
// handle error
package main

import (
"fmt"

"github.com/sch8ill/mclib/fingerprint"
)

func main() {
software, _ := fingerprint.Fingerprint("localhost")
fmt.Printf("software fingerprint: %s\n", software)
}
```

#### output

fmt.Printf("latency: %dms\n", latency)
```text
software fingerprint: craftbukkit
```

Further documentation can be found on [pkg.go.dev](https://pkg.go.dev/github.com/sch8ill/mclib).

---

### Cli

#### Build
Expand All @@ -79,13 +96,11 @@ requires:

```
make
go >= 1.20
go >= 1.22
```

build:

```bash
make build && mv build/mcli mcli
make build
```

#### Usage
Expand All @@ -95,6 +110,10 @@ make build && mv build/mcli mcli
```
-addr string
the server address (default "localhost")
-fingerprint
whether a software fingerprint should be performed on the server (default true)
-protocol int
the protocol version number the client should use (default 760)
-srv
whether a srv lookup should be made (default true)
-timeout duration
Expand All @@ -107,6 +126,8 @@ For example:
mcli --addr hypixel.net --timeout 10s
```

---

## License

This package is licensed under the [MIT License](LICENSE).
Expand Down

0 comments on commit c7b4176

Please sign in to comment.