bedrock

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: 7 Imported by: 1

Documentation

Overview

bedrock package implements the unconnected ping sequence of the raknet protocol (used by minecraft bedrock servers). This package is strictly compliant with the following documentation : https://wiki.vg/Raknet_Protocol.

Index

Constants

View Source
const (
	UnconnectedPingPacketID byte = 0x01
	UnconnectedPongPacketID byte = 0x1C
)

Variables

View Source
var (
	ErrInvalidPacketType error = errors.New("invalid packet type")
	ErrInvalidMagic      error = errors.New("invalid magic")

	RaknetMagic = [16]byte{0x00, 0xff, 0xff, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0x12, 0x34, 0x56, 0x78}
)

Functions

This section is empty.

Types

type PingClient

type PingClient struct {
	ClientGUID uint64

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

PingClient is the bedrock ping client.

func NewClient

func NewClient(hostname string, port int) *PingClient

NewClient returns a well-formed *PingClient. ClientGUID is set to a random value.

func (*PingClient) Connect

func (client *PingClient) Connect() error

Connect establishes a connection via UDP.

func (*PingClient) Disconnect

func (client *PingClient) Disconnect() error

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

func (*PingClient) UnconnectedPing

func (client *PingClient) UnconnectedPing() (UnconnectedPong, int, error)

Handshake sends an unconncted ping request to the server, and returns the pong response informations.

type UnconnectedPong

type UnconnectedPong struct {
	GameName         string `json:"gameName"`
	MOTD             string `json:"motd"`
	ProtocolVersion  int    `json:"protocolVersion"`
	MinecraftVersion string `json:"minecraftVersion"`
	OnlinePlayers    int    `json:"onlinePlayers"`
	MaxPlayers       int    `json:"maxPlayers"`
	ServerID         string `json:"serverId"`
	LevelName        string `json:"levelName"`
	GameMode         string `json:"gameMode"`
	GameModeNumeric  int    `json:"gameModeNumeric"`
	IPv4Port         int    `json:"ipv4Port"`
	IPv6Port         int    `json:"ipv6Port"`
}

UnconnectedPong contains unconnected pong informations.

func Ping

func Ping(hostname string, port int) (UnconnectedPong, int, error)

Ping returns the server infos, and latency of a minecraft bedrock server. If an error occurred at any point of the process, an empty pong response, a latency of -1, and a non nil error are returned.

Jump to

Keyboard shortcuts

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