Documentation ¶
Overview ¶
This package provide some useful data encode/decode
Index ¶
- Constants
- Variables
- func GetProtocolName(p int) string
- func IsProtocolSupport(p int) bool
- func RegisterCmdEncoder(p CmdPropEncoder) (ok bool)
- func ResloveAddr(target string) (addr *net.TCPAddr, err error)
- func ResloveAddrWithContext(ctx context.Context, target string) (addr *net.TCPAddr, err error)
- func ToNearestProtocol(p int) int
- func UnregisterCmdEncoder(p CmdPropEncoder) (ok bool)
- type AccessData
- type Angle
- type AuthClient
- func (cli *AuthClient) Auth(data AuthData) (res *AuthResponse, err error)
- func (cli *AuthClient) GetPlayerInfo(name string) (player PlayerInfo, err error)
- func (cli *AuthClient) GetPlayerProfile(id UUID) (profile *PlayerProfile, err error)
- func (cli *AuthClient) Invalidate(data AccessData) (err error)
- func (cli *AuthClient) Refresh(data AccessData) (res *RefreshResponse, err error)
- func (cli *AuthClient) Signout(data LoginData) (err error)
- func (cli *AuthClient) Validate(data AccessData) (err error)
- type AuthData
- type AuthResponse
- type BitSet
- type Bool
- type Byte
- type ByteArray
- type Chat
- type ChatType
- type ChunkSection
- type ClickAction
- type ClickEvent
- type CmdFlag
- type CmdPropEncoder
- type CommandNode
- func (c *CommandNode) DecodeFrom(r *PacketReader) (err error)
- func (c *CommandNode) Encode(b *PacketBuilder)
- func (c *CommandNode) GetParser() (CmdPropEncoder, error)
- func (c *CommandNode) GetParserId() (VarInt, error)
- func (c *CommandNode) GetParserStrId() (String, error)
- func (c *CommandNode) HasFlag(f CmdFlag) bool
- func (c *CommandNode) Type() CmdFlag
- func (c *CommandNode) Vaild() bool
- type Conn
- func (c *Conn) Close() (err error)
- func (c *Conn) Compressed() bool
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Protocol() int
- func (c *Conn) RawConn() net.Conn
- func (c *Conn) Recv() (r *PacketReader, err error)
- func (c *Conn) RecvHandshakePkt() (pkt *HandshakePkt, err error)
- func (c *Conn) RecvPkt(id int32, pkt Decodable) (err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) Send(p *PacketBuilder) (err error)
- func (c *Conn) SendHandshakePkt(pkt *HandshakePkt) (err error)
- func (c *Conn) SendPkt(id int32, value Encodable) (err error)
- func (c *Conn) SetThreshold(threshold int)
- func (c *Conn) Threshold() int
- type Decodable
- type DirectPalette
- type DisconnectPkt
- type Double
- type EmptyCmdPropEncoder
- type Encodable
- type Float
- type HandshakePkt
- type HoverAction
- type HoverEvent
- type HttpStatusError
- type Identifier
- type IndirectPalette
- type Int
- type LoginAcknowledgedPkt
- type LoginData
- type LoginEncryptionRequestPkt
- type LoginEncryptionResponsePkt
- type LoginSetCompressionPkt
- type LoginStartPkt
- type LoginSuccessPkt
- type Long
- type NumRangeProp
- func (p *NumRangeProp[T]) Clear()
- func (p *NumRangeProp[T]) HasMax() bool
- func (p *NumRangeProp[T]) HasMin() bool
- func (p *NumRangeProp[T]) InRange(v T) bool
- func (p *NumRangeProp[T]) Max() T
- func (p *NumRangeProp[T]) Min() T
- func (p *NumRangeProp[T]) SetMax(max T) *NumRangeProp[T]
- func (p *NumRangeProp[T]) SetMin(min T) *NumRangeProp[T]
- type Object
- type OptBool
- type Optional
- type Packet
- type PacketBuilder
- func (p *PacketBuilder) Bool(v bool) *PacketBuilder
- func (p *PacketBuilder) Byte(v Byte) *PacketBuilder
- func (p *PacketBuilder) ByteArray(buf []byte) *PacketBuilder
- func (p *PacketBuilder) Bytes() (buf []byte)
- func (p *PacketBuilder) Chat(v *Chat) *PacketBuilder
- func (p *PacketBuilder) Data() []byte
- func (p *PacketBuilder) Double(v Double) *PacketBuilder
- func (p *PacketBuilder) Encode(v any)
- func (p *PacketBuilder) Float(v Float) *PacketBuilder
- func (p *PacketBuilder) Id() VarInt
- func (p *PacketBuilder) Int(v Int) *PacketBuilder
- func (p *PacketBuilder) JSON(v any) *PacketBuilder
- func (p *PacketBuilder) Len() int
- func (p *PacketBuilder) Long(v Long) *PacketBuilder
- func (p *PacketBuilder) Protocol() int
- func (p *PacketBuilder) Reset(protocol int, id VarInt) *PacketBuilder
- func (p *PacketBuilder) Short(v Short) *PacketBuilder
- func (p *PacketBuilder) String(v String) *PacketBuilder
- func (p *PacketBuilder) UByte(v UByte) *PacketBuilder
- func (p *PacketBuilder) UShort(v UShort) *PacketBuilder
- func (p *PacketBuilder) UUID(v UUID) *PacketBuilder
- func (p *PacketBuilder) VarInt(v VarInt) *PacketBuilder
- func (p *PacketBuilder) VarLong(v VarLong) *PacketBuilder
- func (p *PacketBuilder) WriteCompressedTo(w io.Writer, threshold int) (n int64, err error)
- func (p *PacketBuilder) WriteTo(w io.Writer) (n int64, err error)
- type PacketReader
- func (p *PacketReader) Bool() (v bool, ok bool)
- func (p *PacketReader) Byte() (v Byte, ok bool)
- func (p *PacketReader) ByteArray(buf []byte) (ok bool)
- func (p *PacketReader) Bytes() []byte
- func (p *PacketReader) Chat() (c *Chat, err error)
- func (p *PacketReader) Double() (v Double, ok bool)
- func (p *PacketReader) Float() (v Float, ok bool)
- func (p *PacketReader) Id() VarInt
- func (p *PacketReader) Int() (v Int, ok bool)
- func (p *PacketReader) JSON(ptr any) (err error)
- func (p *PacketReader) Long() (v Long, ok bool)
- func (p *PacketReader) Offset() int
- func (p *PacketReader) Protocol() int
- func (p *PacketReader) ReadAll() (buf []byte)
- func (p *PacketReader) Remain() int
- func (p *PacketReader) Short() (v Short, ok bool)
- func (p *PacketReader) String() (v String, ok bool)
- func (p *PacketReader) UByte() (v UByte, ok bool)
- func (p *PacketReader) UShort() (v UShort, ok bool)
- func (p *PacketReader) UUID() (v UUID, ok bool)
- func (p *PacketReader) Uint16() (v uint16, ok bool)
- func (p *PacketReader) Uint32() (v uint32, ok bool)
- func (p *PacketReader) Uint64() (v uint64, ok bool)
- func (p *PacketReader) Uint8() (v uint8, ok bool)
- func (p *PacketReader) VarInt() (v VarInt, ok bool)
- func (p *PacketReader) VarLong() (v VarLong, ok bool)
- type PalettedContainer
- type PingRequestPkt
- type PingResponsePkt
- type PktIdAssertError
- type PlayerInfo
- type PlayerProfile
- type PlayerStatus
- type Position
- type Prop
- type Property
- type Props
- type ProtocolVersion
- type RefreshResponse
- type ScoreComponent
- type Short
- type SingleValuedPalette
- type Skin
- type StatusRequestPkt
- type StatusResponsePayload
- type StatusResponsePkt
- type String
- type Tag
- type UByte
- type UShort
- type UUID
- type UserData
- type VarInt
- type VarLong
- type YggError
Constants ¶
const ( NextPingState = 1 NextLoginState = 2 )
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 )
const ( DefaultApiServer = "https://api.mojang.com/" DefaultAuthServer = "https://authserver.mojang.com/" DefaultSessionServer = "https://sessionserver.mojang.com/session/minecraft/" )
const DefaultPort = 25565
Variables ¶
var ( ErrParserIdNotExists = errors.New("liter.CommandNode: parser id is not exists") ErrParserInstanceNotExists = errors.New("liter.CommandNode: command parser instance not exists") )
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 )
var ( ErrPlayerNameInvalid = errors.New("Player name is invalid") ErrPlayerNotExists = errors.New("Player not exists on the server") )
var DefaultAuthClient = &AuthClient{ Client: &http.Client{}, ApiServer: DefaultApiServer, AuthServer: DefaultAuthServer, SessionServer: DefaultSessionServer, }
var VarIntTooBig = errors.New("VarInt is too big")
var VarLongTooBig = errors.New("VarLong is too big")
Functions ¶
func GetProtocolName ¶
func IsProtocolSupport ¶
func RegisterCmdEncoder ¶
func RegisterCmdEncoder(p CmdPropEncoder) (ok bool)
func ResloveAddr ¶
Resolve the minecraft server's hostport with the given address
func ResloveAddrWithContext ¶
Resolve the minecraft server's hostport with the given address and cancel context
func ToNearestProtocol ¶
func UnregisterCmdEncoder ¶
func UnregisterCmdEncoder(p CmdPropEncoder) (ok bool)
Types ¶
type AccessData ¶
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 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 NewBitSetWith ¶
func (*BitSet) DecodeFrom ¶
func (s *BitSet) DecodeFrom(r *PacketReader) (err error)
func (BitSet) Encode ¶
func (s BitSet) Encode(p *PacketBuilder)
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 (*Chat) MarshalJSON ¶ added in v0.2.0
func (*Chat) Plain ¶ added in v0.2.0
Plain() will return the plain text value for the chat component
func (*Chat) UnmarshalJSON ¶ added in v0.2.0
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 DialWithContext ¶
Dial to a minecraft server with given context
func (*Conn) Compressed ¶ added in v0.2.6
Compressed returns whether the connection is compressed or not (threshold >= 0)
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 ¶
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 ¶
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 ¶
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
SetThreshold will set the current connection's data compress threshold. It should only be called once
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 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 HandshakePkt ¶
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 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 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
func (p LoginEncryptionRequestPkt) Encode(b *PacketBuilder)
type LoginEncryptionResponsePkt ¶ added in v0.2.4
type LoginEncryptionResponsePkt struct { 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
func (p LoginEncryptionResponsePkt) Encode(b *PacketBuilder)
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
func (p LoginSetCompressionPkt) Encode(b *PacketBuilder)
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 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 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
func (OptBool) MarshalJSON ¶ added in v0.2.0
func (*OptBool) UnmarshalJSON ¶ added in v0.2.0
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
WriteCompressedTo will write the packet to a writer, use with compression format
type PacketReader ¶
type PacketReader struct {
// contains filtered or unexported fields
}
func ReadPacket ¶
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 ¶
func (*PktIdAssertError) Error ¶
func (e *PktIdAssertError) Error() string
type PlayerInfo ¶ added in v0.2.0
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)
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 ¶
func PositionFromLong ¶
func (*Position) DecodeFrom ¶
func (p *Position) DecodeFrom(r *PacketReader) (err error)
func (Position) Encode ¶
func (p Position) Encode(b *PacketBuilder)
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
type ProtocolVersion ¶ added in v0.2.0
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 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 }
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 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)
Source Files ¶
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 |