Skip to content

Commit

Permalink
Merge pull request #9 from mcstatus-io/v4
Browse files Browse the repository at this point in the history
Merge v4 into main
  • Loading branch information
PassTheMayo authored Jul 18, 2024
2 parents 4d1a60a + 9323756 commit 427b3bc
Show file tree
Hide file tree
Showing 36 changed files with 727 additions and 665 deletions.
166 changes: 83 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ A zero-dependency library for interacting with the Minecraft protocol in Go. Sup
## Installation

```bash
go get github.com/mcstatus-io/mcutil/v3
go get github.com/mcstatus-io/mcutil/v4
```

## Documentation

https://pkg.go.dev/github.com/mcstatus-io/mcutil/v3
https://pkg.go.dev/github.com/mcstatus-io/mcutil/v4

## Usage

Expand All @@ -23,25 +23,25 @@ Retrieves the status of the Java Edition Minecraft server. This method only work

```go
import (
"context"
"fmt"
"time"
"context"
"fmt"
"time"

"github.com/mcstatus-io/mcutil/v3"
"github.com/mcstatus-io/mcutil/v4/status"
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)

defer cancel()
defer cancel()

response, err := mcutil.Status(ctx, "play.hypixel.net", 25565)
response, err := status.Modern(ctx, "demo.mcstatus.io")

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}

fmt.Println(response)
fmt.Println(response)
}
```

Expand All @@ -51,25 +51,25 @@ Retrieves the status of the Java Edition Minecraft server. This is a legacy meth

```go
import (
"context"
"fmt"
"time"
"context"
"fmt"
"time"

"github.com/mcstatus-io/mcutil/v3"
"github.com/mcstatus-io/mcutil/v4/status"
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)

defer cancel()
defer cancel()

response, err := mcutil.StatusLegacy(ctx, "play.hypixel.net", 25565)
response, err := status.Legacy(ctx, "demo.mcstatus.io")

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}

fmt.Println(response)
fmt.Println(response)
}
```

Expand All @@ -79,25 +79,25 @@ Retrieves the status of the Bedrock Edition Minecraft server.

```go
import (
"context"
"fmt"
"time"
"context"
"fmt"
"time"

"github.com/mcstatus-io/mcutil/v3"
"github.com/mcstatus-io/mcutil/v4/status"
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)

defer cancel()
defer cancel()

response, err := mcutil.StatusBedrock(ctx, "127.0.0.1", 19132)
response, err := status.Bedrock(ctx, "demo.mcstatus.io")

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}

fmt.Println(response)
fmt.Println(response)
}
```

Expand All @@ -107,25 +107,25 @@ Performs a basic query lookup on the server, retrieving most information about t

```go
import (
"context"
"fmt"
"time"
"context"
"fmt"
"time"

"github.com/mcstatus-io/mcutil/v3"
"github.com/mcstatus-io/mcutil/v4/query"
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)

defer cancel()
defer cancel()

response, err := mcutil.BasicQuery(ctx, "play.hypixel.net", 25565)
response, err := query.Basic(ctx, "play.hypixel.net")

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}

fmt.Println(response)
fmt.Println(response)
}

```
Expand All @@ -136,25 +136,25 @@ Performs a full query lookup on the server, retrieving all available information

```go
import (
"context"
"fmt"
"time"
"context"
"fmt"
"time"

"github.com/mcstatus-io/mcutil/v3"
"github.com/mcstatus-io/mcutil/v4/query"
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)

defer cancel()
defer cancel()

response, err := mcutil.FullQuery(ctx, "play.hypixel.net", 25565)
response, err := query.Full(ctx, "play.hypixel.net")

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}

fmt.Println(response)
fmt.Println(response)
}
```

