protocol

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BufferPool = sync.Pool{
	New: func() interface{} {
		return bytes.NewBuffer(make([]byte, 0, 256))
	},
}

BufferPool is a sync.Pool for buffers used to write compressed data to.

View Source
var CompressPool = sync.Pool{
	New: func() interface{} {
		w, _ := flate.NewWriter(ioutil.Discard, 6)
		return w
	},
}

CompressPool is a sync.Pool for writeCloseResetter flate readers. These are pooled for connections.

View Source
var DecompressPool = sync.Pool{
	New: func() interface{} {
		return flate.NewReader(bytes.NewReader(nil))
	},
}

DecompressPool is a sync.Pool for io.ReadCloser flate readers. These are pooled for connections.

Functions

func MarshalPacket

func MarshalPacket(pk Packet) ([]byte, error)

func UnmarshalPacket

func UnmarshalPacket(b []byte, pk Packet) error

func Varuint32

func Varuint32(src io.ByteReader, x *uint32) error

Types

type DecodeReader

type DecodeReader interface {
	io.Reader
	io.ByteReader
}

type Decoder

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

func NewDecoder

func NewDecoder(reader io.Reader) *Decoder

NewDecoder returns a new decoder decoding data from the io.Reader passed. One read call from the reader is assumed to consume an entire packet.

func (*Decoder) Decode

func (decoder *Decoder) Decode() (packets [][]byte, err error)

Decode decodes one 'packet' from the io.Reader passed in NewDecoder(), producing a slice of packets that it held and an error if not successful.

type Disconnect

type Disconnect struct {
	// HideDisconnectionScreen specifies if the disconnection screen should be hidden when the client is
	// disconnected, meaning it will be sent directly to the main menu.
	HideDisconnectionScreen bool
	// Message is an optional message to show when disconnected. This message is only written if the
	// HideDisconnectionScreen field is set to true.
	Message string
}

Disconnect may be sent by the server to disconnect the client using an optional message to send as the disconnect screen.

func (*Disconnect) ID

func (*Disconnect) ID() uint32

ID ...

func (*Disconnect) Marshal

func (pk *Disconnect) Marshal(w *Writer)

Marshal ...

func (*Disconnect) Unmarshal

func (pk *Disconnect) Unmarshal(buf *Reader) error

Unmarshal ...

type EncodeReader

type EncodeReader interface {
	io.Writer
	io.ByteWriter
}

type Encoder

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

Encoder handles the encoding of Minecraft packets that are sent to an io.Writer. The packets are compressed and optionally encoded before they are sent to the io.Writer.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new Encoder for the io.Writer passed. Each final packet produced by the Encoder is sent with a single call to io.Writer.Write().

func (*Encoder) Encode

func (encoder *Encoder) Encode(packet []byte) error

Encode encodes the packet passed and compresses it.

type Header struct {
	PacketID        uint32
	SenderSubClient byte
	TargetSubClient byte
}

func (*Header) Read

func (header *Header) Read(r io.ByteReader) error

func (*Header) Write

func (header *Header) Write(w io.ByteWriter) error

type Login

type Login struct {
	// ClientProtocol is the protocol version of the player. The player is disconnected if the protocol is
	// incompatible with the protocol of the server.
	ClientProtocol int32
	// ConnectionRequest is a string containing information about the player and JWTs that may be used to
	// verify if the player is connected to XBOX Live. The connection request also contains the necessary
	// client public key to initiate encryption.
	ConnectionRequest []byte
}

Login is sent when the client initially tries to join the server. It is the first packet sent and contains information specific to the player.

func (*Login) ID

func (pk *Login) ID() uint32

func (*Login) Marshal

func (pk *Login) Marshal(buf *Writer)

Marshal ...

func (*Login) Unmarshal

func (pk *Login) Unmarshal(r *Reader) error

type Packet

type Packet interface {
	// ID returns the ID of the packet. All of these identifiers of packets may be found in id.go.
	ID() uint32
	// Unmarshal decodes a serialised packet in buf into the Packet instance. The serialised packet passed
	// into Unmarshal will not have a header in it.
	Unmarshal(r *Reader) error
	Marshal(w *Writer)
}

Packet represents a packet that may be sent over a Minecraft network connection. The packet needs to hold a method to encode itself to binary and decode itself from binary.

type Reader

type Reader struct {
	DecodeReader
}

func NewReader

func NewReader(r DecodeReader) *Reader

func (*Reader) BEInt32

func (r *Reader) BEInt32(x *int32) error

func (*Reader) ByteSlice

func (r *Reader) ByteSlice(x *[]byte) error

func (*Reader) Varuint32

func (r *Reader) Varuint32(x *uint32) error

type Writer

type Writer struct {
	EncodeReader
}

func NewWriter

func NewWriter(w EncodeReader) *Writer

func (*Writer) Bool

func (w *Writer) Bool(x bool)

func (*Writer) String

func (w *Writer) String(x string)

func (*Writer) Varuint32

func (w *Writer) Varuint32(x uint32)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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