mcproto

package module
v0.0.0-...-889dc37 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: MIT Imports: 12 Imported by: 0

README

MCProto

Work in progress Minecraft protocol library in Go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnectionState  = errors.New("connection has invalid state for packet type")
	ErrDirection        = errors.New("packet being sent in wrong direction")
	ErrLegacyServerPing = errors.New("not implemented: legacy server ping")
)

Functions

func ResolveServerAddress

func ResolveServerAddress(ctx context.Context, address string) string

Types

type Connection

type Connection interface {
	ReadPacket() (packet.Packet, error)
	WritePacket(packet.Packet) error
	SetReadDeadline(time.Time) error
	SetWriteDeadline(time.Time) error
	Close() error
	SetState(state game.ConnectionState)
}

Connection represents a connection to a Minecraft server or client.

func Dial

func Dial(address string, opts ...Option) (Connection, string, error)

Dial connects to the specified address and creates a new Connection for it. Returns the connection & the address that was connected to.

See DialContext for more information.

func DialContext

func DialContext(ctx context.Context, address string, opts ...Option) (Connection, string, error)

DialContext creates a TCP connection with specified address and creates a new Connection for it. If no port is specified, the Minecraft default of 25565 will be used.

Just like the vanilla Minecraft client, DialContext will do an SRV DNS lookup before connecting to a Minecraft server with the default port. If an SRV record is found, the contained target and port will be used to connect instead.

The provided Context must be non-nil. If the context expires before the connection is established, an error is returned. Once successfully connected, any expiration of this context will not affect the connection.

The given options will be applied to the created connection.

Will return the created Connection and the resolved address that was connected to.

func Wrap

func Wrap(conn net.Conn, opts ...Option) Connection

Wrap wraps the given connection with a Connection, so it can be used for sending/receiving Minecraft packets.

Wrap defaults its side to ServerSide, which means it will interpret incoming packets as being server-bound. If you are using Wrap for the client side, use the WithSide option to configure this. Wrap will also default the connection state to packet.HandshakeState. If you are wrapping a connection which is in a different state, use the WithState option to configure this.

The given options will be applied to the created connection.

type Logger

type Logger interface {
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
}

type Option

type Option func(conn *connection)

Option is a configuration option for mcproto.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger configures the logger for mcproto.

func WithPackets

func WithPackets(packets []packet.Packet) Option

WithPackets allows you to add custom packets to mcproto's packet registry. This will make mcproto automatically parse the packet when it is received.

func WithSide

func WithSide(side Side) Option

WithSide configures the connection side of the mcproto Connection.

func WithState

func WithState(state game.ConnectionState) Option

type Side

type Side uint8

Side is the side of a Minecraft connection

const (
	ClientSide Side = iota // Client
	ServerSide             // Server
)

func (Side) ReadDirection

func (s Side) ReadDirection() packet.Direction

func (Side) String

func (i Side) String() string

func (Side) WriteDirection

func (s Side) WriteDirection() packet.Direction

type UnknownPacketError

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

func (UnknownPacketError) Error

func (u UnknownPacketError) Error() string

Directories

Path Synopsis
examples
tools

Jump to

Keyboard shortcuts

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