proto

package module
v0.0.0-...-9e7ab50 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: MIT Imports: 8 Imported by: 1

README

proto

Golang Minecraft protocol implementation

Documentation

Index

Constants

View Source
const EncryptionRequest_ID = 0x01

EncrpytionRequest_ID is the EncryptionRequest packet ID.

View Source
const EncryptionResponse_ID = 0x01

EncrpytionResponse_ID is the EncryptionResponse packet ID.

View Source
const Handshake_ID = 0x00

Handshake_ID is the Handshake packet ID.

View Source
const LegacyServerListPing_ID = 0xFE

LegacyServerListPing_ID is the LegacyServerListPing packet ID.

View Source
const LoginDisconnect_ID = 0x00

LoginDisconnect_ID is the LoginDisconnect packet ID.

View Source
const LoginPluginRequest_ID = 0x04

LoginPluginResponse_ID is the LoginPluginResponse packet ID.

View Source
const LoginPluginResponse_ID = 0x04

LoginPluginResponse_ID is the LoginPluginResponse packet ID.

View Source
const LoginStart_ID = 0x00

LoginStart_ID is the LoginStart packet ID.

View Source
const LoginSuccess_ID = 0x02

LoginSuccess_ID is the LoginSuccess packet ID.

View Source
const MaxVarIntLen = 5

MaxVarIntLen is Maximum VarInt length.

View Source
const MaxVarLongLen = 10

MaxVarLongLen is Maximum VarLong length.

View Source
const Ping_ID = 0x01

Ping_ID is the Ping packet ID.

View Source
const Pong_ID = 0x01

Pong_ID is the Pong packet ID.

View Source
const Request_ID = 0x00

Request_ID is the Request packet ID.

View Source
const Response_ID = 0x00

Response_ID is the Response packet ID.

View Source
const SetCompression_ID = 0x03

SetCompression_ID is the SetCompression packet ID.

Variables

This section is empty.

Functions

func WrongPacketError

func WrongPacketError(expect, get int32) error

Types

type Angle

type Angle Byte

Angle is rotation angle in steps of 1/256 of a full turn. Implements proto.Type interface (Minecraft protocol data type).

func (*Angle) ReadFrom

func (a *Angle) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads Angle data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (Angle) ToDeg

func (a Angle) ToDeg() float64

ToDeg convert Angle to Degree

func (Angle) ToRad

func (a Angle) ToRad() float64

ToRad convert Angle to Radian

func (Angle) WriteTo

func (a Angle) WriteTo(w io.Writer) (int64, error)

WriteTo writes Angle data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type Boolean

type Boolean bool

Boolean is either false or true. Implements proto.Type interface (Minecraft protocol data type).

func (*Boolean) ReadFrom

func (b *Boolean) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads Boolean data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (Boolean) WriteTo

func (b Boolean) WriteTo(w io.Writer) (int64, error)

WriteTo writes Boolean data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type Byte

type Byte int8

Byte is a signed 8-bit integer, two's complement. Implements proto.Type interface (Minecraft protocol data type).

func (*Byte) ReadFrom

func (b *Byte) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads Byte data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (Byte) WriteTo

func (b Byte) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes Byte data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type ByteArray

type ByteArray []byte

ByteArray is just a sequence of zero or more bytes. Its meaning should be explained somewhere else (e.g. in the packet description). Implements proto.Type interface (Minecraft protocol data type).

func (*ByteArray) ReadFrom

func (b *ByteArray) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads ByteArray data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (ByteArray) WriteTo

func (b ByteArray) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes ByteArray data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type Chat

type Chat = String

Chat supports two-way chat communication. Implements proto.Type interface (Minecraft protocol data type).

type Double

type Double float64

Double is a double-precision 64-bit IEEE 754 floating point number. Implements proto.Type interface (Minecraft protocol data type).

func (*Double) ReadFrom

func (d *Double) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads Double data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (Double) WriteTo

func (d Double) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes Double data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type EncryptionRequest

type EncryptionRequest struct {
	ServerID          String
	PublicKeyLength   VarInt
	PublicKey         ByteArray
	VerifyTokenLength VarInt
	VerifyToken       ByteArray
}

EncryptionRequest is a packet that initiate encryption process. Clientbound (S -> C) Implements proto.Packet interface.

func (*EncryptionRequest) FromRaw

func (pi *EncryptionRequest) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the EncryptionRequest Packet from the given RawPacket.

func (*EncryptionRequest) ToRaw

