liter

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: AGPL-3.0 Imports: 21 Imported by: 23

README

Discord Build Status Go Reference

Go Liter

A Minecraft proxy that can extended with JavaScript.

If you are interested in develop script, please check script/README.MD

Features

  • Support both forward proxy and reverse proxy
  • Extendable with JavaScript
  • Written in Golang, fast and easy to understand

Applications

  • liter-proxy: The minecraft forward proxy which support socks5
  • liter-server: The minecraft reverse proxy with a simple manage dashboard

Documentation

Overview

This package provide some useful data encode/decode

Index

Constants

View Source
const (
	NextPingState  = 1
	NextLoginState = 2
)
View Source
const (
	V_UNSET   = -1
	V_HIGHEST = V1_20
	V1_20     = 763 // https://wiki.vg/index.php?title=Protocol&oldid=18256
	V1_19_4   = 762 // https://wiki.vg/index.php?title=Protocol&oldid=18242
	V1_19_3   = 761 // https://wiki.vg/index.php?title=Protocol&oldid=18067
	V1_19_2   = 760 // https://wiki.vg/index.php?title=Protocol&oldid=17873
	V1_19     = 759 // https://wiki.vg/index.php?title=Protocol&oldid=17753
	V1_18_2   = 758 // https://wiki.vg/index.php?title=Protocol&oldid=17499
	V1_18_1   = 757 // https://wiki.vg/index.php?title=Protocol&oldid=17341
	V1_17_1   = 756 // https://wiki.vg/index.php?title=Protocol&oldid=16918
	V1_17     = 755 // https://wiki.vg/index.php?title=Protocol&oldid=16866
	V1_16_5   = 754 // https://wiki.vg/index.php?title=Protocol&oldid=16681
	V1_16_3   = 753 // https://wiki.vg/index.php?title=Protocol&oldid=16091
	V1_15_2   = 578 // https://wiki.vg/index.php?title=Protocol&oldid=16067
	V1_14_4   = 498 // https://wiki.vg/index.php?title=Protocol&oldid=15346
	V1_13_2   = 404 // https://wiki.vg/index.php?title=Protocol&oldid=14889
	V1_12_2   = 340 // https://wiki.vg/index.php?title=Protocol&oldid=14204
	V1_12_1   = 338 // https://wiki.vg/index.php?title=Protocol&oldid=13339
	V1_12     = 335 // https://wiki.vg/index.php?title=Protocol&oldid=13223
	V1_11_2   = 316 // https://wiki.vg/index.php?title=Protocol&oldid=8543
	V1_11     = 315 // https://wiki.vg/index.php?title=Protocol&oldid=8405
	V1_10_2   = 210 // https://wiki.vg/index.php?title=Protocol&oldid=8235
	V1_9_4    = 110 // https://wiki.vg/index.php?title=Protocol&oldid=7959
	V1_8_9    = 47  // https://wiki.vg/index.php?title=Protocol&oldid=7368
	V1_7_5    = 4   // https://wiki.vg/index.php?title=Protocol&oldid=5486
	V_LOWEST  = V1_7_5
)
View Source
const (
	DefaultApiServer     = "https://api.mojang.com/"
	DefaultAuthServer    = "https://authserver.mojang.com/"
	DefaultSessionServer = "https://sessionserver.mojang.com/session/minecraft/"
)
View Source
const DefaultPort = 25565

Variables

View Source
var (
	ErrParserIdNotExists       = errors.New("liter.CommandNode: parser id is not exists")
	ErrParserInstanceNotExists = errors.New("liter.CommandNode: command parser instance not exists")
)
View Source
var (
	ErrNoRecordFound = errors.New("No DNS record was found")
	ErrOldHandshake  = errors.New("Old client(<=1.6) handshake received") // The handshake packet <= 1.6 which first byte is 0xFE
)
View Source
var (
	ErrPlayerNameInvalid = errors.New("Player name is invalid")
	ErrPlayerNotExists   = errors.New("Player not exists on the server")
)
View Source
var DefaultAuthClient = &AuthClient{
	Client: &http.Client{},

	ApiServer:     DefaultApiServer,
	AuthServer:    DefaultAuthServer,
	SessionServer: DefaultSessionServer,
}
View Source
var VarIntTooBig = errors.New("VarInt is too big")
View Source
var VarLongTooBig = errors.New("VarLong is too big")

Functions

func GetProtocolName

func GetProtocolName(p int) string

func IsProtocolSupport

func IsProtocolSupport(p int) bool

func RegisterCmdEncoder

func RegisterCmdEncoder(p CmdPropEncoder) (ok bool)

func ResloveAddr

func ResloveAddr(target string) (addr *net.TCPAddr, err error)

