diff --git a/go.mod b/go.mod index c0121b0..158e777 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/chzyer/readline v1.5.1 github.com/denisbrodbeck/machineid v1.0.1 - github.com/dreamscached/minequery/v2 v2.4.1 + github.com/dreamscached/minequery/v2 v2.5.0 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/shirou/gopsutil v3.21.11+incompatible golang.org/x/image v0.15.0 diff --git a/go.sum b/go.sum index 2a55475..9b12c0b 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= -github.com/dreamscached/minequery/v2 v2.4.1 h1:jRx0oQ80dq6+2a01oHiSm0s3KzLs3cT+9vkAL2tLOHc= -github.com/dreamscached/minequery/v2 v2.4.1/go.mod h1:wKoUWEntOrS1jnJJfq73nkkU8cjNCCQojUHqXAtibZU= +github.com/dreamscached/minequery/v2 v2.5.0 h1:hUkN//4x96xUJ7pz1Cr1Gs7IISXkE3LoNCcXui1AfvY= +github.com/dreamscached/minequery/v2 v2.5.0/go.mod h1:zRAFqhE8tFyRUmwkxu3hoNy6H/shys59bickqJRc/yg= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= @@ -26,17 +26,39 @@ github.com/tklauser/go-sysconf v0.3.13 h1:GBUpcahXSpR2xN01jhkNAbTLRk2Yzgggk8IM08 github.com/tklauser/go-sysconf v0.3.13/go.mod h1:zwleP4Q4OehZHGn4CYZDipCgg9usW5IJePewFCGVEa0= github.com/tklauser/numcpus v0.7.0 h1:yjuerZP127QG9m5Zh/mSO4wqurYil27tHrqwRoRjpr4= github.com/tklauser/numcpus v0.7.0/go.mod h1:bb6dMVcj8A42tSE7i32fsIUCbQNllK5iDguyOZRUzAY= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/vendor/github.com/dreamscached/minequery/v2/MIGRATING.md b/vendor/github.com/dreamscached/minequery/v2/MIGRATING.md index 728d74e..d27bccf 100644 --- a/vendor/github.com/dreamscached/minequery/v2/MIGRATING.md +++ b/vendor/github.com/dreamscached/minequery/v2/MIGRATING.md @@ -5,6 +5,12 @@ versions of it may introduce changes that might be breaking to existing codebase This page will help you migrate your code in order to adapt to changes. +## From v2.4.x + +Version 2.5.0 enables SRV records support which is (to adhere to expected behavior) +enabled *by default*. If you need to stick to v2.4.x behavior, disable it with +`WithPreferSRVRecords` option when creating new `Pinger` instance. + ## From v2.2.x Version 2.3.0 enables query session caching by default. If you need to stick to diff --git a/vendor/github.com/dreamscached/minequery/v2/README.md b/vendor/github.com/dreamscached/minequery/v2/README.md index bca52f8..d17313e 100644 --- a/vendor/github.com/dreamscached/minequery/v2/README.md +++ b/vendor/github.com/dreamscached/minequery/v2/README.md @@ -22,11 +22,14 @@ # 🚀 Migrating from v2 or v1 If you're new to MineQuery, you can skip this part. If you have used it before, you -might want to give it a read if you're planning to switch from v1 or v2.0.x. +might want to give it a read if you're planning to switch from v1, or want to know +about breaking changes in v2.x.x version and how to adapt your codebase. See [MIGRATING.md][1] for help with migrating from MineQuery. -## #️⃣ Minecraft Version Support +## ✨ Features + +### ⛏ Minecraft Version Support MineQuery supports pinging of all versions of Minecraft. @@ -34,15 +37,19 @@ MineQuery supports pinging of all versions of Minecraft. |----------------------|-----------------|-------------|-------------| | ✅ Supported | ✅ Supported | ✅ Supported | ✅ Supported | -### Query Protocol Support +### 📡 Query Protocol Support + +MineQuery v2.1.0+ fully supports [Query][9] protocol. -MineQuery fully supports [Query][9] protocol. +### 🏷 SRV Record Support + +MineQuery v2.5.0+ fully supports SRV records. ## 📚 How to use ### Basic usage -For simple pinging with default parameters, use package-global `Ping*` functions +For simple pinging with default parameters, use package-global `Ping*` functions (where `*` is your respective Minecraft server version.) If you're unsure about version, it is known that Notchian servers respond to @@ -85,10 +92,10 @@ response validation, you can use `Pinger` struct with `PingerOption` passed to i import "github.com/dreamscached/minequery/v2" pinger := minequery.NewPinger( - minequery.WithTimeout(5 * time.Second), - minequery.WithUseStrict(true), - minequery.WithProtocolVersion16(minequery.Ping16ProtocolVersion162), - minequery.WithProtocolVersion17(minequery.Ping17ProtocolVersion172), +minequery.WithTimeout(5 * time.Second), +minequery.WithUseStrict(true), +minequery.WithProtocolVersion16(minequery.Ping16ProtocolVersion162), +minequery.WithProtocolVersion17(minequery.Ping17ProtocolVersion172), ) ``` @@ -127,13 +134,13 @@ to customize this duration, you can use `WithTimeout` option. By default, `Pinger` does not validate response data it receives and silently omits erroneous values it processes (incorrect favicon or bad player UUID). -If you need it to return an error in case of invalid response, you can use +If you need it to return an error in case of invalid response, you can use `WithUseStrict` option. #### WithQueryCacheExpiry -By default, `Pinger` stores query sessions in cache for 30 seconds and flushes expired -entries every 5 minutes. If you want to override these defaults, use `WithQueryCacheExpiry` +By default, `Pinger` stores query sessions in cache for 30 seconds and flushes expired +entries every 5 minutes. If you want to override these defaults, use `WithQueryCacheExpiry` option. #### WithQueryCacheDisabled @@ -142,6 +149,13 @@ By default, `Pinger` stores query sessions in cache, reusing sessions and securi and saving bandwidth. If you don't want to use session cache, use `WithQueryCacheDisabled` option. +#### WithQueryCache + +By default, `Pinger` stores query sessions using `patrickmn/go-cache` library +(and `WithQueryCacheExpiry`/`WithQueryCacheDisabled` only affect this implementation of +cache for Go). If you wish to use other cache implementation, you can use any that +implements `Cache` interface. + #### WithProtocolVersion16 By default, `Pinger` sends protocol version 74 in 1.6 ping packets. If you need @@ -163,21 +177,29 @@ use this option to provide an `Unmarshaller` implementation that will be used in #### WithImageDecoder By default, `Pinger` uses standard Go `png.Decode` function to decode PNG from binary stream. -If you need to use another decoding library, you can use this option to provide +If you need to use another decoding library, you can use this option to provide `png.Decode`-compatible function that will be used instead. #### WithImageEncoding By default, `Pinger` uses standard Go `base64.StdEncoding` encoding to decode Base64 string -returned in 1.7+ responses. If you need to use another encoding, you can use this option to +returned in 1.7+ responses. If you need to use another encoding, you can use this option to provide a compatible implementation that will be used instead. [1]: MIGRATING.md + [2]: https://wiki.vg/Server_List_Ping#Beta_1.8_to_1.3 + [3]: https://wiki.vg/Server_List_Ping#1.4_to_1.5 + [4]: https://wiki.vg/Server_List_Ping#1.6 + [5]: https://wiki.vg/Server_List_Ping#Current + [6]: https://github.com/dreamscached/minequery/issues/25 + [7]: https://pkg.go.dev/github.com/dreamscached/minequery/v2 + [8]: #basic-usage + [9]: https://wiki.vg/Query diff --git a/vendor/github.com/dreamscached/minequery/v2/cache.go b/vendor/github.com/dreamscached/minequery/v2/cache.go new file mode 100644 index 0000000..09412bf --- /dev/null +++ b/vendor/github.com/dreamscached/minequery/v2/cache.go @@ -0,0 +1,13 @@ +package minequery + +// Cache is a common interface for various cache implementations +// to provide abstract layer for other caching libraries. +type Cache interface { + // Get retrieves value by cache key, either returning the value + // itself and true as second return value or nil and false correspondingly. + Get(string) (interface{}, bool) + + // SetDefault sets value by cache key with default TTL and expiration + // configuration parameters. + SetDefault(string, interface{}) +} diff --git a/vendor/github.com/dreamscached/minequery/v2/io.go b/vendor/github.com/dreamscached/minequery/v2/io.go index 4a9945b..6bf2955 100644 --- a/vendor/github.com/dreamscached/minequery/v2/io.go +++ b/vendor/github.com/dreamscached/minequery/v2/io.go @@ -12,6 +12,8 @@ var ( utf16BEDecoder = unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewDecoder() ) +// readAllUntilZero reads all bytes from reader until it hits zero. +// This is a backport from newer Go stdlib for sake of minequery's compatibility with Go 1.13. func readAllUntilZero(reader io.ByteReader) ([]byte, error) { buf := &bytes.Buffer{} @@ -31,3 +33,24 @@ func readAllUntilZero(reader io.ByteReader) ([]byte, error) { } } } + +// readAll reads all bytes from reader. +// This is a backport from newer Go stdlib for sake of minequery's compatibility with Go 1.13. +func readAll(r io.Reader) ([]byte, error) { + b := make([]byte, 0, 512) + for { + n, err := r.Read(b[len(b):cap(b)]) + b = b[:len(b)+n] + if err != nil { + if err == io.EOF { + err = nil + } + return b, err + } + + if len(b) == cap(b) { + // Add more capacity (let append pick how much). + b = append(b, 0)[:len(b)] + } + } +} diff --git a/vendor/github.com/dreamscached/minequery/v2/net.go b/vendor/github.com/dreamscached/minequery/v2/net.go index 713513f..fedcf3a 100644 --- a/vendor/github.com/dreamscached/minequery/v2/net.go +++ b/vendor/github.com/dreamscached/minequery/v2/net.go @@ -1,6 +1,7 @@ package minequery import ( + "errors" "fmt" "net" "strings" @@ -58,6 +59,30 @@ func (p *Pinger) openUDPConnWithLocalAddr(host string, remotePort int, localAddr return conn, nil } +// resolveSRV performs SRV lookup of a Minecraft server hostname. +// +// In case there are no records found, an empty string, a zero port and nil error are returned. +// +// In case when there is more than one record, the hostname and port of the first record with +// the least weight is returned. +func (p *Pinger) resolveSRV(host string) (string, uint16, error) { + _, records, err := net.LookupSRV("minecraft", "tcp", host) + if err != nil { + var dnsError *net.DNSError + if errors.As(err, &dnsError) && dnsError.IsNotFound { + return "", 0, nil + } + + return "", 0, err + } + + if len(records) == 0 { + return "", 0, nil + } + target := records[0] + return target.Target, target.Port, nil +} + func shouldWrapIPv6(host string) bool { return len(host) >= 2 && !(host[0] == '[' && host[1] == ']') && strings.Count(host, ":") >= 2 } diff --git a/vendor/github.com/dreamscached/minequery/v2/ping_14.go b/vendor/github.com/dreamscached/minequery/v2/ping_14.go index a769466..9dcf988 100644 --- a/vendor/github.com/dreamscached/minequery/v2/ping_14.go +++ b/vendor/github.com/dreamscached/minequery/v2/ping_14.go @@ -39,6 +39,14 @@ func Ping14(host string, port int) (*Status14, error) { // Ping14 pings 1.4 to 1.6 (exclusively) Minecraft servers (Notchian servers of more late versions also respond to // this ping packet.) func (p *Pinger) Ping14(host string, port int) (*Status14, error) { + status, err := p.pingGeneric(p.ping14, host, port) + if err != nil { + return nil, err + } + return status.(*Status14), nil +} + +func (p *Pinger) ping14(host string, port int) (interface{}, error) { conn, err := p.openTCPConn(host, port) if err != nil { return nil, err diff --git a/vendor/github.com/dreamscached/minequery/v2/ping_16.go b/vendor/github.com/dreamscached/minequery/v2/ping_16.go index d0d62e3..01d7ece 100644 --- a/vendor/github.com/dreamscached/minequery/v2/ping_16.go +++ b/vendor/github.com/dreamscached/minequery/v2/ping_16.go @@ -446,6 +446,14 @@ func Ping16(host string, port int) (*Status16, error) { // Ping16 pings 1.6 to 1.7 (exclusively) Minecraft servers (Notchian servers of more late versions also respond // to this ping packet.) func (p *Pinger) Ping16(host string, port int) (*Status16, error) { + status, err := p.pingGeneric(p.ping16, host, port) + if err != nil { + return nil, err + } + return status.(*Status16), nil +} + +func (p *Pinger) ping16(host string, port int) (interface{}, error) { conn, err := p.openTCPConn(host, port) if err != nil { return nil, err diff --git a/vendor/github.com/dreamscached/minequery/v2/ping_17.go b/vendor/github.com/dreamscached/minequery/v2/ping_17.go index b4aaf48..b627015 100644 --- a/vendor/github.com/dreamscached/minequery/v2/ping_17.go +++ b/vendor/github.com/dreamscached/minequery/v2/ping_17.go @@ -26,6 +26,201 @@ const Ping17ProtocolVersionUndefined int32 = -1 //goland:noinspection GoUnusedConst const ( + // Ping17ProtocolVersion1202 holds a protocol version (=764) for Minecraft 1.20.2 + Ping17ProtocolVersion1202 int32 = 764 + + // Ping17ProtocolVersion1202rc2 holds a protocol version (=1073741977) for Minecraft 1.20.2-rc2 + Ping17ProtocolVersion1202rc2 int32 = 1073741977 + + // Ping17ProtocolVersion1202rc1 holds a protocol version (=1073741976) for Minecraft 1.20.2-rc1 + Ping17ProtocolVersion1202rc1 int32 = 1073741976 + + // Ping17ProtocolVersion1202pre4 holds a protocol version (=1073741975) for Minecraft 1.20.2-pre4 + Ping17ProtocolVersion1202pre4 int32 = 1073741975 + + // Ping17ProtocolVersion1202pre3 holds a protocol version (=1073741974) for Minecraft 1.20.2-pre3 + Ping17ProtocolVersion1202pre3 int32 = 1073741974 + + // Ping17ProtocolVersion1202pre2 holds a protocol version (=1073741973) for Minecraft 1.20.2-pre2 + Ping17ProtocolVersion1202pre2 int32 = 1073741973 + + // Ping17ProtocolVersion1202pre1 holds a protocol version (=1073741972) for Minecraft 1.20.2-pre1 + Ping17ProtocolVersion1202pre1 int32 = 1073741972 + + // Ping17ProtocolVersion23w35a holds a protocol version (=1073741971) for Minecraft 23w35a + Ping17ProtocolVersion23w35a int32 = 1073741971 + + // Ping17ProtocolVersion23w33a holds a protocol version (=1073741970) for Minecraft 23w33a + Ping17ProtocolVersion23w33a int32 = 1073741970 + + // Ping17ProtocolVersion23w32a holds a protocol version (=1073741969) for Minecraft 23w32a + Ping17ProtocolVersion23w32a int32 = 1073741969 + + // Ping17ProtocolVersion23w31a holds a protocol version (=1073741968) for Minecraft 23w31a + Ping17ProtocolVersion23w31a int32 = 1073741968 + + // Ping17ProtocolVersion1201 holds a protocol version (=763) for Minecraft 1.20.1 + Ping17ProtocolVersion1201 int32 = 763 + + // Ping17ProtocolVersion1201rc1 holds a protocol version (=1073741966) for Minecraft 1.20.1-rc1 + Ping17ProtocolVersion1201rc1 int32 = 1073741966 + + // Ping17ProtocolVersion120 holds a protocol version (=763) for Minecraft 1.20 + Ping17ProtocolVersion120 int32 = 763 + + // Ping17ProtocolVersion120rc1 holds a protocol version (=1073741965) for Minecraft 1.20-rc1 + Ping17ProtocolVersion120rc1 int32 = 1073741965 + + // Ping17ProtocolVersion120pre7 holds a protocol version (=1073741964) for Minecraft 1.20-pre7 + Ping17ProtocolVersion120pre7 int32 = 1073741964 + + // Ping17ProtocolVersion120pre6 holds a protocol version (=1073741963) for Minecraft 1.20-pre6 + Ping17ProtocolVersion120pre6 int32 = 1073741963 + + // Ping17ProtocolVersion120pre5 holds a protocol version (=1073741962) for Minecraft 1.20-pre5 + Ping17ProtocolVersion120pre5 int32 = 1073741962 + + // Ping17ProtocolVersion120pre4 holds a protocol version (=1073741961) for Minecraft 1.20-pre4 + Ping17ProtocolVersion120pre4 int32 = 1073741961 + + // Ping17ProtocolVersion120pre3 holds a protocol version (=1073741960) for Minecraft 1.20-pre3 + Ping17ProtocolVersion120pre3 int32 = 1073741960 + + // Ping17ProtocolVersion120pre2 holds a protocol version (=1073741959) for Minecraft 1.20-pre2 + Ping17ProtocolVersion120pre2 int32 = 1073741959 + + // Ping17ProtocolVersion120pre1 holds a protocol version (=1073741958) for Minecraft 1.20-pre1 + Ping17ProtocolVersion120pre1 int32 = 1073741958 + + // Ping17ProtocolVersion23w18a holds a protocol version (=1073741957) for Minecraft 23w18a + Ping17ProtocolVersion23w18a int32 = 1073741957 + + // Ping17ProtocolVersion23w17a holds a protocol version (=1073741956) for Minecraft 23w17a + Ping17ProtocolVersion23w17a int32 = 1073741956 + + // Ping17ProtocolVersion23w16a holds a protocol version (=1073741955) for Minecraft 23w16a + Ping17ProtocolVersion23w16a int32 = 1073741955 + + // Ping17ProtocolVersion23w14a holds a protocol version (=1073741954) for Minecraft 23w14a + Ping17ProtocolVersion23w14a int32 = 1073741954 + + // Ping17ProtocolVersion23w13a holds a protocol version (=1073741952) for Minecraft 23w13a + Ping17ProtocolVersion23w13a int32 = 1073741952 + + // Ping17ProtocolVersion23w12a holds a protocol version (=1073741951) for Minecraft 23w12a + Ping17ProtocolVersion23w12a int32 = 1073741951 + + // Ping17ProtocolVersion1194 holds a protocol version (=762) for Minecraft 1.19.4 + Ping17ProtocolVersion1194 int32 = 762 + + // Ping17ProtocolVersion1194rc3 holds a protocol version (=1073741950) for Minecraft 1.19.4-rc3 + Ping17ProtocolVersion1194rc3 int32 = 1073741950 + + // Ping17ProtocolVersion1194rc2 holds a protocol version (=1073741949) for Minecraft 1.19.4-rc2 + Ping17ProtocolVersion1194rc2 int32 = 1073741949 + + // Ping17ProtocolVersion1194rc1 holds a protocol version (=1073741948) for Minecraft 1.19.4-rc1 + Ping17ProtocolVersion1194rc1 int32 = 1073741948 + + // Ping17ProtocolVersion1194pre4 holds a protocol version (=1073741947) for Minecraft 1.19.4-pre4 + Ping17ProtocolVersion1194pre4 int32 = 1073741947 + + // Ping17ProtocolVersion1194pre3 holds a protocol version (=1073741946) for Minecraft 1.19.4-pre3 + Ping17ProtocolVersion1194pre3 int32 = 1073741946 + + // Ping17ProtocolVersion1194pre2 holds a protocol version (=1073741945) for Minecraft 1.19.4-pre2 + Ping17ProtocolVersion1194pre2 int32 = 1073741945 + + // Ping17ProtocolVersion1194pre1 holds a protocol version (=1073741944) for Minecraft 1.19.4-pre1 + Ping17ProtocolVersion1194pre1 int32 = 1073741944 + + // Ping17ProtocolVersion23w07a holds a protocol version (=1073741943) for Minecraft 23w07a + Ping17ProtocolVersion23w07a int32 = 1073741943 + + // Ping17ProtocolVersion23w06a holds a protocol version (=1073741942) for Minecraft 23w06a + Ping17ProtocolVersion23w06a int32 = 1073741942 + + // Ping17ProtocolVersion23w05a holds a protocol version (=1073741941) for Minecraft 23w05a + Ping17ProtocolVersion23w05a int32 = 1073741941 + + // Ping17ProtocolVersion23w04a holds a protocol version (=1073741940) for Minecraft 23w04a + Ping17ProtocolVersion23w04a int32 = 1073741940 + + // Ping17ProtocolVersion23w03a holds a protocol version (=1073741939) for Minecraft 23w03a + Ping17ProtocolVersion23w03a int32 = 1073741939 + + // Ping17ProtocolVersion1193 holds a protocol version (=761) for Minecraft 1.19.3 + Ping17ProtocolVersion1193 int32 = 761 + + // Ping17ProtocolVersion1193rc3 holds a protocol version (=1073741938) for Minecraft 1.19.3-rc3 + Ping17ProtocolVersion1193rc3 int32 = 1073741938 + + // Ping17ProtocolVersion1193rc2 holds a protocol version (=1073741937) for Minecraft 1.19.3-rc2 + Ping17ProtocolVersion1193rc2 int32 = 1073741937 + + // Ping17ProtocolVersion1193rc1 holds a protocol version (=1073741936) for Minecraft 1.19.3-rc1 + Ping17ProtocolVersion1193rc1 int32 = 1073741936 + + // Ping17ProtocolVersion1193pre3 holds a protocol version (=1073741935) for Minecraft 1.19.3-pre3 + Ping17ProtocolVersion1193pre3 int32 = 1073741935 + + // Ping17ProtocolVersion1193pre2 holds a protocol version (=1073741934) for Minecraft 1.19.3-pre2 + Ping17ProtocolVersion1193pre2 int32 = 1073741934 + + // Ping17ProtocolVersion1193pre1 holds a protocol version (=1073741933) for Minecraft 1.19.3-pre1 + Ping17ProtocolVersion1193pre1 int32 = 1073741933 + + // Ping17ProtocolVersion22w46a holds a protocol version (=1073741932) for Minecraft 22w46a + Ping17ProtocolVersion22w46a int32 = 1073741932 + + // Ping17ProtocolVersion22w45a holds a protocol version (=1073741931) for Minecraft 22w45a + Ping17ProtocolVersion22w45a int32 = 1073741931 + + // Ping17ProtocolVersion22w44a holds a protocol version (=1073741930) for Minecraft 22w44a + Ping17ProtocolVersion22w44a int32 = 1073741930 + + // Ping17ProtocolVersion22w43a holds a protocol version (=1073741929) for Minecraft 22w43a + Ping17ProtocolVersion22w43a int32 = 1073741929 + + // Ping17ProtocolVersion22w42a holds a protocol version (=1073741928) for Minecraft 22w42a + Ping17ProtocolVersion22w42a int32 = 1073741928 + + // Ping17ProtocolVersion1192 holds a protocol version (=760) for Minecraft 1.19.2 + Ping17ProtocolVersion1192 int32 = 760 + + // Ping17ProtocolVersion1192rc2 holds a protocol version (=1073741927) for Minecraft 1.19.2-rc2 + Ping17ProtocolVersion1192rc2 int32 = 1073741927 + + // Ping17ProtocolVersion1192rc1 holds a protocol version (=1073741926) for Minecraft 1.19.2-rc1 + Ping17ProtocolVersion1192rc1 int32 = 1073741926 + + // Ping17ProtocolVersion1191 holds a protocol version (=760) for Minecraft 1.19.1 + Ping17ProtocolVersion1191 int32 = 760 + + // Ping17ProtocolVersion1191rc3 holds a protocol version (=1073741925) for Minecraft 1.19.1-rc3 + Ping17ProtocolVersion1191rc3 int32 = 1073741925 + + // Ping17ProtocolVersion1191rc2 holds a protocol version (=1073741924) for Minecraft 1.19.1-rc2 + Ping17ProtocolVersion1191rc2 int32 = 1073741924 + + // Ping17ProtocolVersion1191pre6 holds a protocol version (=1073741923) for Minecraft 1.19.1-pre6 + Ping17ProtocolVersion1191pre6 int32 = 1073741923 + + // Ping17ProtocolVersion1191pre5 holds a protocol version (=1073741922) for Minecraft 1.19.1-pre5 + Ping17ProtocolVersion1191pre5 int32 = 1073741922 + + // Ping17ProtocolVersion1191pre4 holds a protocol version (=1073741921) for Minecraft 1.19.1-pre4 + Ping17ProtocolVersion1191pre4 int32 = 1073741921 + + // Ping17ProtocolVersion1191pre3 holds a protocol version (=1073741920) for Minecraft 1.19.1-pre3 + Ping17ProtocolVersion1191pre3 int32 = 1073741920 + + // Ping17ProtocolVersion1191pre2 holds a protocol version (=1073741919) for Minecraft 1.19.1-pre2 + Ping17ProtocolVersion1191pre2 int32 = 1073741919 + + // Ping17ProtocolVersion1191rc1 holds a protocol version (=1073741918) for Minecraft 1.19.1-rc1 + Ping17ProtocolVersion1191rc1 int32 = 1073741918 + // Ping17ProtocolVersion1191pre1 holds a protocol version (=1073741917) for Minecraft 1.19.1-pre1. Ping17ProtocolVersion1191pre1 int32 = 1073741917 @@ -1745,6 +1940,14 @@ func Ping17(host string, port int) (*Status17, error) { // Ping17 pings 1.7+ Minecraft servers. func (p *Pinger) Ping17(host string, port int) (*Status17, error) { + status, err := p.pingGeneric(p.ping17, host, port) + if err != nil { + return nil, err + } + return status.(*Status17), nil +} + +func (p *Pinger) ping17(host string, port int) (interface{}, error) { conn, err := p.openTCPConn(host, port) if err != nil { return nil, err diff --git a/vendor/github.com/dreamscached/minequery/v2/ping_beta18.go b/vendor/github.com/dreamscached/minequery/v2/ping_beta18.go index 82a51c9..b692dcc 100644 --- a/vendor/github.com/dreamscached/minequery/v2/ping_beta18.go +++ b/vendor/github.com/dreamscached/minequery/v2/ping_beta18.go @@ -41,6 +41,14 @@ func PingBeta18(host string, port int) (*StatusBeta18, error) { // PingBeta18 pings Beta 1.8 to Release 1.4 (exclusively) Minecraft servers (Notchian servers of more late versions // also respond to this ping packet.) func (p *Pinger) PingBeta18(host string, port int) (*StatusBeta18, error) { + status, err := p.pingGeneric(p.pingBeta18, host, port) + if err != nil { + return nil, err + } + return status.(*StatusBeta18), nil +} + +func (p *Pinger) pingBeta18(host string, port int) (interface{}, error) { conn, err := p.openTCPConn(host, port) if err != nil { return nil, err diff --git a/vendor/github.com/dreamscached/minequery/v2/ping_generic.go b/vendor/github.com/dreamscached/minequery/v2/ping_generic.go new file mode 100644 index 0000000..5810086 --- /dev/null +++ b/vendor/github.com/dreamscached/minequery/v2/ping_generic.go @@ -0,0 +1,50 @@ +package minequery + +// defaultMinecraftPort is a default port Minecraft server runs on and which +// will be used when server port is left as zero value. +const defaultMinecraftPort = 25565 + +// pingGeneric accepts version-specific ping function and host/port pair. Then it performs +// (if necessary, see PreferSRVRecord) SRV lookup, and attempts to use the SRV record hostname and port +// (first returned record is used if more than one is returned, see net.LookupSRV documentation) +// to ping, if lookup fails or ping fails, the provided hostname/port pair is used directly. +func (p *Pinger) pingGeneric(pingFn func(string, int) (interface{}, error), host string, port int) (interface{}, error) { + // Use default Minecraft port if port is 0 + if port == 0 { + port = defaultMinecraftPort + } + + if p.PreferSRVRecord { + // When SRV record is preferred, try resolving it + srvHost, srvPort, err := p.resolveSRV(host) + if err != nil { + if p.UseStrict { + // If UseStrict, SRV lookup error is fatal + return nil, err + } + + // If not UseStrict, continue pinging on the desired host/port + + } else { + // If SRV lookup is successful, check if there are any records + if srvHost != "" { + status, err := pingFn(srvHost, int(srvPort)) + if err != nil { + // If pinging on the SRV record failed and UseStrict is set, + // this is fatal enough to raise an error + if p.UseStrict { + return nil, err + } + + } else { + // Success, SRV record ping passed + return status, nil + } + } + + } + } + + // Otherwise just ping normally + return pingFn(host, port) +} diff --git a/vendor/github.com/dreamscached/minequery/v2/pinger.go b/vendor/github.com/dreamscached/minequery/v2/pinger.go index 96e88f0..ea3c585 100644 --- a/vendor/github.com/dreamscached/minequery/v2/pinger.go +++ b/vendor/github.com/dreamscached/minequery/v2/pinger.go @@ -39,6 +39,15 @@ func WithUseStrict(useStrict bool) PingerOption { return func(p *Pinger) { p.UseStrict = useStrict } } +// WithPreferSRVRecord sets Pinger PreferSRVRecord to the provided value. +// +//goland:noinspection GoUnusedExportedFunction +func WithPreferSRVRecord(preferSRV bool) PingerOption { + return func(p *Pinger) { + p.PreferSRVRecord = preferSRV + } +} + // WithProtocolVersion16 sets Pinger ProtocolVersion16 value. // //goland:noinspection GoUnusedExportedFunction @@ -57,7 +66,9 @@ func WithProtocolVersion17(version int32) PingerOption { } } -// WithQueryCacheExpiry sets Pinger Cache expiry and purge duration values. +// WithQueryCacheExpiry sets Pinger cache expiry and purge duration values. +// This function uses go-cache library; consider using WithQueryCache for +// custom implementations that implement Cache interface. // //goland:noinspection GoUnusedExportedFunction func WithQueryCacheExpiry(expire, purge time.Duration) PingerOption { @@ -66,6 +77,15 @@ func WithQueryCacheExpiry(expire, purge time.Duration) PingerOption { } } +// WithQueryCache sets Pinger cache instance that will be used for server query. +// +//goland:noinspection GoUnusedExportedFunction +func WithQueryCache(cache Cache) PingerOption { + return func(p *Pinger) { + p.SessionCache = cache + } +} + // WithQueryCacheDisabled disables Pinger cache used for server query. // //goland:noinspection GoUnusedExportedFunction @@ -115,12 +135,16 @@ type Pinger struct { Timeout time.Duration // SessionCache holds query protocol sessions in order to reuse them instead of creating new each time. - SessionCache *cache.Cache + SessionCache Cache // UseStrict is a configuration value that defines if tolerable errors (in server ping/query responses) // that are by default silently ignored should be actually returned as errors. UseStrict bool + // PreferSRVRecord is a configuration value that defines if Pinger will prefer SRV records, which is the + // default behavior of Minecraft clients. + PreferSRVRecord bool + // UnmarshalFunc is the function used to unmarshal JSON (used by Ping17 for responses from 1.7+ servers). // By default, it uses json.Unmarshal function. UnmarshalFunc UnmarshalFunc @@ -151,6 +175,7 @@ func newDefaultPinger() *Pinger { WithDialer(&net.Dialer{})(p) WithQueryCacheExpiry(30*time.Second, 5*time.Minute)(p) WithTimeout(15 * time.Second)(p) + WithPreferSRVRecord(true)(p) WithUnmarshaller(json.Unmarshal)(p) WithImageEncoding(base64.StdEncoding)(p) WithImageDecoder(png.Decode)(p) diff --git a/vendor/github.com/dreamscached/minequery/v2/query.go b/vendor/github.com/dreamscached/minequery/v2/query.go index 9d7e402..f911c68 100644 --- a/vendor/github.com/dreamscached/minequery/v2/query.go +++ b/vendor/github.com/dreamscached/minequery/v2/query.go @@ -371,7 +371,7 @@ func (p *Pinger) writeQueryFullStatPacket(conn *net.UDPConn, sessionID int32, to func (p *Pinger) parseQueryHandshakeResponse(reader io.Reader) (int32, error) { // Read all the remaining data in packet and ensure it has NUL terminator (if UseStrict) - token, _ := io.ReadAll(reader) + token, _ := readAll(reader) if len(token) == 0 { return 0, fmt.Errorf("challenge token is empty") } @@ -392,7 +392,7 @@ func (p *Pinger) parseQueryHandshakeResponse(reader io.Reader) (int32, error) { func (p *Pinger) parseQueryBasicStatResponse(reader io.Reader) (*BasicQueryStatus, error) { // Read all the remaining data and ensure it has NUL terminator (if UseStrict) - data, _ := io.ReadAll(reader) + data, _ := readAll(reader) if len(data) == 0 { return nil, fmt.Errorf("%w: empty response body", ErrInvalidStatus) } @@ -437,7 +437,7 @@ func (p *Pinger) parseQueryBasicStatResponse(reader io.Reader) (*BasicQueryStatu } // Read host as byte sequence - hostBytes, err := io.ReadAll(remReader) + hostBytes, err := readAll(remReader) if err != nil { return nil, err } @@ -454,7 +454,7 @@ func (p *Pinger) parseQueryBasicStatResponse(reader io.Reader) (*BasicQueryStatu func (p *Pinger) parseQueryFullStatResponse(reader io.Reader) (*FullQueryStatus, error) { // Read all the remaining data and ensure it has NUL terminator (if UseStrict) - data, _ := io.ReadAll(reader) + data, _ := readAll(reader) if len(data) == 0 { return nil, fmt.Errorf("%w: empty response body", ErrInvalidStatus) } diff --git a/vendor/github.com/dreamscached/minequery/v2/util.go b/vendor/github.com/dreamscached/minequery/v2/util.go index 28f08f1..dbc8408 100644 --- a/vendor/github.com/dreamscached/minequery/v2/util.go +++ b/vendor/github.com/dreamscached/minequery/v2/util.go @@ -10,10 +10,13 @@ import ( var errStackEmpty = errors.New("stack is empty") +// stack provides a simple array-based stack implementation for internal use within minequery. type stack []interface{} +// Push pushes an item on top of the stack. func (s *stack) Push(value interface{}) { *s = append(*s, value) } +// Pop removes an item from the top of the stack, returning errStackEmpty if stack is empty. func (s *stack) Pop() (interface{}, error) { if len(*s) == 0 { return nil, errStackEmpty diff --git a/vendor/modules.txt b/vendor/modules.txt index 68ce768..fa78936 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,7 +4,7 @@ github.com/chzyer/readline # github.com/denisbrodbeck/machineid v1.0.1 ## explicit github.com/denisbrodbeck/machineid -# github.com/dreamscached/minequery/v2 v2.4.1 +# github.com/dreamscached/minequery/v2 v2.5.0 ## explicit; go 1.13 github.com/dreamscached/minequery/v2 # github.com/go-ole/go-ole v1.3.0