func (pi *EncryptionRequest) ToRaw(p *RawPacket) (err error)

ToRaw marshals the EncryptionRequest Packet to the given RawPacket.

type EncryptionResponse

type EncryptionResponse struct {
	SharedSecretLength VarInt
	SharedSecret       ByteArray
	VerifyTokenLength  VarInt
	VerifyToken        ByteArray
}

EncryptionResponse is a packet sent by server to confirm the encryption process. Serverbound (C -> S) Implements proto.Packet interface.

func (*EncryptionResponse) FromRaw

func (pi *EncryptionResponse) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the EncryptionResponse Packet from the given RawPacket.

func (*EncryptionResponse) ToRaw

func (pi *EncryptionResponse) ToRaw(p *RawPacket) (err error)

ToRaw marshals the EncryptionResponse Packet to the given RawPacket.

type EntityMetadata

type EntityMetadata struct{}

EntityMetadata represents miscellaneous information about an entity Implements proto.Type interface (Minecraft protocol data type). WARNING: EntityMetadata is not implemented in proto.

func (*EntityMetadata) ReadFrom

func (e *EntityMetadata) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads EntityMetadata data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned. WARNING: EntityMetadata is not implemented in proto.

func (*EntityMetadata) WriteTo

func (e *EntityMetadata) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes EntityMetadata data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned. WARNING: EntityMetadata is not implemented in proto.

type Float

type Float float32

Float is a single-precision 32-bit IEEE 754 floating point number. Implements proto.Type interface (Minecraft protocol data type).

func (*Float) ReadFrom

func (f *Float) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads Float data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (Float) WriteTo

func (f Float) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes Float data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type Handshake

type Handshake struct {
	ProtocolVersion VarInt
	ServerAddress   String
	ServerPort      UnsignedShort
	NextState       VarInt
}

Handshake is a packet that causes the server to switch into the target state. Serverbound (C -> S) Implements proto.Packet interface.

func (*Handshake) FromRaw

func (h *Handshake) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the Handshake Packet from the given RawPacket.

func (*Handshake) ToRaw

func (h *Handshake) ToRaw(p *RawPacket) (err error)

ToRaw marshals the Handshake Packet to the given RawPacket.

type Identifier

type Identifier = String

Identifier is a namespaced location. Implements proto.Type interface (Minecraft protocol data type).

type Int

type Int int32

Int is a signed 32-bit integer, two's complement. Implements proto.Type interface (Minecraft protocol data type).

func (*Int) ReadFrom

func (i *Int) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads Int data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (Int) WriteTo

func (i Int) WriteTo(w io.Writer) (int64, error)

Write Int data to w

type LegacyServerListPing

type LegacyServerListPing struct {
	Payload UnsignedByte
}

LegacyServerListPing is a packet asking for Server List Ping. While not technically part of the current protocol, modern servers should handle it correctly. Serverbound (C -> S) Implements proto.Packet interface.

func (*LegacyServerListPing) FromRaw

func (l *LegacyServerListPing) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the LegacyServerListPing Packet from the given RawPacket.

func (*LegacyServerListPing) ToRaw

func (l *LegacyServerListPing) ToRaw(p *RawPacket) (err error)

ToRaw marshals the LegacyServerListPing Packet to the given RawPacket.

type LoginDisconnect

type LoginDisconnect struct {
	Reason Chat
}

LoginDisconnect is a packet that tells the user they have been disconnected. Clientbound (S -> C) Implements proto.Packet interface.

func (*LoginDisconnect) FromRaw

func (pi *LoginDisconnect) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the LoginDisconnect Packet from the given RawPacket.

func (*LoginDisconnect) ToRaw

func (pi *LoginDisconnect) ToRaw(p *RawPacket) (err error)

ToRaw marshals the LoginDisconnect Packet to the given RawPacket.

type LoginPluginRequest

type LoginPluginRequest struct {
	MessageID VarInt
	Channel   Identifier
	Data      ByteArray
}

LoginPluginRequest is a packet used to implement a custom handshaking flow together with LoginPluginResponse. Clientbound (S -> C) Implements proto.Packet interface.

func (*LoginPluginRequest) FromRaw

func (pi *LoginPluginRequest) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the LoginPluginRequest Packet from the given RawPacket.

func (*LoginPluginRequest) ToRaw

func (pi *LoginPluginRequest) ToRaw(p *RawPacket) (err error)

ToRaw marshals the LoginPluginRequest Packet to the given RawPacket.

type LoginPluginResponse