Resolve the minecraft server's hostport with the given address

func ResloveAddrWithContext

func ResloveAddrWithContext(ctx context.Context, target string) (addr *net.TCPAddr, err error)

Resolve the minecraft server's hostport with the given address and cancel context

func ToNearestProtocol

func ToNearestProtocol(p int) int

func UnregisterCmdEncoder

func UnregisterCmdEncoder(p CmdPropEncoder) (ok bool)

Types

type AccessData

type AccessData struct {
	ClientToken string `json:"clientToken"`
	AccessToken string `json:"accessToken"`
}

type Angle

type Angle = UByte

type AuthClient

type AuthClient struct {
	Client *http.Client

	ApiServer     string
	AuthServer    string
	SessionServer string
}

func (*AuthClient) Auth

func (cli *AuthClient) Auth(data AuthData) (res *AuthResponse, err error)

func (*AuthClient) GetPlayerInfo added in v0.2.0

func (cli *AuthClient) GetPlayerInfo(name string) (player PlayerInfo, err error)

func (*AuthClient) GetPlayerProfile added in v0.2.0

func (cli *AuthClient) GetPlayerProfile(id UUID) (profile *PlayerProfile, err error)

func (*AuthClient) Invalidate

func (cli *AuthClient) Invalidate(data AccessData) (err error)

func (*AuthClient) Refresh

func (cli *AuthClient) Refresh(data AccessData) (res *RefreshResponse, err error)

func (*AuthClient) Signout

func (cli *AuthClient) Signout(data LoginData) (err error)

func (*AuthClient) Validate

func (cli *AuthClient) Validate(data AccessData) (err error)

type AuthData

type AuthData struct {
	LoginData
	ClientToken string `json:"clientToken"`
}

type AuthResponse

type AuthResponse struct {
	User        UserData `json:"user"`
	ClientToken string   `json:"clientToken"`
	AccessToken string   `json:"accessToken"`

	AvailableProfiles []PlayerInfo `json:"availableProfiles"`
	SelectedProfile   PlayerInfo   `json:"selectedProfile"`
}

type BitSet

type BitSet []uint64

func NewBitSet

func NewBitSet() (s *BitSet)

func NewBitSetWith

func NewBitSetWith(size int) (s *BitSet)

func (*BitSet) Clear

func (s *BitSet) Clear()

func (*BitSet) Close

func (s *BitSet) Close(index int)

func (*BitSet) DecodeFrom

func (s *BitSet) DecodeFrom(r *PacketReader) (err error)

func (BitSet) Encode

func (s BitSet) Encode(p *PacketBuilder)

func (*BitSet) Get

func (s *BitSet) Get(index int) (value bool)

func (*BitSet) Open

func (s *BitSet) Open(index int)

func (*BitSet) Set

func (s *BitSet) Set(index int, value bool)

type Bool

type Bool = bool

type Byte

type Byte = int8
const (
	NumPropMin Byte = 0x01
	NumPropMax Byte = 0x02
)

type ByteArray

type ByteArray = []byte

type Chat added in v0.2.0

type Chat struct {
	// content: parse by order
	Text      string          `json:"text,omitempty"`
	Translate string          `json:"translate,omitempty"`
	With      []*Chat         `json:"with,omitempty"` // the values for translate
	Keybind   string          `json:"keybind,omitempty"`
	Score     *ScoreComponent `json:"score,omitempty"`
	// properties
	Bold          OptBool     `json:"bold,omitempty"`
	Italic        OptBool     `json:"italic,omitempty"`
	Underlined    OptBool     `json:"underlined,omitempty"`
	Strikethrough OptBool     `json:"strikethrough,omitempty"`
	Obfuscated    OptBool     `json:"obfuscated,omitempty"`
	Font          string      `json:"font,omitempty"`
	Color         string      `json:"color,omitempty"`
	Insertion     string      `json:"insertion,omitempty"`
	ClickEvent    *ClickEvent `json:"clickEvent,omitempty"`
	HoverEvent    *HoverEvent `json:"hoverEvent,omitempty"`
	Extra         []*Chat     `json:"extra,omitempty"`
}

func NewChatFromString added in v0.2.0

func NewChatFromString(s string) (c *Chat)

func (*Chat) MarshalJSON added in v0.2.0

func (c *Chat) MarshalJSON() (buf []byte, err error)

func (*Chat) Plain added in v0.2.0

func (c *Chat) Plain() string

Plain() will return the plain text value for the chat component

func (*Chat) Type added in v0.3.2

func (c *Chat) Type() ChatType

Type will return the content's type of the chat component.

func (*Chat) UnmarshalJSON added in v0.2.0

