mcstatus

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: GPL-3.0 Imports: 19 Imported by: 0

README

MCStatus

A Go library for retrieving the status of a Minecraft server.

Installation

go get -u github.com/PassTheMayo/mcstatus

Documentation

https://pkg.go.dev/github.com/PassTheMayo/mcstatus

Usage

Status
import "github.com/PassTheMayo/mcstatus"

func main() {
    response, err := mcstatus.Status("play.hypixel.net", 25565)

    if err != nil {
        panic(err)
    }

    fmt.Println(response)
}
Bedrock Status
import "github.com/PassTheMayo/mcstatus"

func main() {
    response, err := mcstatus.StatusBedrock("127.0.0.1", 19132)

    if err != nil {
        panic(err)
    }

    fmt.Println(response)
}
Basic Query
import "github.com/PassTheMayo/mcstatus"

func main() {
    response, err := mcstatus.BasicQuery("play.hypixel.net", 25565)

    if err != nil {
        panic(err)
    }

    fmt.Println(response)
}
Full Query
import "github.com/PassTheMayo/mcstatus"

func main() {
    response, err := mcstatus.FullQuery("play.hypixel.net", 25565)

    if err != nil {
        panic(err)
    }

    fmt.Println(response)
}
RCON
import "github.com/PassTheMayo/mcstatus"

func main() {
    client := mcstatus.NewRCON()

    if err := client.Dial("127.0.0.1", 25575); err != nil {
        panic(err)
    }

    if err := client.Login("mypassword"); err != nil {
        panic(err)
    }

    if err := client.Run("say Hello, world!"); err != nil {
        panic(err)
    }

    fmt.Println(<- client.Messages)

    if err := client.Close(); err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnexpectedResponse means the server sent an unexpected response to the client
	ErrUnexpectedResponse = errors.New("received an unexpected response from the server")
	// ErrEmptyBuffer is a generic error for any read methods where the buffer array doesn't contain enough data to read the whole type
	ErrEmptyBuffer = errors.New("packet does not contain enough data to read this type")
	// ErrInvalidBoolean means the server sent a value expected as a boolean but the value was neither 0 or 1
	ErrInvalidBoolean = errors.New("cannot ReadBoolean() as value is neither 0 or 1")
	// ErrVarIntTooBig means the server sent a varint which was beyond the protocol size of a varint
	ErrVarIntTooBig = errors.New("size of VarInt exceeds maximum data size")
	// ErrNotConnected means the client attempted to send data but there was no connection to the server
	ErrNotConnected = errors.New("client attempted to send data but connection is non-existent")
	// ErrAlreadyLoggedIn means the RCON client was already logged in after a second login attempt was made
	ErrAlreadyLoggedIn = errors.New("RCON client is already logged in after a second login attempt was made")
	// ErrInvalidPassword means the password used in the RCON loggin was incorrect
	ErrInvalidPassword = errors.New("incorrect RCON password")
	// ErrNotLoggedIn
	ErrNotLoggedIn = errors.New("RCON client attempted to send message before successful login")
)

Functions

This section is empty.

Types

type BasicQueryResponse

type BasicQueryResponse struct {
	MOTD          Description
	GameType      string
	Map           string
	OnlinePlayers uint64
	MaxPlayers    uint64
	HostPort      uint16
	HostIP        string
}

func BasicQuery

func BasicQuery(host string, port uint16, options ...QueryOptions) (*BasicQueryResponse, error)

BasicQuery runs a query on the server and returns basic information

type BedrockStatusOptions added in v1.2.0

type BedrockStatusOptions struct {
	EnableSRV  bool
	Timeout    time.Duration
	ClientGUID int64
}

type BedrockStatusResponse added in v1.2.0

