mc

package
v1.0.3-beta Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerBoundHandshakePacketID byte = 0x00
	HandshakePacketID            int  = 0x00

	StatusState = 1
	LoginState  = 2

	HandshakeStatusState = VarInt(StatusState)
	HandshakeLoginState  = VarInt(LoginState)

	ForgeSeparator  = "\x00"
	RealIPSeparator = "///"
)
View Source
const (
	ClientBoundResponsePacketID byte = 0x00
	ServerBoundRequestPacketID  byte = 0x00
	ServerBoundPingPacketID     byte = 0x01
	ClientBoundPongPacketID     byte = 0x01
)
View Source
const ClientBoundDisconnectPacketID byte = 0x00
View Source
const ServerBoundLoginStartPacketID byte = 0x00

Variables

View Source
var (
	ErrInvalidPacketID = errors.New("invalid packet id")
	ErrPacketTooBig    = errors.New("packet contains too much data")
	MaxPacketSize      = 2097151
)
View Source
var (
	ErrVarIntSize = errors.New("VarInt is too big")
)

Functions

func NewMcConn

func NewMcConn(conn net.Conn) mcConn

func ReadNBytes

func ReadNBytes(r DecodeReader, n int) ([]byte, error)

ReadNBytes read N bytes from bytes.Reader

func ReadNBytes_ByteReader

func ReadNBytes_ByteReader(r io.ByteReader, n int) ([]byte, error)

func ReadPacketBytes

func ReadPacketBytes(r DecodeReader) ([]byte, error)

ReadPacketBytes decodes a byte stream and cuts the first Packet as a byte array out

func ReadPacketSize_Bytes

func ReadPacketSize_Bytes(bytes []byte) (int, int, error)

func ReadShot_ByteReader

func ReadShot_ByteReader(r io.ByteReader) (int16, error)

Decode a UnsignedShort

func ReadString_ByteReader

func ReadString_ByteReader(r io.ByteReader) (string, error)

Decode a String

func ReadVarInt_ByteReader

func ReadVarInt_ByteReader(b io.ByteReader) (int, error)

func ScanFields

func ScanFields(r DecodeReader, fields ...FieldDecoder) error

ScanFields decodes a byte stream into fields

Types

type Byte

type Byte int8

Byte is signed 8-bit integer, two's complement

func ReadByte

func ReadByte(r DecodeReader) (Byte, error)

Read a Byte

func (*Byte) Decode

func (b *Byte) Decode(r DecodeReader) error

Decode a Byte

func (Byte) Encode

func (b Byte) Encode() []byte

Encode a Byte

type Chat

type Chat = String

Chat is encoded as a String with max length of 262144.

type ClientBoundDisconnect

type ClientBoundDisconnect struct {
	Reason Chat
}

func UnmarshalClientDisconnect

func UnmarshalClientDisconnect(packet Packet) (ClientBoundDisconnect, error)

func (ClientBoundDisconnect) Marshal

func (pk ClientBoundDisconnect) Marshal() Packet

func (*ClientBoundDisconnect) MarshalPacket

func (pk *ClientBoundDisconnect) MarshalPacket() Packet

type ClientBoundResponse

type ClientBoundResponse struct {
	JSONResponse String
}

func UnmarshalClientBoundResponse

func UnmarshalClientBoundResponse(packet Packet) (ClientBoundResponse, error)

func (*ClientBoundResponse) Marshal

func (pk *ClientBoundResponse) Marshal() Packet

type DecodeReader

type DecodeReader interface {
	io.ByteReader
	io.Reader
}

DecodeReader is both io.Reader and io.ByteReader

type DescriptionJSON

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

type DifferentStatusResponse

type DifferentStatusResponse struct {
	Version     VersionJSON     `json:"version"`
	Description DescriptionJSON `json:"description"`
	Favicon     string          `json:"favicon,omitempty"`
}

func (*DifferentStatusResponse) Marshal

func (pk *DifferentStatusResponse) Marshal() Packet

type Field

type Field interface {
	FieldEncoder
	FieldDecoder
}

A Field is both FieldEncoder and FieldDecoder

type FieldDecoder

type FieldDecoder interface {
	Decode(r DecodeReader) error
}

A FieldDecoder can Decode from minecraft protocol

type FieldEncoder

type FieldEncoder interface {
	Encode() []byte
}

A FieldEncoder can be encode as minecraft protocol used.

type HandshakeState

type HandshakeState byte
const (
	UnknownState HandshakeState = iota
	Status
	Login
)

func RequestState

func RequestState(n byte) HandshakeState

func (HandshakeState) String

func (i HandshakeState) String() string

type Long

type Long int64

Long is signed 64-bit integer, two's complement

func (*Long) Decode

func (l *Long) Decode(r DecodeReader) error

Decode a Long

func (Long) Encode

func (l Long) Encode() []byte

Encode a Long

type McPacket

type McPacket interface {
	MarshalPacket() Packet
}

type McTypesHandshake

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

type Packet

type Packet struct {
	ID   byte
	Data []byte
}

Packet is the raw representation of message that is send between the client and the server

func MarshalPacket

func MarshalPacket(ID byte, fields ...FieldEncoder) Packet

MarshalPacket transforms an ID and Fields into a Packet

func ReadPacket

func ReadPacket(r DecodeReader) (Packet, error)

func ReadPacket3

func ReadPacket3(r *bufio.Reader) (Packet, error)

func ReadPacketOld

func ReadPacketOld(r DecodeReader) (Packet, error)

ReadPacketOld decodes and decompresses a byte stream and cuts the first Packet out

func ReadPacket_WithBytes