func (c *Chat) UnmarshalJSON(buf []byte) (err error)

type ChatType added in v0.2.0

type ChatType int
const (
	TextChat ChatType
	TranslateChat
	KeybindChat
	ScoreChat
)

type ChunkSection

type ChunkSection struct {
	/*
	 * Number of non-air blocks present in the chunk section. "Non-air" is defined as any fluid and block other than air, cave air, and void air.
	 * The client will keep count of the blocks as they are broken and placed, and,
	 * if the block count reaches 0, the whole chunk section is not rendered, even if it still has blocks.
	 */
	BlockCount Short
	/* Consists of 4096 entries, representing all the blocks in the chunk section */
	BlockStates PalettedContainer
	/* Consists of 64 entries, representing 4x4x4 biome regions in the chunk section */
	Biomes PalettedContainer
}

func (*ChunkSection) DecodeFrom

func (c *ChunkSection) DecodeFrom(r *PacketReader) (err error)

func (*ChunkSection) Encode

func (c *ChunkSection) Encode(b *PacketBuilder)

type ClickAction added in v0.2.0

type ClickAction string
const (
	OpenUrl         ClickAction = "open_url"
	RunCommand      ClickAction = "run_command"
	SuggestCommand  ClickAction = "suggest_command"
	ChangePage      ClickAction = "change_page"
	CopyToClipboard ClickAction = "copy_to_clipboard"
)

type ClickEvent added in v0.2.0

type ClickEvent struct {
	Action ClickAction `json:"action"`
	Value  any         `json:"value"`
}

type CmdFlag

type CmdFlag Byte
const (
	// Values
	CmdTypeRoot    CmdFlag = 0x00
	CmdTypeLiteral CmdFlag = 0x01
	CmdTypeArg     CmdFlag = 0x02
	// Masks
	CmdTypeMask CmdFlag = 0x03 // 0: root, 1: literal, 2: argument. 3 is not used.
	CmdExec     CmdFlag = 0x04 // Set if the node stack to this point constitutes a valid command.
	CmdRedirect CmdFlag = 0x08 // Set if the node redirects to another node.
	CmdSuggest  CmdFlag = 0x10 // Only present for argument nodes.
)

type CmdPropEncoder

type CmdPropEncoder interface {
	Id() VarInt
	String() String
	Encode(b *PacketBuilder, value any) (err error)
	Decode(r *PacketReader) (value any, err error)
}

type CommandNode

type CommandNode struct {
	Flags           CmdFlag
	Children        []VarInt
	RedirectNode    Optional[VarInt]
	Name            Optional[String]
	ParserId        Optional[VarInt] // 1.19+
	ParserStrId     Optional[String] // 1.7 ~ 1.18
	Properties      any
	SuggestionsType Optional[String]
}

func (*CommandNode) DecodeFrom

func (c *CommandNode) DecodeFrom(r *PacketReader) (err error)

func (*CommandNode) Encode

func (c *CommandNode) Encode(b *PacketBuilder)

func (*CommandNode) GetParser

func (c *CommandNode) GetParser() (CmdPropEncoder, error)

func (*CommandNode) GetParserId

func (c *CommandNode) GetParserId() (VarInt, error)

func (*CommandNode) GetParserStrId

func (c *CommandNode) GetParserStrId() (String, error)

func (*CommandNode) HasFlag

func (c *CommandNode) HasFlag(f CmdFlag) bool

func (*CommandNode) Type

func (c *CommandNode) Type() CmdFlag

func (*CommandNode) Vaild

func (c *CommandNode) Vaild() bool

type Conn

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

func Dial

func Dial(target string) (c *Conn, err error)

Dial to a minecraft server

func DialWithContext

func DialWithContext(ctx context.Context, target string) (c *Conn, err error)

Dial to a minecraft server with given context

func WrapConn

func WrapConn(c net.Conn) *Conn

WrapConn wraps a raw net.Conn as a minecraft connection

func (*Conn) Close

func (c *Conn) Close() (err error)

Close will directly close the underlying connection

func (*Conn) Compressed added in v0.2.6

func (c *Conn) Compressed() bool

Compressed returns whether the connection is compressed or not (threshold >= 0)

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

LocalAddr returns the LocalAddr of the underlying connection

func (*Conn) Protocol

func (c *Conn) Protocol() int

Protocol returns the cached protocol from HandshakePkt

func (*Conn) RawConn

func (c *Conn) RawConn() net.Conn

RawConn returns the underlying connection

func (*Conn) Recv

func (c *Conn) Recv() (r *PacketReader, err error)

Recv read a packet and returns a PacketReader. The PacketReader is safely to read concurrently, but this method cannot be called concurrently.