type BedrockStatusResponse struct {
	ServerGUID      int64       `json:"server_guid"`
	Edition         string      `json:"edition"`
	MOTDLine1       Description `json:"motd_line_1"`
	MOTDLine2       Description `json:"motd_line_2"`
	ProtocolVersion int64       `json:"protocol_version"`
	Version         string      `json:"version"`
	OnlinePlayers   int64       `json:"online_players"`
	MaxPlayers      int64       `json:"max_players"`
	ServerID        uint64      `json:"server_id"`
	Gamemode        string      `json:"gamemode"`
	GamemodeID      int64       `json:"gamemode_id"`
	PortIPv4        uint16      `json:"port_ipv4"`
	PortIPv6        uint16      `json:"port_ipv6"`
	SRVResult       *SRVRecord  `json:"srv_result"`
}

func StatusBedrock added in v1.2.0

func StatusBedrock(host string, port uint16, options ...BedrockStatusOptions) (*BedrockStatusResponse, error)

StatusBedrock retrieves the status of a Bedrock Minecraft server

type Description

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

Description contains helper functions for reading and writing the description

func (Description) Clean added in v1.2.0

func (d Description) Clean() string

Clean returns the description with no formatting

func (Description) HTML

func (d Description) HTML() (string, error)

HTML returns the description with HTML formatting

func (Description) Raw

func (d Description) Raw() string

Raw returns the raw description with formatting

func (Description) String

func (d Description) String() string

String returns the description with formatting

type Favicon

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

Favicon contains helper functions for reading and writing the favicon

func (Favicon) Exists

func (f Favicon) Exists() bool

func (Favicon) Image

func (f Favicon) Image() (image.Image, error)

func (Favicon) SaveToFile

func (f Favicon) SaveToFile(path string) error

func (Favicon) String

func (f Favicon) String() string

type FullQueryResponse

type FullQueryResponse struct {
	Data    map[string]string
	Players []string
}

func FullQuery

func FullQuery(host string, port uint16, options ...QueryOptions) (*FullQueryResponse, error)

FullQuery runs a query on the server and returns the full information

type JavaStatusOptions added in v1.2.0

type JavaStatusOptions struct {
	EnableSRV       bool
	Timeout         time.Duration
	ProtocolVersion int
}

type JavaStatusResponse

type JavaStatusResponse struct {
	Version struct {
		Name     string `json:"name"`
		Protocol int    `json:"protocol"`
	} `json:"version"`
	Players struct {
		Max    int `json:"max"`
		Online int `json:"online"`
		Sample []struct {
			Name string `json:"name"`
			ID   string `json:"id"`
		} `json:"sample"`
	} `json:"players"`
	Description Description `json:"description"`
	Favicon     Favicon     `json:"favicon"`
	SRVResult   *SRVRecord  `json:"srv_result"`
}

func Status

func Status(host string, port uint16, options ...JavaStatusOptions) (*JavaStatusResponse, error)

Status retrieves the status of any Minecraft server

type Packet

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

Packet contains helper functions for reading and writing buffer packets to the TCP stream

func NewPacket

func NewPacket() *Packet

NewPacket creates a new packet with no data

func NewPacketFromReader

func NewPacketFromReader(r io.Reader) *Packet

NewPacketFromReader creates a new packet from the reader

func (*Packet) ReadAllBytes

func (p *Packet) ReadAllBytes() ([]byte, error)

func (*Packet) ReadBoolean

func (p *Packet) ReadBoolean() (bool, error)

func (*Packet) ReadByte

func (p *Packet) ReadByte() (byte, error)

func (*Packet) ReadBytes

func (p *Packet) ReadBytes(length int) ([]byte, error)

func (*Packet) ReadDouble

func (p *Packet) ReadDouble() (float64, error)

func (*Packet) ReadFloat

func (p *Packet) ReadFloat() (float32, error)

func (*Packet) ReadInt

func (p *Packet) ReadInt() (int32, error)

func (*Packet) ReadIntLE

func (p *Packet) ReadIntLE() (int32, error)

func (*Packet) ReadLong

func (p *Packet) ReadLong() (int64, error)

func (*Packet) ReadLongLE

func (p *Packet) ReadLongLE() (int64, error)

func (*Packet) ReadShort

func (p *Packet) ReadShort() (int16, error)

func (*Packet) ReadShortLE

func (p *Packet) ReadShortLE() (int16, error)

func (*Packet) ReadString

func (p *Packet) ReadString() (string, error)

