diff --git a/status/bedrock.go b/status/bedrock.go index d384914..64f5962 100644 --- a/status/bedrock.go +++ b/status/bedrock.go @@ -57,11 +57,12 @@ func Bedrock(ctx context.Context, host string, options ...options.StatusBedrock) } func getStatusBedrock(host string, options ...options.StatusBedrock) (*response.StatusBedrock, error) { - opts := parseBedrockStatusOptions(options...) + var ( + opts = parseBedrockStatusOptions(options...) + connectionPort uint16 = uint16(util.DefaultBedrockPort) + ) - connectionPort := uint16(util.DefaultBedrockPort) - - connectionHost, port, err := util.ParseAddress(host) + connectionHostname, port, err := util.ParseAddress(host) if err != nil { return nil, err @@ -71,7 +72,7 @@ func getStatusBedrock(host string, options ...options.StatusBedrock) (*response. connectionPort = *port } - conn, err := net.DialTimeout("udp", fmt.Sprintf("%s:%d", connectionHost, connectionPort), opts.Timeout) + conn, err := net.DialTimeout("udp", fmt.Sprintf("%s:%d", connectionHostname, connectionPort), opts.Timeout) if err != nil { return nil, err diff --git a/status/legacy.go b/status/legacy.go index 6690345..a39898d 100644 --- a/status/legacy.go +++ b/status/legacy.go @@ -53,24 +53,23 @@ func Legacy(ctx context.Context, host string, options ...options.StatusLegacy) ( } func getStatusLegacy(host string, options ...options.StatusLegacy) (*response.StatusLegacy, error) { - opts := parseJavaStatusLegacyOptions(options...) - var ( + opts = parseJavaStatusLegacyOptions(options...) connectionPort uint16 = util.DefaultJavaPort srvRecord *response.SRVRecord = nil ) - connectionHost, port, err := util.ParseAddress(host) + connectionHostname, port, err := util.ParseAddress(host) if err != nil { return nil, err } - if opts.EnableSRV && port == nil && net.ParseIP(connectionHost) == nil { + if opts.EnableSRV && port == nil && net.ParseIP(connectionHostname) == nil { record, err := util.LookupSRV(host) if err == nil && record != nil { - connectionHost = record.Target + connectionHostname = record.Target connectionPort = record.Port srvRecord = &response.SRVRecord{ @@ -80,7 +79,7 @@ func getStatusLegacy(host string, options ...options.StatusLegacy) (*response.St } } - conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", connectionHost, connectionPort), opts.Timeout) + conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", connectionHostname, connectionPort), opts.Timeout) if err != nil { return nil, err diff --git a/status/modern.go b/status/modern.go index 6b7eeb7..7e41df6 100644 --- a/status/modern.go +++ b/status/modern.go @@ -91,26 +91,25 @@ func Modern(ctx context.Context, host string, options ...options.StatusModern) ( } func getStatusModern(host string, options ...options.StatusModern) (*response.StatusModern, error) { - opts := parseJavaStatusOptions(options...) - var ( + opts = parseJavaStatusOptions(options...) connectionPort uint16 = util.DefaultJavaPort srvRecord *response.SRVRecord = nil rawResponse rawJavaStatus = rawJavaStatus{} latency time.Duration = 0 ) - connectionHost, port, err := util.ParseAddress(host) + connectionHostname, port, err := util.ParseAddress(host) if err != nil { return nil, err } - if opts.EnableSRV && port == nil && net.ParseIP(connectionHost) == nil { + if opts.EnableSRV && port == nil && net.ParseIP(connectionHostname) == nil { record, err := util.LookupSRV(host) if err == nil && record != nil { - connectionHost = record.Target + connectionHostname = record.Target connectionPort = record.Port srvRecord = &response.SRVRecord{ @@ -120,7 +119,7 @@ func getStatusModern(host string, options ...options.StatusModern) (*response.St } } - conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", connectionHost, connectionPort), opts.Timeout) + conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", connectionHostname, connectionPort), opts.Timeout) if err != nil { return nil, err @@ -132,7 +131,7 @@ func getStatusModern(host string, options ...options.StatusModern) (*response.St return nil, err } - if err = writeJavaStatusHandshakeRequestPacket(conn, int32(opts.ProtocolVersion), host, 0); err != nil { + if err = writeJavaStatusHandshakeRequestPacket(conn, int32(opts.ProtocolVersion), connectionHostname, connectionPort); err != nil { return nil, err } diff --git a/status/modern_raw.go b/status/modern_raw.go index 68b5be6..5d9071a 100644 --- a/status/modern_raw.go +++ b/status/modern_raw.go @@ -41,32 +41,29 @@ func ModernRaw(ctx context.Context, host string, options ...options.StatusModern } func getStatusRaw(host string, options ...options.StatusModern) (map[string]interface{}, error) { - opts := parseJavaStatusOptions(options...) - var ( + opts = parseJavaStatusOptions(options...) connectionPort uint16 = util.DefaultJavaPort result map[string]interface{} = make(map[string]interface{}) payload int64 = rand.Int63() ) - // Parse the provided host into a split hostname and port. - connectionHost, port, err := util.ParseAddress(host) + connectionHostname, port, err := util.ParseAddress(host) if err != nil { return nil, err } - // Perform an SRV lookup on the - if opts.EnableSRV && port == nil && net.ParseIP(connectionHost) == nil { + if opts.EnableSRV && port == nil && net.ParseIP(connectionHostname) == nil { record, err := util.LookupSRV(host) if err == nil && record != nil { - connectionHost = record.Target + connectionHostname = record.Target connectionPort = record.Port } } - conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", connectionHost, connectionPort), opts.Timeout) + conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", connectionHostname, connectionPort), opts.Timeout) if err != nil { return nil, err @@ -78,7 +75,7 @@ func getStatusRaw(host string, options ...options.StatusModern) (map[string]inte return nil, err } - if err = writeJavaStatusHandshakeRequestPacket(conn, int32(opts.ProtocolVersion), host, connectionPort); err != nil { + if err = writeJavaStatusHandshakeRequestPacket(conn, int32(opts.ProtocolVersion), connectionHostname, connectionPort); err != nil { return nil, err } diff --git a/status/modern_test.go b/status/modern_test.go index 8b20489..4b54ec8 100644 --- a/status/modern_test.go +++ b/status/modern_test.go @@ -8,7 +8,7 @@ import ( ) func TestModern(t *testing.T) { - resp, err := status.Modern(context.Background(), "demo.mcstatus.io") + resp, err := status.Modern(context.Background(), "play.cobbletwo.com") if err != nil { t.Fatal(err)