mcstatus/client/status.go

32 lines
638 B
Go
Raw Normal View History

package client
import (
"time"
"git.0cd.xyz/michael/mcstatus/mcstatuspb"
)
// GetStatus gets minecraft server status
func (client *Client) GetStatus() (*mcstatuspb.Response, error) {
2022-06-22 03:05:10 +00:00
if err := client.write(); err != nil {
return nil, err
}
2022-06-22 03:05:10 +00:00
resp, err := client.read()
if err != nil {
return nil, err
}
return resp, nil
}
// PingServer pings Minecraft server
func (client *Client) PingServer() (time.Duration, error) {
ping := make([]byte, 1)
start := time.Now()
2022-06-22 03:05:10 +00:00
if _, err := client.Conn.Write([]byte{0x01, 0x00}); err != nil {
return 0, err
}
2022-06-22 03:05:10 +00:00
client.Conn.Read(ping[:])
diff := time.Since(start)
return diff, nil
}