minecraft

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenMC

func ListenMC(addr string) (*mcnet.Listener, error)

ListenMC listens on a minecraft port

Types

type Client

type Client struct {
	*mcnet.Conn

	ProtocolVersion int32
}

Client is a minecraft protocol aware connection somewhat

func (*Client) Handshake

func (c *Client) Handshake() (*Handshake, error)

Handshake reads the handshake packet and returns the next state

func (*Client) ReadLoginStart

func (c *Client) ReadLoginStart() (*LoginStart, *pk.Packet, error)

ReadLoginStart reads the login start packet from the client. It returns the parsed packet, the original packet, and an error if one occurred.

This should not be trusted as the client can send any string they want and hasn't been authenticated until later in the login process.

func (*Client) SendDisconnect

func (c *Client) SendDisconnect(reason string) error

SendDisconnect sends a disconnect packet to the client with the provided reason

func (*Client) SendStatus

func (c *Client) SendStatus(status *Status) error

SendStatus sends status request and ping packets to the client

type ClientState

type ClientState int

ClientState is the state of the client during the handshake process

const (
	// ClientStateCheck is when a client is attempting to check the status
	// of the server
	ClientStateCheck ClientState = iota + 1

	// ClientStatePlayerLogin is the state of the client when trying to login to
	// the server
	ClientStatePlayerLogin
)

Contains definitions for the ClientState type

type Handshake

type Handshake struct {
	// Packet is the original packet that was sent, and consumed, by the
	// proxy.
	Packet *pk.Packet

	// ProtocolVersion is the version of the Minecraft protocol the client
	// is using.
	ProtocolVersion int32

	// ServerAddress is the address of the server the client is trying to
	// connect to. If there are any NULL characters, they are
	// automatically stripped as well as all content after them. This is
	// to handle the case of Forge servers where the server address is
	// suffixed with \0x00FML3\0x00.
	ServerAddress string

	// ServerPort is the port of the server the client is trying to
	// connect to.
	ServerPort uint16

	// NextState is the next state the client is trying to transition to.
	NextState int32
}

Handshake is the first packet sent to a Minecraft server.

See: https://wiki.vg/Protocol#Handshaking

type LoginStart

type LoginStart struct {
	Name string `json:"name"`
}

LoginStart is the packet sent by the client when they're trying to login to the server.

See https://wiki.vg/Protocol#Login_Start.

type Status

type Status struct {
	Version     *StatusVersion     `json:"version"`
	Players     *StatusPlayers     `json:"players"`
	Description *StatusDescription `json:"description"`
	Favicon     string             `json:"favicon"`
}

func GetServerStatus

func GetServerStatus(addr string, port uint) (*Status, error)

GetServerStatus returns a server's status

type StatusDescription

type StatusDescription struct {
	Text string `json:"text"`
}

type StatusPlayers

type StatusPlayers struct {
	Max    int           `json:"max"`
	Online int           `json:"online"`
	Sample []interface{} `json:"sample"`
}

type StatusVersion

type StatusVersion struct {
	Name     string `json:"name"`
	Protocol int    `json:"protocol"`
}

Jump to

Keyboard shortcuts

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