func (*Conn) RecvHandshakePkt

func (c *Conn) RecvHandshakePkt() (pkt *HandshakePkt, err error)

For each connection, only one of the SendHandshakePkt or RecvHandshakePkt can be called, and it should be only called once. This method cannot be called concurrently

func (*Conn) RecvPkt

func (c *Conn) RecvPkt(id int32, pkt Decodable) (err error)

RecvPkt read a packet and parse it into the Decodable. It will assert the id while parsing the packet. This method cannot be called concurrently

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns the RemoteAddr of the underlying connection

func (*Conn) Send

func (c *Conn) Send(p *PacketBuilder) (err error)

Send sends data from a PacketBuilder It's thread-safe

func (*Conn) SendHandshakePkt

func (c *Conn) SendHandshakePkt(pkt *HandshakePkt) (err error)

SendHandshakePkt will encode the HandshakePkt into a PacketBuilder. For each connection, only one of the SendHandshakePkt or RecvHandshakePkt can be called, and it should be only called once. It's thread-safe, but you shouldn't call it more than one time

func (*Conn) SendPkt

func (c *Conn) SendPkt(id int32, value Encodable) (err error)

SendPkt encode the encodable value into a PacketBuilder with given ID and cached protocol. It will pass the builder to method Send. It's thread-safe

func (*Conn) SetThreshold added in v0.2.6

func (c *Conn) SetThreshold(threshold int)

SetThreshold will set the current connection's data compress threshold. It should only be called once

func (*Conn) Threshold added in v0.2.6

func (c *Conn) Threshold() int

Threshold returns the current connection's data compress threshold. Less than zero means the threshold is unset

type Decodable

type Decodable interface {
	DecodeFrom(r *PacketReader) (err error)
}

type DirectPalette

type DirectPalette struct{}

type DisconnectPkt added in v0.2.0

type DisconnectPkt struct {
	Reason *Chat
}

ID=0x00; Clientbound

func (*DisconnectPkt) DecodeFrom added in v0.2.0

func (p *DisconnectPkt) DecodeFrom(r *PacketReader) (err error)

func (DisconnectPkt) Encode added in v0.2.0

func (p DisconnectPkt) Encode(b *PacketBuilder)

type Double

type Double = float64

type EmptyCmdPropEncoder

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

func NewEmptyCmdPropEncoder

func NewEmptyCmdPropEncoder(id VarInt, sid string) *EmptyCmdPropEncoder

func (*EmptyCmdPropEncoder) Decode

func (p *EmptyCmdPropEncoder) Decode(r *PacketReader) (value any, err error)

func (*EmptyCmdPropEncoder) Encode

func (p *EmptyCmdPropEncoder) Encode(b *PacketBuilder, value any) (err error)

func (*EmptyCmdPropEncoder) Id

func (p *EmptyCmdPropEncoder) Id() VarInt

func (*EmptyCmdPropEncoder) String

func (p *EmptyCmdPropEncoder) String() String

type Encodable

type Encodable interface {
	Encode(p *PacketBuilder)
}

type Float

type Float = float32

type HandshakePkt

type HandshakePkt struct {
	Protocol  int
	Addr      string
	Addition  string
	Port      uint16
	NextState VarInt
}

It's on purpose that `HandshakePkt` didn't implement `Packet` interface To prevent accidently call with `Conn.SendPkt` or `Conn.RecvPkt` If you want to handle it, please use `Conn.SendHandshakePkt` or `Conn.RecvHandshakePkt` instead

func (*HandshakePkt) Decode

func (p *HandshakePkt) Decode(r *PacketReader) (err error)

func (HandshakePkt) EncodeTo

func (p HandshakePkt) EncodeTo(b *PacketBuilder)

func (HandshakePkt) String

func (p HandshakePkt) String() string

type HoverAction added in v0.2.0

type HoverAction string
const (
	ShowText   HoverAction = "show_text"
	ShowItem   HoverAction = "show_item"
	ShowEntity HoverAction = "show_entity"
)

type HoverEvent added in v0.2.0

type HoverEvent struct {
	Action  HoverAction `json:"action"`
	Content any         `json:"content"`
}

type HttpStatusError

type HttpStatusError struct {
	Code int
}

func (*HttpStatusError) Error

func (e *HttpStatusError) Error() string

type Identifier

type Identifier = String

type IndirectPalette

type IndirectPalette struct {
	Palette []VarInt
}

type Int

type Int = int32

type LoginAcknowledgedPkt added in v0.2.4

type LoginAcknowledgedPkt struct{}

ID=0x03; Serverbound; not before 1.20.2

func (*LoginAcknowledgedPkt) DecodeFrom added in v0.2.4