func ReadPacket_WithBytes(b []byte) (Packet, error)

func ServerBoundRequestPacket

func ServerBoundRequestPacket() Packet

func (*Packet) Marshal

func (pk *Packet) Marshal() []byte

Marshal encodes the packet and all it's fields

func (Packet) Scan

func (pk Packet) Scan(fields ...FieldDecoder) error

Scan decodes and copies the Packet data into the fields

type PlayerSampleJSON

type PlayerSampleJSON struct {
	Name string `json:"name"`
	ID   string `json:"id"`
}

type PlayersJSON

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

type ResponseJSON

type ResponseJSON struct {
	Version     VersionJSON     `json:"version"`
	Players     PlayersJSON     `json:"players"`
	Description DescriptionJSON `json:"description"`
	Favicon     string          `json:"favicon"`
}

type ServerBoundHandshake

type ServerBoundHandshake struct {
	ProtocolVersion int
	ServerAddress   string
	ServerPort      int16
	NextState       byte
}

func ReadPacket3_Handshake

func ReadPacket3_Handshake(r *bufio.Reader) (ServerBoundHandshake, error)

func UnmarshalServerBoundHandshake

func UnmarshalServerBoundHandshake(packet Packet) (ServerBoundHandshake, error)

func UnmarshalServerBoundHandshake2

func UnmarshalServerBoundHandshake2(packet Packet) (ServerBoundHandshake, error)

func UnmarshalServerBoundHandshake_ByteReader

func UnmarshalServerBoundHandshake_ByteReader(r io.ByteReader) (ServerBoundHandshake, error)

func (ServerBoundHandshake) IsForgeAddress

func (hs ServerBoundHandshake) IsForgeAddress() bool

func (ServerBoundHandshake) IsLoginRequest

func (hs ServerBoundHandshake) IsLoginRequest() bool

func (ServerBoundHandshake) IsRealIPAddress

func (hs ServerBoundHandshake) IsRealIPAddress() bool

func (ServerBoundHandshake) IsStatusRequest

func (hs ServerBoundHandshake) IsStatusRequest() bool

func (ServerBoundHandshake) Marshal

func (pk ServerBoundHandshake) Marshal() Packet

func (ServerBoundHandshake) MarshalPacket

func (pk ServerBoundHandshake) MarshalPacket() Packet

func (ServerBoundHandshake) ParseServerAddress

func (hs ServerBoundHandshake) ParseServerAddress() string

func (ServerBoundHandshake) State

func (*ServerBoundHandshake) UpgradeToNewRealIP

func (hs *ServerBoundHandshake) UpgradeToNewRealIP(clientAddr string, key *ecdsa.PrivateKey) error

func (*ServerBoundHandshake) UpgradeToOldRealIP

func (hs *ServerBoundHandshake) UpgradeToOldRealIP(clientAddr string)

func (*ServerBoundHandshake) UpgradeToOldRealIP_WithTime

func (hs *ServerBoundHandshake) UpgradeToOldRealIP_WithTime(clientAddr string, stamp time.Time)

type ServerBoundPing

type ServerBoundPing struct {
	Time Long
}

func NewServerBoundPing

func NewServerBoundPing() ServerBoundPing

func (ServerBoundPing) Marshal

func (pk ServerBoundPing) Marshal() Packet

type ServerBoundRequest

type ServerBoundRequest struct{}

func (ServerBoundRequest) Marshal

func (pk ServerBoundRequest) Marshal() Packet

func (*ServerBoundRequest) MarshalPacket

func (pk *ServerBoundRequest) MarshalPacket() Packet

type ServerLoginStart

type ServerLoginStart struct {
	Name String
}

func UnmarshalServerBoundLoginStart

func UnmarshalServerBoundLoginStart(packet Packet) (ServerLoginStart, error)

func (ServerLoginStart) Marshal

func (pk ServerLoginStart) Marshal() Packet

func (*ServerLoginStart) MarshalPacket

func (pk *ServerLoginStart) MarshalPacket() Packet

type SimpleStatus

type SimpleStatus struct {
	Name        string `json:"name"`
	Protocol    int    `json:"protocol"`
	Description string `json:"text"`
	Favicon     string `json:"favicon,omitempty"`
}

func (SimpleStatus) Marshal

func (pk SimpleStatus) Marshal() Packet

func (*SimpleStatus) MarshalPacket

func (pk *SimpleStatus) MarshalPacket() Packet

type String

type String string

String is sequence of Unicode scalar values with a max length of 32767

func ReadString

func ReadString(r DecodeReader) (String, error)

Read a String

func (*String) Decode

func (s *String) Decode(r DecodeReader) error

Decode a String

func (String) Encode

func (s String) Encode() []byte

Encode a String

type UnsignedShort

type UnsignedShort uint16

UnsignedShort is unsigned 16-bit integer

func ReadUnsignedShort

func ReadUnsignedShort(r DecodeReader) (UnsignedShort, error)

Read a UnsignedShort

func (*UnsignedShort) Decode

func (us *UnsignedShort) Decode(r DecodeReader) error

Decode a UnsignedShort

func (UnsignedShort) Encode

func (us UnsignedShort) Encode() []byte

Encode a Unsigned Short

type VarInt

type VarInt int32

VarInt is variable-length data encoding a two's complement signed 32-bit integer

func ReadVarInt

func ReadVarInt(r DecodeReader) (VarInt, error)

Read a VarInt

func (*VarInt) Decode

func (v *VarInt) Decode(r DecodeReader) error

Decode a VarInt

func (VarInt) Encode

func (v VarInt) Encode() []byte

Encode a VarInt

type VersionJSON

type VersionJSON 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