type LoginPluginResponse struct {
	MessageID  VarInt
	Successful Boolean
	Data       ByteArray
}

LoginPluginResponse is a packet used to implement a custom handshaking flow together with LoginPluginResponse. Serverbound (C -> S) Implements proto.Packet interface.

func (*LoginPluginResponse) FromRaw

func (pi *LoginPluginResponse) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the LoginPluginResponse Packet from the given RawPacket.

func (*LoginPluginResponse) ToRaw

func (pi *LoginPluginResponse) ToRaw(p *RawPacket) (err error)

ToRaw marshals the LoginPluginResponse Packet to the given RawPacket.

type LoginStart

type LoginStart struct {
	Name String
}

LoginStart is a packet sent by client to initiate the login process. Serverbound (C -> S) Implements proto.Packet interface.

func (*LoginStart) FromRaw

func (pi *LoginStart) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the LoginStart Packet from the given RawPacket.

func (*LoginStart) ToRaw

func (pi *LoginStart) ToRaw(p *RawPacket) (err error)

ToRaw marshals the LoginStart Packet to the given RawPacket.

type LoginSuccess

type LoginSuccess struct {
	UUID     UUID
	Username String
}

LoginSuccess is a packet that tells the client they have successfully logged in. Clientbound (S -> C) Implements proto.Packet interface.

func (*LoginSuccess) FromRaw

func (pi *LoginSuccess) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the LoginSuccess Packet from the given RawPacket.

func (*LoginSuccess) ToRaw

func (pi *LoginSuccess) ToRaw(p *RawPacket) (err error)

ToRaw marshals the LoginSuccess Packet to the given RawPacket.

type Long

type Long int64

Long is a signed 64-bit integer, two's complement. Implements proto.Type interface (Minecraft protocol data type).

func (*Long) ReadFrom

func (l *Long) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads Long data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (Long) WriteTo

func (l Long) WriteTo(w io.Writer) (int64, error)

WriteTo writes Long data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type NBTTag

type NBTTag struct{}

NBTTag represents an item and its associated data. Implements proto.Type interface (Minecraft protocol data type). WARNING: NBTTag is not implemented in proto.

func (*NBTTag) ReadFrom

func (t *NBTTag) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads NBTTag data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned. WARNING: NBTTag is not implemented in proto.

func (*NBTTag) WriteTo

func (t *NBTTag) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes NBTTag data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned. WARNING: NBTTag is not implemented in proto.

type Packet

type Packet interface {
	FromRaw(p *RawPacket) error
	ToRaw(p *RawPacket) error
}

Packet is a structured Minecraft packet. It can be converted from/to a RawPacket.

type Ping

type Ping struct {
	Payload Long
}

Ping is a packet sent to ask a Pong response. Serverbound (C -> S) Implements proto.Packet interface.

func (*Ping) FromRaw

func (pi *Ping) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the Ping Packet from the given RawPacket.

func (*Ping) ToRaw

func (pi *Ping) ToRaw(p *RawPacket) (err error)

ToRaw marshals the Ping Packet to the given RawPacket.

type Pong

type Pong struct {
	Payload Long
}

Pong is a packet sent as a response to Ping. Clientbound (S -> C) Implements proto.Packet interface.

func (*Pong) FromRaw

func (pi *Pong) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the Pong Packet from the given RawPacket.

func (*Pong) ToRaw

func (pi *Pong) ToRaw(p *RawPacket) (err error)

ToRaw marshals the Pong Packet to the given RawPacket.

type Position

type Position struct {
	X, Y, Z int
}

Position is an integer/block position: x,y,z. Implements proto.Type interface (Minecraft protocol data type).

func (*Position) ReadFrom

func (p *Position) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads Position data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (Position) WriteTo

func (p Position) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes Position data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type RawPacket

type RawPacket struct {
	ID   int32
	Data []byte
}

RawPacket is an unstructured Minecraft packet that contains id and raw data. It can be sent/received over Minecraft Network Protocol.

func NewRawPacket

func NewRawPacket() *RawPacket

NewRawPacket creates a new RawPacket

func (*RawPacket) Marshal

func (p *RawPacket) Marshal(types ...Type) error

Marshal encodes given types to the raw packet

func (*RawPacket) Pack

func (p *RawPacket) Pack(writer io.Writer, threshold int) error

Pack packs the raw packet to the writer

func (*RawPacket) Unmarshal

func (p *RawPacket) Unmarshal(types ...Type) error

Unmarshal parses the raw packet and store the result in given types

func (*RawPacket) Unpack

