protocol

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HandShakePacketId  = 0x00 // handshake state, C2S
	DisconnectPacketId = 0x00 // login state, S2C

	HandshakeNextStateStatus = 1
	HandshakeNextStateLogin  = 2
)

Variables

This section is empty.

Functions

func WritePacket

func WritePacket(writer BufWriter, packet Packet) error

Types

type BufReadWriter added in v0.1.0

type BufReadWriter interface {
	BufReader
	PeekableReader
	BufWriter
}

func NewBufferReadWriter added in v0.1.0

func NewBufferReadWriter(buf io.ReadWriter) BufReadWriter

type BufReader added in v0.1.0

type BufReader interface {
	PeekableReader

	GetReadLen() int
	Read(n int) ([]byte, error)

	ReadUInt8() (uint8, error)   // Unsigned byte
	ReadUInt16() (uint16, error) // Unsigned Short
	ReadInt16() (int16, error)   // Short
	ReadUInt32() (uint32, error) // Unsigned Int
	ReadInt32() (int32, error)   // Int

	ReadVarInt() (int32, error)
	ReadString() (string, error)
	ReadUTF16BE() (string, error)
}

type BufWriter added in v0.1.0

type BufWriter interface {
	GetWriteLen() int
	Write(b []byte) error

	WriteUInt8(value uint8) error   // Unsigned byte
	WriteUInt16(value uint16) error // Unsigned Short
	WriteInt16(value int16) error   // Short
	WriteUInt32(value uint32) error // Unsigned Int
	WriteInt32(value int32) error   // Int

	WriteVarInt(value int32) error
	WriteString(s string) error
	WriteUTF16BE(s string) error
}

type DisconnectPacket

type DisconnectPacket struct {
	Reason string
}

DisconnectPacket is in login state, S2C

func (*DisconnectPacket) GetId

func (p *DisconnectPacket) GetId() int32

func (*DisconnectPacket) ReadFrom

func (p *DisconnectPacket) ReadFrom(reader BufReader) error

func (*DisconnectPacket) WriteTo

func (p *DisconnectPacket) WriteTo(writer BufWriter) error

type HandshakePacket

type HandshakePacket struct {
	Protocol  int32
	Hostname  string
	Port      uint16
	NextState int32
}

HandshakePacket is in handshake state, C2S

func (*HandshakePacket) GetHostname added in v0.1.0

func (p *HandshakePacket) GetHostname() *string

func (*HandshakePacket) GetId

func (p *HandshakePacket) GetId() int32

func (*HandshakePacket) GetPort added in v0.1.0

func (p *HandshakePacket) GetPort() *uint16

func (*HandshakePacket) IsLegacy added in v0.1.0

func (p *HandshakePacket) IsLegacy() bool

func (*HandshakePacket) ReadFrom

func (p *HandshakePacket) ReadFrom(reader BufReader) error

func (*HandshakePacket) WriteTo

func (p *HandshakePacket) WriteTo(writer BufWriter) error

type IHandshakePacket added in v0.1.0

type IHandshakePacket interface {
	Packet
	IsLegacy() bool
	GetHostname() *string
	GetPort() *uint16
}

func ReadHandshakePacket

func ReadHandshakePacket(reader BufReader) (IHandshakePacket, error)

type LegacyServerListPingPacket added in v0.1.0

type LegacyServerListPingPacket struct {
	Header   []byte // the first 27 bytes of whatever things. see legacyServerPingHead
	Protocol uint8
	Hostname string
	Port     uint16
}

LegacyServerListPingPacket is in handshake state, C2S see https://wiki.vg/Server_List_Ping#1.6

func (*LegacyServerListPingPacket) GetHostname added in v0.1.0

func (p *LegacyServerListPingPacket) GetHostname() *string

func (*LegacyServerListPingPacket) GetPort added in v0.1.0

func (p *LegacyServerListPingPacket) GetPort() *uint16

func (*LegacyServerListPingPacket) IsLegacy added in v0.1.0

func (p *LegacyServerListPingPacket) IsLegacy() bool

func (*LegacyServerListPingPacket) ReadFrom added in v0.1.0

func (p *LegacyServerListPingPacket) ReadFrom(reader BufReader) error

func (*LegacyServerListPingPacket) WriteTo added in v0.1.0

func (p *LegacyServerListPingPacket) WriteTo(writer BufWriter) error

type ModernPacket added in v0.1.0

type ModernPacket interface {
	Packet
	GetId() int32
}

func ReadModernPacket added in v0.1.0

func ReadModernPacket(reader BufReader, packetFactory func(int32) (ModernPacket, error)) (ModernPacket, error)

type Packet

type Packet interface {
	ReadFrom(reader BufReader) error
	WriteTo(writer BufWriter) error
}

type PeekableReader added in v0.1.0

type PeekableReader interface {
	// PeekByte for detecting the legacy ping packet
	PeekByte() (byte, error)
}

Jump to

Keyboard shortcuts

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