mcstatus/client/status.go
2022-06-22 04:05:10 +01:00

32 lines
638 B
Go

package client
import (
"time"
"git.0cd.xyz/michael/mcstatus/mcstatuspb"
)
// GetStatus gets minecraft server status
func (client *Client) GetStatus() (*mcstatuspb.Response, error) {
if err := client.write(); err != nil {
return nil, err
}
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()
if _, err := client.Conn.Write([]byte{0x01, 0x00}); err != nil {
return 0, err
}
client.Conn.Read(ping[:])
diff := time.Since(start)
return diff, nil
}