query

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2023 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

query package implements the mincraft query protocol. This package is strictly compliant with the following documentation : https://wiki.vg/Query.

Index

Constants

View Source
const (
	MagicValue uint16 = 65277
)

Variables

View Source
var (
	FullStatRequestPadding   = [4]byte{0x00, 0x00, 0x00, 0x00}
	FullStatResponsePadding1 = [11]byte{0x73, 0x70, 0x6C, 0x69, 0x74, 0x6E, 0x75, 0x6D, 0x00, 0x80, 0x00}
	FullStatResponsePadding2 = [10]byte{0x01, 0x70, 0x6C, 0x61, 0x79, 0x65, 0x72, 0x5F, 0x00, 0x00}
)

Functions

This section is empty.

Types

type BasicStat

type BasicStat struct {
	MOTD       string `json:"motd"`
	GameType   string `json:"gameType"`
	Map        string `json:"map"`
	NumPlayers int    `json:"numPlayers"`
	MaxPlayers int    `json:"maxPlayers"`
	HostPort   int    `json:"hostPort"`
	HostIP     string `json:"hostIp"`
}

BasicStat contains basic stat query informations.

func QueryBasic

func QueryBasic(hostname string, port int) (BasicStat, error)

QueryBasic returns the basic stat of a minecraft server. If an error occured at any point of the process, an empty BasicStat and a non nil error are returned.

type FullStat

type FullStat struct {
	Properties    map[string]string `json:"properties"`
	OnlinePlayers []string          `json:"onlinePlayers"`
}

FullStat contains full stat query informations.

func QueryFull

func QueryFull(hostname string, port int) (FullStat, error)

QueryFull returns the full stat of a minecraft server. If an error occured at any point of the process, an empty FullStat and a non nil error are returned.

type QueryClient

type QueryClient struct {

	// options
	SkipSRVLookup                bool
	ForceUDPProtocolForSRVLookup bool
	DialTimeout                  time.Duration
	ReadTimeout                  time.Duration
	// contains filtered or unexported fields
}

QueryClient is the query client. challengeToken isn't stored in the client as it can change in the lifetime of a client, while session ID doesn't.

func NewClient

func NewClient(hostname string, port int) *QueryClient

NewClient returns a well-formed *QueryClient.

func (*QueryClient) BasicStat

func (client *QueryClient) BasicStat(challengeToken uint32) (BasicStat, error)

BasicStat sends a basic stat query to the server, and returns the formatted result.

func (*QueryClient) Connect

func (client *QueryClient) Connect() error

Connect establishes a connection via UDP.

func (*QueryClient) Disconnect

func (client *QueryClient) Disconnect() error

Disconnect closes the connection. Connection is made not usable anymore no matter if the it closed properly or not.

func (*QueryClient) FullStat

func (client *QueryClient) FullStat(challengeToken uint32) (FullStat, error)

FullStat sends a full stat query to the server, and returns the formatted result.

func (*QueryClient) Handshake

func (client *QueryClient) Handshake() (uint32, error)

Handshake sends a handshake query to the server, and returns the challenge token if successful.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL