mcprotocol

package
v0.0.0-...-a5406a4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Chat = iota
	System
	GameInfo
	SayCommand
	MsgCommand
	TeamMsgCommand
	EmoteCommand
	TellrawCommand
)
View Source
const (
	Black       = "black"
	DarkBlue    = "dark_blue"
	DarkGreen   = "dark_green"
	DarkAqua    = "dark_aqua"
	DarkRed     = "dark_red"
	DarkPurple  = "dark_purple"
	Gold        = "gold"
	Gray        = "gray"
	DarkGray    = "dark_gray"
	Blue        = "blue"
	Green       = "green"
	Aqua        = "aqua"
	Red         = "red"
	LightPurple = "light_purple"
	Yellow      = "yellow"
	White       = "white"
)

Colors

View Source
const (
	BooleanTrue  = 0x01
	BooleanFalse = 0x00
)
View Source
const MaxVarIntLen = 5

Variables

View Source
var ErrVarIntTooBig = errors.New("VarInt is too big")

Functions

func AppendPacketLength

func AppendPacketLength(buffer *buf.Buffer, l int)

func PutVarInt

func PutVarInt(bs []byte, n int32) (numWrite int)

PutVarInt encodes a Minecraft variable-length format int32 into bs and returns the number of bytes written. If the buffer is too small, PutVarInt will panic.

func ReadInt

func ReadInt(buffer *buf.Buffer) (int, error)

ReadInt reads an 32-bit signed integer from buffer. Note that even though int type in Go may be 64-bit, we only treat it as an int32 in this method.

func ReadInt16

func ReadInt16(buffer *buf.Buffer) (int16, error)

func ReadInt32

func ReadInt32(buffer *buf.Buffer) (int32, error)

func ReadInt64

func ReadInt64(buffer *buf.Buffer) (int64, error)

func ReadInt8

func ReadInt8(buffer *buf.Buffer) (int8, error)

func ReadString

func ReadString(buffer *buf.Buffer) (string, error)

func ReadUint16

func ReadUint16(buffer *buf.Buffer) (uint16, error)

func ReadUint32

func ReadUint32(buffer *buf.Buffer) (uint32, error)

func ReadUint64

func ReadUint64(buffer *buf.Buffer) (uint64, error)

func ReadVarIntFrom

func ReadVarIntFrom(r io.Reader) (i int32, n int64, err error)

func Scan

func Scan(buffer *buf.Buffer, item ...any) (err error)

func VarIntLen

func VarIntLen(n int32) int

func WriteToPacket

func WriteToPacket(buffer *buf.Buffer, item ...any) (err error)

Types

type Conn

type Conn struct {
	io.Reader
	io.Writer
	net.Conn
}

func StreamConn

func StreamConn(conn net.Conn) Conn

func (Conn) ReadLimitedPacket

func (c Conn) ReadLimitedPacket(buffer *buf.Buffer, maxLen int) (err error)

ReadLimitedPacket likes ReadPacket, but limits the maximum number of packet content bytes to read to maxLen.

func (Conn) ReadPacket

func (c Conn) ReadPacket(buffer *buf.Buffer) error

ReadPacket reads a full packet to buffer.

func (Conn) WritePacket

func (c Conn) WritePacket(buffer *buf.Buffer) (err error)

WritePacket appends packet length to packet head, and writes to Conn. Then reset the buffer to MaxVarIntLen. Note that the given buffer should have at least 5 bytes front headroom space.

func (Conn) WriteVectorizedPacket

func (c Conn) WriteVectorizedPacket(buffer *buf.Buffer, packets ...[]byte) (err error)

WriteVectorizedPacket appends the sum of length of packets to the buffer head, and writes all the packets to Conn. Then reset the buffer to MaxVarIntLen. This function would attempt to write packets using writev syscall to optimize performance, if the platform is available. Note that the given buffer should have at least 5 bytes front headroom space.

type Message

type Message struct {
	Text string `json:"text"`

	Bold          bool `json:"bold,omitempty"`          // 粗体
	Italic        bool `json:"italic,omitempty"`        // 斜体
	UnderLined    bool `json:"underlined,omitempty"`    // 下划线
	StrikeThrough bool `json:"strikethrough,omitempty"` // 删除线
	Obfuscated    bool `json:"obfuscated,omitempty"`    // 随机
	// Font of the message, could be one of minecraft:uniform, minecraft:alt or minecraft:default
	// This option is only valid on 1.16+, otherwise the property is ignored.
	Font  string `json:"font,omitempty"`  // 字体
	Color string `json:"color,omitempty"` // 颜色

	// Insertion contains text to insert. Only used for messages in chat.
	// When shift is held, clicking the component inserts the given text
	// into the chat box at the cursor (potentially replacing selected text).
	Insertion string `json:"insertion,omitempty"`

	Translate string    `json:"translate,omitempty"`
	With      []Message `json:"with,omitempty"`
	Extra     []Message `json:"extra,omitempty"`
}

Message is a message sent by other

func (Message) MarshalJSON

func (m Message) MarshalJSON() ([]byte, error)

func (*Message) ReadMessage

func (m *Message) ReadMessage(buffer *buf.Buffer) error

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(raw []byte) (err error)

UnmarshalJSON decode json to Message

func (Message) WriteTo

func (m Message) WriteTo(w io.Writer) (int64, error)

WriteTo encode Message into a ChatMsg packet

type VarInt

type VarInt int32

func (VarInt) Value

func (i VarInt) Value() int

func (VarInt) Value32

func (i VarInt) Value32() int32

func (VarInt) WriteTo

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

func (VarInt) WriteToBuffer

func (i VarInt) WriteToBuffer(buffer *buf.Buffer)

Jump to

Keyboard shortcuts

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