Expand All @@ -163,14 +163,14 @@ func main() {
Executes remote console commands on the server. You must know the connection details of the RCON server, as well as the password.

```go
import "github.com/mcstatus-io/mcutil/v3/rcon"
import "github.com/mcstatus-io/mcutil/v4/rcon"

func main() {
client, err := rcon.Connect("127.0.0.1", 25575)
client, err := rcon.Dial("127.0.0.1", 25575)

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}

if err := client.Login("mypassword"); err != nil {
panic(err)
Expand All @@ -194,36 +194,36 @@ Sends a Votifier vote to the specified server, typically used by server listing

```go
import (
"context"
"time"
"context"
"time"

"github.com/mcstatus-io/mcutil/v3"
"github.com/mcstatus-io/mcutil/v3/options"
"github.com/mcstatus-io/mcutil/v4/vote"
"github.com/mcstatus-io/mcutil/v4/options"
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)

defer cancel()
defer cancel()

err := mcutil.SendVote(ctx, "127.0.0.1", 8192, options.Vote{
// General
ServiceName: "my-service", // Required
Username: "PassTheMayo", // Required
Timestamp: time.Now(), // Required
Timeout: time.Second * 5, // Required
err := vote.SendVote(ctx, "127.0.0.1", 8192, options.Vote{
// General
ServiceName: "my-service", // Required
Username: "PassTheMayo", // Required
Timestamp: time.Now(), // Required
Timeout: time.Second * 5, // Required

// Votifier 1
PublicKey: "...", // Required
// Votifier 1
PublicKey: "...", // Required

// Votifier 2
Token: "abc123", // Required
UUID: "", // Optional
})
// Votifier 2
Token: "abc123", // Required
UUID: "", // Optional
})

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}
}
```

Expand Down
56 changes: 15 additions & 41 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"
"time"

"github.com/jessevdk/go-flags"
"github.com/mcstatus-io/mcutil/v3"
"github.com/mcstatus-io/mcutil/v3/options"
"github.com/mcstatus-io/mcutil/v4/options"
"github.com/mcstatus-io/mcutil/v4/status"
)

var (
host string
port uint16
opts Options = Options{}
opts passedOptions = passedOptions{}
)

type Options struct {
type passedOptions struct {
Type string `short:"t" long:"type" description:"The type of status to retrieve" default:"java"`
Timeout uint `short:"T" long:"timeout" description:"The amount of seconds before the status retrieval times out" default:"5"`
DisableSRV bool `short:"S" long:"disable-srv" description:"Disables SRV lookup"`
Expand All @@ -45,35 +43,6 @@ func init() {
}

host = args[0]

if len(args) < 2 {
switch opts.Type {
case "java", "legacy", "raw":
{
port = 25565

break
}
case "bedrock":
{
port = 19132

break
}
default:
{
fmt.Printf("unknown --type value: %s\n", opts.Type)
}
}
} else {
value, err := strconv.ParseUint(args[1], 10, 16)

if err != nil {
panic(err)
}

port = uint16(value)
}
}

func main() {
Expand All @@ -89,7 +58,7 @@ func main() {
switch opts.Type {
case "java":
{
result, err = mcutil.Status(ctx, host, port, options.JavaStatus{
result, err = status.Modern(ctx, host, options.StatusModern{
EnableSRV: !opts.DisableSRV,
Timeout: time.Duration(opts.Timeout) * time.Second,
ProtocolVersion: 47,
Expand All @@ -99,7 +68,7 @@ func main() {
}
case "raw":
{
result, err = mcutil.StatusRaw(ctx, host, port, options.JavaStatus{
result, err = status.ModernRaw(ctx, host, options.StatusModern{
EnableSRV: !opts.DisableSRV,
Timeout: time.Duration(opts.Timeout) * time.Second,
ProtocolVersion: 47,
Expand All @@ -109,7 +78,7 @@ func main() {
}
case "legacy":
{
result, err = mcutil.StatusLegacy(ctx, host, port, options.JavaStatusLegacy{
result, err = status.Legacy(ctx, host, options.StatusLegacy{
EnableSRV: !opts.DisableSRV,
Timeout: time.Duration(opts.Timeout) * time.Second,
ProtocolVersion: 47,
Expand All @@ -119,13 +88,18 @@ func main() {
}
case "bedrock":
{
result, err = mcutil.StatusBedrock(ctx, host, port, options.BedrockStatus{
EnableSRV: !opts.DisableSRV,
Timeout: time.Duration(opts.Timeout) * time.Second,
result, err = status.Bedrock(ctx, host, options.StatusBedrock{
Timeout: time.Duration(opts.Timeout) * time.Second,
})

break
}
default:
{
fmt.Printf("unknown --type value: %s\n", opts.Type)

return
}
}

if err != nil {
Expand Down
Loading

0 comments on commit 427b3bc

Please sign in to comment.