func (p *RawPacket) Unpack(reader io.Reader, threshold int) error

Unpack unpacks the raw packet from the reader

type Request

type Request struct {
}

Request is a packet asking for Server List Ping. Serverbound (C -> S) Implements proto.Packet interface.

func (*Request) FromRaw

func (pi *Request) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the Request Packet from the given RawPacket.

func (*Request) ToRaw

func (pi *Request) ToRaw(p *RawPacket) (err error)

ToRaw marshals the Request Packet to the given RawPacket.

type Response

type Response struct {
	JSONResponse String
}

Response is a packet that contains Server List Ping. Clientbound (S -> C) Implements proto.Packet interface.

func (*Response) FromRaw

func (pi *Response) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the Response Packet from the given RawPacket.

func (*Response) ToRaw

func (pi *Response) ToRaw(p *RawPacket) (err error)

ToRaw marshals the Response Packet to the given RawPacket.

type SetCompression

type SetCompression struct {
	Threshold VarInt
}

SetCompression is a packet that tells the client to use compression. Clientbound (S -> C) Implements proto.Packet interface.

func (*SetCompression) FromRaw

func (pi *SetCompression) FromRaw(p *RawPacket) (err error)

FromRaw unmarshals the SetCompression Packet from the given RawPacket.

func (*SetCompression) ToRaw

func (pi *SetCompression) ToRaw(p *RawPacket) (err error)

ToRaw marshals the SetCompression Packet to the given RawPacket.

type Short

type Short int16

Short is a signed 16-bit integer, two's complement. Implements proto.Type interface (Minecraft protocol data type).

func (*Short) ReadFrom

func (s *Short) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads Short data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (Short) WriteTo

func (s Short) WriteTo(w io.Writer) (int64, error)

WriteTo writes Short data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type Slot

type Slot struct{}

Slot represents an item stack in an inventory or container. Implements proto.Type interface (Minecraft protocol data type). WARNING: Slot is not implemented in proto.

func (*Slot) ReadFrom

func (s *Slot) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads Slot data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned. WARNING: Slot is not implemented in proto.

func (*Slot) WriteTo

func (s *Slot) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes Slot data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned. WARNING: Slot is not implemented in proto.

type String

type String string

String is a sequence of Unicode scalar values. Implements proto.Type interface (Minecraft protocol data type).

func (*String) ReadFrom

func (s *String) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads String data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (String) WriteTo

func (s String) WriteTo(w io.Writer) (int64, error)

WriteTo writes String data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type Type

type Type interface {
	io.ReaderFrom
	io.WriterTo
}

Type represents a Minecraft protocol data type. Implements io.ReaderFrom and io.WriterTo.

type UUID

type UUID uuid.UUID

UUID is an uuid. Implements proto.Type interface (Minecraft protocol data type).

func (*UUID) ReadFrom

func (u *UUID) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads UUID data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (UUID) WriteTo

func (u UUID) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes UUID data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type UnsignedByte

type UnsignedByte uint8

UnsignedByte is an unsigned 8-bit integer. Implements proto.Type interface (Minecraft protocol data type).

func (*UnsignedByte) ReadFrom

func (u *UnsignedByte) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads UnsignedByte data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (UnsignedByte) WriteTo

func (u UnsignedByte) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes UnsignedByte data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type UnsignedShort

type UnsignedShort uint16

UnsignedShort is an unsigned 16-bit integer. Implements proto.Type interface (Minecraft protocol data type).

func (*UnsignedShort) ReadFrom

func (us *UnsignedShort) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads UnsignedShort data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (UnsignedShort) WriteTo

func (us UnsignedShort) WriteTo(w io.Writer) (int64, error)

WriteTo writes UnsignedShort data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type VarInt

type VarInt int32

VarInt is variable-length data encoding a two's complement signed 32-bit integer. Implements proto.Type interface (Minecraft protocol data type).

func (*VarInt) ReadFrom

func (v *VarInt) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads VarInt data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (VarInt) WriteTo

func (v VarInt) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes VarInt data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type VarLong

type VarLong int64

VarLong is variable-length data encoding a two's complement signed 64-bit integer. Implements proto.Type interface (Minecraft protocol data type).

func (*VarLong) ReadFrom

func (v *VarLong) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads VarLong data from r until an error occurs. The return value n is the number of bytes read. Any error encountered during the read is also returned.

func (VarLong) WriteTo

func (v VarLong) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes VarLong data to w until an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

Jump to

Keyboard shortcuts

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