query

package module
v0.0.0-...-a3a9e5a Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2018 License: GPL-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Query

A Go package to send and receive queries from a Minecraft server

Documentation

Index

Constants

View Source
const (
	Challenge  = 0x09
	Statistics = 0x00
)
View Source
const (
	GameId = "MINECRAFTPE"
)

Variables

View Source
var Header = []byte{0xfe, 0xfd}

Header is the header of each query.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles the sequence of incoming queries.

func NewManager

func NewManager() Manager

NewManager returns a new query manager with the given server.

func (*Manager) HandleQuery

func (manager *Manager) HandleQuery(query *Query)

HandleQuery handles an incoming query.

func (*Manager) SetQueryResult

func (manager *Manager) SetQueryResult(result Result)

SetQueryResult sets the query result data a query will receive when querying us.

type Query

type Query struct {
	*binutils.Stream
	Address string
	Port    uint16

	Header  byte
	QueryId int32
	Token   []byte

	Statistics []byte

	IsShort bool
	Data    []byte
}

Query is used to encode/decode queries.

func New

func New(address string, port uint16) *Query

NewQuery returns a new query with an address and port.

func NewFromRaw

func NewFromRaw(buffer []byte, addr *net.UDPAddr) *Query

NewQueryFromRaw returns a query from a raw packet.

func (*Query) DecodeClient

func (query *Query) DecodeClient()

DecodeClient decodes a query sent by the server.

func (*Query) DecodeServer

func (query *Query) DecodeServer()

DecodeServer decodes the query sent by the client.

func (*Query) EncodeClient

func (query *Query) EncodeClient()

EncodeClient encodes a query to send to the server.

func (*Query) EncodeServer

func (query *Query) EncodeServer()

EncodeServer encodes the query to send to the client.

type Result

type Result struct {
	MOTD           string
	ListPlugins    bool
	PluginNames    []string
	PlayerNames    []string
	GameMode       string
	Version        string
	ServerEngine   string
	WorldName      string
	OnlinePlayers  int
	MaximumPlayers int
	Whitelist      string
	Port           uint16
	Address        string
}

Result is a struct containing all information received by querying a server. Results should be constructed in order to send too.

func Send

func Send(address string, port uint16, timeout time.Duration) (Result, error)

Send queries a server with the given address and port. The call times out after the given timeout duration if no response is given.

NOTE: This function is time consuming and should be used one a different goroutine where adequate.

func (Result) GetLong

func (result Result) GetLong() []byte

GetLong returns the long encoded query result.

func (Result) GetShort

func (result Result) GetShort() []byte

GetShort returns the short encoded query result.

func (Result) ParseLong

func (result Result) ParseLong(data []byte) Result

ParseLong parses an encoded long query result.

Jump to

Keyboard shortcuts

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