func (p *LoginAcknowledgedPkt) DecodeFrom(r *PacketReader) (err error)

func (LoginAcknowledgedPkt) Encode added in v0.2.4

func (p LoginAcknowledgedPkt) Encode(b *PacketBuilder)

func (LoginAcknowledgedPkt) String added in v0.2.4

func (p LoginAcknowledgedPkt) String() string

type LoginData

type LoginData struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type LoginEncryptionRequestPkt added in v0.2.4

type LoginEncryptionRequestPkt struct {
	ServerID  string         // Appears to be empty.
	PublicKey *rsa.PublicKey // encoded in ASN.1 DER format
	/* A sequence of random bytes generated by the server.
	 * Length of Verify Token is always 4 for Notchian servers. */
	VerifyToken ByteArray
}

ID=0x04; Clientbound

func (*LoginEncryptionRequestPkt) DecodeFrom added in v0.2.4

func (p *LoginEncryptionRequestPkt) DecodeFrom(r *PacketReader) (err error)

func (LoginEncryptionRequestPkt) Encode added in v0.2.4

type LoginEncryptionResponsePkt added in v0.2.4

type LoginEncryptionResponsePkt struct {
	SharedSecret ByteArray // Shared Secret value, encrypted with the server's public key.
	VerifyToken  ByteArray // Verify Token value, encrypted with the same public key as the shared secret.
}

ID=0x01; Serverbound

func (*LoginEncryptionResponsePkt) DecodeFrom added in v0.2.4

func (p *LoginEncryptionResponsePkt) DecodeFrom(r *PacketReader) (err error)

func (LoginEncryptionResponsePkt) Encode added in v0.2.4

type LoginSetCompressionPkt added in v0.2.6

type LoginSetCompressionPkt struct {
	Threshold VarInt // Maximum size of a packet before it is compressed.
}

ID=0x03; Clientbound

func (*LoginSetCompressionPkt) DecodeFrom added in v0.2.6

func (p *LoginSetCompressionPkt) DecodeFrom(r *PacketReader) (err error)

func (LoginSetCompressionPkt) Encode added in v0.2.6

type LoginStartPkt added in v0.2.4

type LoginStartPkt struct {
	Name string

	// if protocol >= 1.19 && protocol <= 1.19.2
	HasSign   bool
	Timestamp Long
	PublicKey ByteArray
	Sign      ByteArray

	// if protocol >= 1.19.1
	Id Optional[UUID]
}

ID=0x00; Serverbound

func (*LoginStartPkt) DecodeFrom added in v0.2.4

func (p *LoginStartPkt) DecodeFrom(r *PacketReader) (err error)

func (LoginStartPkt) Encode added in v0.2.4

func (p LoginStartPkt) Encode(b *PacketBuilder)

func (LoginStartPkt) String added in v0.2.4

func (p LoginStartPkt) String() string

type LoginSuccessPkt added in v0.2.4

type LoginSuccessPkt struct {
	// Before 1.16: Unlike in other packets, this field contains the UUID as a string with hyphens.
	UUID       UUID
	Username   string
	Properties []*Property
}

ID=0x02; Clientbound

func (*LoginSuccessPkt) DecodeFrom added in v0.2.4

func (p *LoginSuccessPkt) DecodeFrom(r *PacketReader) (err error)

func (*LoginSuccessPkt) Encode added in v0.2.4

func (p *LoginSuccessPkt) Encode(b *PacketBuilder)

type Long

type Long = int64

type NumRangeProp

type NumRangeProp[T numbers] struct {
	// contains filtered or unexported fields
}

func (*NumRangeProp[T]) Clear

func (p *NumRangeProp[T]) Clear()

func (*NumRangeProp[T]) HasMax

func (p *NumRangeProp[T]) HasMax() bool

func (*NumRangeProp[T]) HasMin

func (p *NumRangeProp[T]) HasMin() bool

func (*NumRangeProp[T]) InRange

func (p *NumRangeProp[T]) InRange(v T) bool

func (*NumRangeProp[T]) Max

func (p *NumRangeProp[T]) Max() T

func (*NumRangeProp[T]) Min

func (p *NumRangeProp[T]) Min() T

func (*NumRangeProp[T]) SetMax

func (p *NumRangeProp[T]) SetMax(max T) *NumRangeProp[T]

func (*NumRangeProp[T]) SetMin

func (p *NumRangeProp[T]) SetMin(min T) *NumRangeProp[T]

type Object

type Object = map[string]any

type OptBool added in v0.2.0

type OptBool int

OptBool is a simplified optional boolean type liter.TRUE means true liter.FALSE means false default value 0 means not set other values will cause undefined behaviour

const (
	TRUE  OptBool = 1
	FALSE OptBool = -1
)

func (OptBool) Bool added in v0.2.0

func (b OptBool) Bool() bool

func (OptBool) IsDefined added in v0.2.0

func (b OptBool) IsDefined() bool

func (OptBool) MarshalJSON added in v0.2.0

func (b OptBool) MarshalJSON() (buf []byte, err error)

func (OptBool) String added in v0.2.0

func (b OptBool) String() string

func (OptBool) ToBool added in v0.2.0

func (b OptBool) ToBool(def bool) bool

func (*OptBool) UnmarshalJSON added in v0.2.0

func (b *OptBool) UnmarshalJSON(buf []byte) (err error)

type Optional

type Optional[T any] struct {
	Ok bool
	V  T
}

func (Optional[T]) Assert

func (o Optional[T]) Assert() (v T)

func (Optional[T]) Encode

func (o Optional[T]) Encode(b *PacketBuilder)

func (*Optional[T]) Set

func (o *Optional[T]) Set(v T)

type Packet

type Packet interface {
	Encodable
	Decodable
}

type PacketBuilder

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

func NewPacket

func NewPacket(protocol int, id VarInt) (p *PacketBuilder)

func (*PacketBuilder) Bool

func (p *PacketBuilder) Bool(v bool) *PacketBuilder

func (*PacketBuilder) Byte

func (p *PacketBuilder) Byte(v Byte) *PacketBuilder

func (*PacketBuilder) ByteArray

func (p *PacketBuilder) ByteArray(buf []byte) *PacketBuilder

func (*PacketBuilder) Bytes

func (p *PacketBuilder) Bytes() (buf []byte)

Bytes returns the uncompressed packet data, does not include the packet length

func (*PacketBuilder) Chat added in v0.2.0

func (p *PacketBuilder) Chat(v *Chat) *PacketBuilder

func (*PacketBuilder) Data

func (p *PacketBuilder) Data() []byte

func (*PacketBuilder) Double

func (p *PacketBuilder) Double(v Double) *PacketBuilder

func (*PacketBuilder) Encode

func (p *PacketBuilder) Encode(v any)

func (*PacketBuilder) Float

func (p *PacketBuilder) Float(v Float) *PacketBuilder

func (*PacketBuilder) Id

func (p *PacketBuilder) Id() VarInt

func (*PacketBuilder) Int

func (p *PacketBuilder) Int(v Int) *PacketBuilder

func (*PacketBuilder) JSON

func (p *PacketBuilder) JSON(v any) *PacketBuilder

func (*PacketBuilder) Len

func (p *PacketBuilder) Len() int

func (*PacketBuilder) Long

func (p *PacketBuilder) Long(v Long) *PacketBuilder

func (*PacketBuilder) Protocol

func (p *PacketBuilder) Protocol() int

func (*PacketBuilder) Reset

func (p *PacketBuilder) Reset(protocol int, id VarInt) *PacketBuilder

func (*PacketBuilder) Short

func (p *PacketBuilder) Short(v Short) *PacketBuilder

func (*PacketBuilder) String

func (p *PacketBuilder) String(v String) *PacketBuilder

func (*PacketBuilder) UByte

func (p *PacketBuilder) UByte(v UByte) *PacketBuilder

func (*PacketBuilder) UShort

func (p *PacketBuilder) UShort(v UShort) *PacketBuilder

func (*PacketBuilder) UUID

func (p *PacketBuilder) UUID(v UUID) *PacketBuilder

func (*PacketBuilder) VarInt

func (p *PacketBuilder) VarInt(v VarInt) *PacketBuilder

func (*PacketBuilder) VarLong

func (p *PacketBuilder) VarLong(v VarLong) *PacketBuilder

func (*PacketBuilder) WriteCompressedTo added in v0.2.6

func (p *PacketBuilder) WriteCompressedTo(w io.Writer, threshold int) (n int64, err error)

WriteCompressedTo will write the packet to a writer, use with compression format

func (*PacketBuilder) WriteTo

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

WriteTo will write the packet to a writer, use without compression format

type PacketReader

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

func ReadPacket

func ReadPacket(protocol int, r io.Reader, compressed bool) (p *PacketReader, err error)

func ReadPacketFromBytes

func ReadPacketFromBytes(protocol int, buf []byte) (p *PacketReader)

func (*PacketReader) Bool

func (p *PacketReader) Bool() (v bool, ok bool)

func (*PacketReader) Byte

func (p *PacketReader) Byte() (v Byte, ok bool)

func (*PacketReader) ByteArray

func (p *PacketReader) ByteArray(buf []byte) (ok bool)

