ping

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

ping package implements the mincraft Server List Ping protocol. This package is strictly compliant with the following documentation : https://wiki.vg/Server_List_Ping.

Index

Constants

View Source
const (
	UnknownProtocolVersion int32  = -1
	HandshakePacketID      uint32 = 0
	PingPacketID           uint32 = 1
)

Variables

View Source
var (
	CommonLegacyRequest           [2]byte  = [2]byte{0xFE, 0x01}
	PluginMessagePacketIdentifier byte     = 0xFA
	SingleByteIdentifierValue     byte     = 0xFF
	Post1_3Padding                [6]byte  = [6]byte{0x00, 0xA7, 0x00, 0x31, 0x00, 0x00}
	Post1_3Delimiter              [2]byte  = [2]byte{0x00, 0x00}
	Pre1_3Delimiter               [2]byte  = [2]byte{0x00, 0xA7}
	MCPingHostStringWithLength    [24]byte = [24]byte{0x00, 0x0B, 0x00, 0x4D, 0x00, 0x43, 0x00, 0x7C, 0x00, 0x50, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x48, 0x00, 0x6F, 0x00, 0x73, 0x00, 0x74} // MC|PingHost string, UTF16BE encoded, preceded by its length in characters as a short
	ProtocolNumber1_6_4           byte     = 78
)
View Source
var (
	ErrInvalidPacketType error = errors.New("invalid packet type")
)
View Source
var (
	ErrMalformedPacket error = errors.New("malformed packet")
)

Functions

This section is empty.

Types

type Handshake

type Handshake struct {
	Properties JSON `json:"properties"`
}

Handshake contains SLP handshake informations.

type Infos added in v1.1.0

type Infos struct {
	Version     infosVersion `json:"version"`
	Players     infosPlayers `json:"players"`
	Description string       `json:"description"`
	Favicon     string       `json:"favicon"`
}

Infos represents usual informations contained in ping response.

type JSON added in v1.1.0

type JSON map[string]interface{}

JSON is an alias for map[string]interface{} that allows extracting data to an Infos struct.

func Ping

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

Ping returns the server list ping infos (JSON-like object), and latency of a minecraft server. If an error occured at any point of the process, an nil json response, a latency of -1, and a non nil error are returned.

func (*JSON) Infos added in v1.1.0

func (m *JSON) Infos() Infos

Infos extracts informations from ping response properties (JSON), and put it into an Infos structure.

type LegacyPingInfos added in v1.1.0

type LegacyPingInfos struct {
	ProtocolVersion  int    `json:"protocolVersion"`
	MinecraftVersion string `json:"minecraftVersion"`
	MOTD             string `json:"motd"`
	OnlinePlayers    int    `json:"onlinePlayers"`
	MaxPlayers       int    `json:"maxPlayers"`
}

LegacyPingInfos contains legacy SLP informations.

func PingLegacy added in v1.1.0

func PingLegacy(hostname string, port int) (LegacyPingInfos, int, error)

PingLegacy returns the legacy server list ping infos, and latency of a minecraft server. If an error occured at any point of the process, an empty response, a latency of -1, and a non nil error are returned. If the minecraft server has a version <= 1.3, ProtocolNumber and MinecraftVersion are not set.

func PingLegacy1_6_4 added in v1.1.0

func PingLegacy1_6_4(hostname string, port int) (LegacyPingInfos, int, error)

PingLegacy1_6_4 returns the legacy server list ping infos (using 1.6+ SLP protocol), and latency of a minecraft server. If an error occured at any point of the process, an empty response, a latency of -1, and a non nil error are returned. If the minecraft server has a version <= 1.3, ProtocolNumber and MinecraftVersion are not set.

type PingClient

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

PingClient is the ping client.

func NewClient

func NewClient(hostname string, port int) *PingClient

NewClient returns a well-formed *PingClient.

func (*PingClient) Connect

func (client *PingClient) Connect() error

Connect establishes a connection via TCP.

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) Handshake

func (client *PingClient) Handshake() (Handshake, error)

Handshake sends a handshake request to the server, and returns the formatted result.

func (*PingClient) Ping

func (client *PingClient) Ping() (int, error)

Ping sends a ping request to the server, and returns the latency in ms. A ping request must be done after a handshake request has already been done.

func (*PingClient) SetDialOptions

func (client *PingClient) SetDialOptions(dialOptions networking.DialTCPOptions)

SetDialOptions sets the options used in the dial process of the connection.

type PingClientLegacy added in v1.1.0

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

PingClientLegacy is the legacy ping client.

func NewClientLegacy added in v1.1.0

func NewClientLegacy(hostname string, port int) *PingClientLegacy

NewClientLegacy returns a well-formed *LegacyPingClient.

func (*PingClientLegacy) Connect added in v1.1.0

func (client *PingClientLegacy) Connect() error

Connect establishes a connection via TCP.

func (*PingClientLegacy) Disconnect added in v1.1.0

func (client *PingClientLegacy) Disconnect() error

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

func (*PingClientLegacy) Ping added in v1.1.0

func (client *PingClientLegacy) Ping() (LegacyPingInfos, int, error)

Ping sends a legacy ping request to the server, and returns various informations about the server, and the latency in ms. If the minecraft server has a version <= 1.3, ProtocolNumber and MinecraftVersion are not set.

func (*PingClientLegacy) Ping1_6_4 added in v1.1.0

func (client *PingClientLegacy) Ping1_6_4() (LegacyPingInfos, int, error)

Ping1_6_4 sends a legacy ping request to the server (using 1.6+ SLP protocol), and returns various informations about the server, and the latency in ms. If the minecraft server has a version <= 1.3, ProtocolNumber and MinecraftVersion are not set.

func (*PingClientLegacy) SetDialOptions added in v1.1.0

func (client *PingClientLegacy) SetDialOptions(dialOptions networking.DialTCPOptions)

SetDialOptions sets the options used in the dial process of the connection.

Jump to

Keyboard shortcuts

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