func (*Packet) ReadUnsignedByte

func (p *Packet) ReadUnsignedByte() (uint8, error)

func (*Packet) ReadUnsignedInt

func (p *Packet) ReadUnsignedInt() (uint32, error)

func (*Packet) ReadUnsignedIntLE

func (p *Packet) ReadUnsignedIntLE() (uint32, error)

func (*Packet) ReadUnsignedLong

func (p *Packet) ReadUnsignedLong() (uint64, error)

func (*Packet) ReadUnsignedLongLE

func (p *Packet) ReadUnsignedLongLE() (uint64, error)

func (*Packet) ReadUnsignedShort

func (p *Packet) ReadUnsignedShort() (uint16, error)

func (*Packet) ReadUnsignedShortLE

func (p *Packet) ReadUnsignedShortLE() (uint16, error)

func (*Packet) ReadVarInt

func (p *Packet) ReadVarInt() (int32, error)

func (*Packet) ReadVarLong

func (p *Packet) ReadVarLong() (int64, error)

func (*Packet) WriteBoolean

func (p *Packet) WriteBoolean(val bool) error

func (*Packet) WriteByte

func (p *Packet) WriteByte(val byte) error

func (*Packet) WriteBytes

func (p *Packet) WriteBytes(val []byte) error

func (*Packet) WriteDouble

func (p *Packet) WriteDouble(val float64) error

func (*Packet) WriteFloat

func (p *Packet) WriteFloat(val float32) error

func (*Packet) WriteInt

func (p *Packet) WriteInt(val int32) error

func (*Packet) WriteIntLE

func (p *Packet) WriteIntLE(val int32) error

func (*Packet) WriteLength

func (p *Packet) WriteLength() error

func (*Packet) WriteLong

func (p *Packet) WriteLong(val int64) error

func (*Packet) WriteLongLE

func (p *Packet) WriteLongLE(val int64) error

func (*Packet) WriteShort

func (p *Packet) WriteShort(val int16) error

func (*Packet) WriteShortLE

func (p *Packet) WriteShortLE(val int16) error

func (*Packet) WriteString

func (p *Packet) WriteString(val string) error

func (*Packet) WriteTo

func (p *Packet) WriteTo(w io.Writer) (int64, error)

func (*Packet) WriteUnsignedByte

func (p *Packet) WriteUnsignedByte(val uint8) error

func (*Packet) WriteUnsignedInt

func (p *Packet) WriteUnsignedInt(val uint32) error

func (*Packet) WriteUnsignedIntLE

func (p *Packet) WriteUnsignedIntLE(val uint32) error

func (*Packet) WriteUnsignedLong

func (p *Packet) WriteUnsignedLong(val uint64) error

func (*Packet) WriteUnsignedLongLE

func (p *Packet) WriteUnsignedLongLE(val uint64) error

func (*Packet) WriteUnsignedShort

func (p *Packet) WriteUnsignedShort(val uint16) error

func (*Packet) WriteUnsignedShortLE

func (p *Packet) WriteUnsignedShortLE(val uint16) error

func (*Packet) WriteVarInt

func (p *Packet) WriteVarInt(val int32) error

func (*Packet) WriteVarLong

func (p *Packet) WriteVarLong(val int64) error

type QueryOptions

type QueryOptions struct {
	Timeout   time.Duration
	SessionID int32
}

type RCON

type RCON struct {
	Conn *net.Conn

	Messages chan string
	// contains filtered or unexported fields
}

func NewRCON

func NewRCON() *RCON

NewRCON creates a new RCON client from the options parameter

func (*RCON) Close

func (r *RCON) Close() error

func (*RCON) Dial

func (r *RCON) Dial(host string, port uint16, options ...RCONOptions) error

func (*RCON) Login

func (r *RCON) Login(password string) error

func (*RCON) Run

func (r *RCON) Run(command string) error

type RCONOptions

type RCONOptions struct {
	Timeout time.Duration
}

type SRVRecord

type SRVRecord struct {
	Host string `json:"host"`
	Port uint16 `json:"port"`
}

Jump to

Keyboard shortcuts

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