func (*PacketReader) Bytes

func (p *PacketReader) Bytes() []byte

func (*PacketReader) Chat added in v0.2.0

func (p *PacketReader) Chat() (c *Chat, err error)

func (*PacketReader) Double

func (p *PacketReader) Double() (v Double, ok bool)

func (*PacketReader) Float

func (p *PacketReader) Float() (v Float, ok bool)

func (*PacketReader) Id

func (p *PacketReader) Id() VarInt

func (*PacketReader) Int

func (p *PacketReader) Int() (v Int, ok bool)

func (*PacketReader) JSON

func (p *PacketReader) JSON(ptr any) (err error)

func (*PacketReader) Long

func (p *PacketReader) Long() (v Long, ok bool)

func (*PacketReader) Offset

func (p *PacketReader) Offset() int

func (*PacketReader) Protocol

func (p *PacketReader) Protocol() int

func (*PacketReader) ReadAll

func (p *PacketReader) ReadAll() (buf []byte)

func (*PacketReader) Remain

func (p *PacketReader) Remain() int

func (*PacketReader) Short

func (p *PacketReader) Short() (v Short, ok bool)

func (*PacketReader) String

func (p *PacketReader) String() (v String, ok bool)

func (*PacketReader) UByte

func (p *PacketReader) UByte() (v UByte, ok bool)

func (*PacketReader) UShort

func (p *PacketReader) UShort() (v UShort, ok bool)

func (*PacketReader) UUID

func (p *PacketReader) UUID() (v UUID, ok bool)

func (*PacketReader) Uint16

func (p *PacketReader) Uint16() (v uint16, ok bool)

func (*PacketReader) Uint32

func (p *PacketReader) Uint32() (v uint32, ok bool)

func (*PacketReader) Uint64

func (p *PacketReader) Uint64() (v uint64, ok bool)

func (*PacketReader) Uint8

func (p *PacketReader) Uint8() (v uint8, ok bool)

func (*PacketReader) VarInt

func (p *PacketReader) VarInt() (v VarInt, ok bool)

func (*PacketReader) VarLong

func (p *PacketReader) VarLong() (v VarLong, ok bool)

type PalettedContainer

type PalettedContainer struct {

	/*
	 * Determines how many bits are used to encode entries. Note that not all numbers are valid here.
	 * Single valued: when bits per entry is equal to 0
	 * Indirect:
	 *  - For block states with bits per entry <= 4, 4 bits are used to represent a block.
	 *  - For block states and bits per entry between 5 and 8, the given value is used.
	 *  - For biomes the given value is always used, and will be <= 3
	 * Direct: bits per entry values greater than or equal to a threshold (9 for block states, 4 for biomes).
	 */
	BitsPerEntry UByte
	/*
	 * The bits per entry value determines what format is used for the palette.
	 * In most cases, invalid values will be interpreted as a different value when parsed by the notchian client,
	 * meaning that chunk data will be parsed incorrectly if you use an invalid bits per entry.
	 * Servers must make sure that the bits per entry value is correct.
	 */
	Palette any
	/* Compacted list of indices pointing to entry IDs in the Palette. When Bits Per Entry is 0, this array is empty (see Single valued palette) */
	DataArray []Long
	// contains filtered or unexported fields
}

func (*PalettedContainer) DecodeFrom

func (c *PalettedContainer) DecodeFrom(r *PacketReader) (err error)

func (PalettedContainer) Encode

func (c PalettedContainer) Encode(b *PacketBuilder)

type PingRequestPkt

type PingRequestPkt struct {
	Payload int64
}

func (*PingRequestPkt) DecodeFrom

func (p *PingRequestPkt) DecodeFrom(r *PacketReader) (err error)

func (PingRequestPkt) Encode

func (p PingRequestPkt) Encode(b *PacketBuilder)

func (PingRequestPkt) String

func (p PingRequestPkt) String() string

type PingResponsePkt

type PingResponsePkt struct {
	Payload int64
}

func (*PingResponsePkt) DecodeFrom

func (p *PingResponsePkt) DecodeFrom(r *PacketReader) (err error)

func (PingResponsePkt) Encode

func (p PingResponsePkt) Encode(b *PacketBuilder)

func (PingResponsePkt) String

func (p PingResponsePkt) String() string

type PktIdAssertError

type PktIdAssertError struct {
	Require int32
	Got     int32
}

func (*PktIdAssertError) Error

func (e *PktIdAssertError) Error() string

type PlayerInfo added in v0.2.0

type PlayerInfo struct {
	Name string `json:"name"`
	Id   UUID   `json:"id"`
}

type PlayerProfile added in v0.2.0

type PlayerProfile struct {
	Id             UUID        `json:"id"`
	Name           string      `json:"name"`
	Properties     []*Property `json:"properties`
	ProfileActions []string    `json:"profileActions"`
}

func (*PlayerProfile) GetProp added in v0.2.3

func (p *PlayerProfile) GetProp(name string) (t *Property)

func (*PlayerProfile) GetSkin added in v0.2.3

func (p *PlayerProfile) GetSkin(cli *http.Client) (skin *Skin, err error)

type PlayerStatus added in v0.2.0

type PlayerStatus struct {
	Max    int          `json:"max"`
	Online int          `json:"online"`
	Sample []PlayerInfo `json:"sample,omitempty"`
}

type Position

type Position struct {
	X int
	Y int
	Z int
}

func PositionFromLong

func PositionFromLong(n Long) (p Position)

func (Position) AsLong

func (p Position) AsLong() (n Long)

func (*Position) DecodeFrom

func (p *Position) DecodeFrom(r *PacketReader) (err error)

func (Position) Encode

func (p Position) Encode(b *PacketBuilder)

type Prop

type Prop struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Property added in v0.2.0

type Property struct {
	Name  string `json:"name"`
	Value string `json:"value"`
	Sign  string `json:"signature,omitempty"`
}

func (*Property) DecodeFrom added in v0.2.4

func (p *Property) DecodeFrom(r *PacketReader) (err error)

func (*Property) Encode added in v0.2.4

func (p *Property) Encode(b *PacketBuilder)

func (*Property) UnmarshalJSONValue added in v0.2.3

func (p *Property) UnmarshalJSONValue(ptr any) (err error)

type Props

type Props []Prop

type ProtocolVersion added in v0.2.0

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

type RefreshResponse

type RefreshResponse struct {
	User        UserData `json:"user"`
	ClientToken string   `json:"clientToken"`
	AccessToken string   `json:"accessToken"`

	SelectedProfile PlayerInfo `json:"selectedProfile"`
}

type ScoreComponent added in v0.2.0

type ScoreComponent struct {
	Name      string `json:"name"`
	Objective string `json:"objective"`
	Value     int    `json:"value"`
}

type Short

type Short = int16

type SingleValuedPalette

type SingleValuedPalette struct {
	Value VarInt
}

type Skin added in v0.2.3

type Skin struct {
	// HTTP cache
	Etag string
	// contains filtered or unexported fields
}

https://minecraft.wiki/w/Skin

func (*Skin) Head added in v0.2.3

func (s *Skin) Head() image.Image

type StatusRequestPkt

type StatusRequestPkt struct{}

func (*StatusRequestPkt) DecodeFrom

func (p *StatusRequestPkt) DecodeFrom(r *PacketReader) (err error)

func (StatusRequestPkt) Encode

func (p StatusRequestPkt) Encode(b *PacketBuilder)

func (StatusRequestPkt) String

func (p StatusRequestPkt) String() string

type StatusResponsePayload added in v0.2.0

type StatusResponsePayload struct {
	Version     ProtocolVersion `json:"version"`
	Players     PlayerStatus    `json:"players"`
	Description *Chat           `json:"description"`
}

type StatusResponsePkt

type StatusResponsePkt struct {
	Payload StatusResponsePayload
}

func (*StatusResponsePkt) DecodeFrom

func (p *StatusResponsePkt) DecodeFrom(r *PacketReader) (err error)

func (StatusResponsePkt) Encode

func (p StatusResponsePkt) Encode(b *PacketBuilder)

func (StatusResponsePkt) String

func (p StatusResponsePkt) String() string

type String

type String = string

type Tag

type Tag struct {
	Name    Identifier
	Entries []VarInt
}

func (*Tag) DecodeFrom

func (t *Tag) DecodeFrom(r *PacketReader) (err error)

func (Tag) Encode

func (t Tag) Encode(b *PacketBuilder)

type UByte

type UByte = uint8

type UShort

type UShort = uint16

type UUID

type UUID = uuid.UUID

type UserData

type UserData struct {
	Username   string `json:"username"`
	Id         string `json:"id"`
	Properties Props  `json:"properties"`
}

type VarInt

type VarInt int32

type VarLong

type VarLong int64

type YggError

type YggError struct {
	Code         int    `json:"-"`
	ErrorShort   string `json:"error"`
	ErrorMessage string `json:"errorMessage"`
	Cause        string `json:"cause,omitempty"`
}

func (*YggError) Error

func (e *YggError) Error() (s string)

Directories

Path Synopsis
cmds
This package provide packet types which used NBT And also the types changed between versions
This package provide packet types which used NBT And also the types changed between versions

Jump to

Keyboard shortcuts

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