protocol_impl

package module
v0.0.0-...-500f755 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 9 Imported by: 0

README

protocol_impl

An implementation of the Minecraft protocol

Some of my code is inspired by go-mc, but I did not just skid, I researched most of the things online to understand them. I'm doing this because I am interested in the functionality of the Minecraft protocol.

Documentation

Index

Constants

View Source
const (
	PacketHandshakeSvHandshake            = 0x00
	PacketHandshakeSvLegacyServerListPing = 0xFE

	PacketStatusClResponse = 0x00
	PacketStatusClPong     = 0x01
	PacketStatusSvRequest  = 0x00
	PacketStatusSvPing     = 0x01

	PacketLoginClDisconnect          = 0x00
	PacketLoginClEncryptionRequest   = 0x01
	PacketLoginClLoginSuccess        = 0x02
	PacketLoginClSetCompression      = 0x03
	PacketLoginClLoginPluginRequest  = 0x04
	PacketLoginSvLoginStart          = 0x00
	PacketLoginSvEncryptionResponse  = 0x01
	PacketLoginSvLoginPluginResponse = 0x02

	PacketPlayClSpawnEntity                = 0x00
	PacketPlayClSpawnExperienceOrb         = 0x01
	PacketPlayClSpawnWeatherEntity         = 0x02
	PacketPlayClSpawnLivingEntity          = 0x03
	PacketPlayClSpawnPainting              = 0x04
	PacketPlayClSpawnPlayer                = 0x05
	PacketPlayClEntityAnimation            = 0x06
	PacketPlayClStatistics                 = 0x07
	PacketPlayClAcknowledgePlayerDigging   = 0x08
	PacketPlayClBlockBreakAnimation        = 0x09
	PacketPlayClBlockEntityData            = 0x0A
	PacketPlayClBlockAction                = 0x0B
	PacketPlayClBlockChange                = 0x0C
	PacketPlayClBossBar                    = 0x0D
	PacketPlayClServerDifficulty           = 0x0E
	PacketPlayClChatMessage                = 0x0F
	PacketPlayClMultiBlockChange           = 0x10
	PacketPlayClTabComplete                = 0x11
	PacketPlayClDeclareCommands            = 0x12
	PacketPlayClWindowConfirmation         = 0x13
	PacketPlayClCloseWindow                = 0x14
	PacketPlayClWindowItems                = 0x15
	PacketPlayClWindowProperty             = 0x16
	PacketPlayClSetSlot                    = 0x17
	PacketPlayClSetCooldown                = 0x18
	PacketPlayClPluginMessage              = 0x19
	PacketPlayClNamedSoundEffect           = 0x1A
	PacketPlayClDisconnect                 = 0x1B
	PacketPlayClEntityStatus               = 0x1C
	PacketPlayClExplosions                 = 0x1D
	PacketPlayClUnloadChunk                = 0x1E
	PacketPlayClChangeGameState            = 0x1F
	PacketPlayClOpenHorseWindow            = 0x20
	PacketPlayClKeepAlive                  = 0x21
	PacketPlayClChunkData                  = 0x22
	PacketPlayClEffect                     = 0x23
	PacketPlayClParticle                   = 0x24
	PacketPlayClUpdateLight                = 0x25
	PacketPlayClJoinGame                   = 0x26
	PacketPlayClMapData                    = 0x27
	PacketPlayClTradeList                  = 0x28
	PacketPlayClEntityPosition             = 0x29
	PacketPlayClEntityPositionAndRotation  = 0x2A
	PacketPlayClEntityRotation             = 0x2B
	PacketPlayClEntityMovement             = 0x2C
	PacketPlayClVehicleMove                = 0x2D
	PacketPlayClOpenBook                   = 0x2E
	PacketPlayClOpenWindow                 = 0x2F
	PacketPlayClOpenSignEditor             = 0x30
	PacketPlayClCraftRecipeResponse        = 0x31
	PacketPlayClPlayerAbilities            = 0x32
	PacketPlayClCombatEvent                = 0x33
	PacketPlayClPlayerInfo                 = 0x34
	PacketPlayClFacePlayer                 = 0x35
	PacketPlayClPlayerPositionAndLook      = 0x36
	PacketPlayClUnlockRecipes              = 0x37
	PacketPlayClDestroyEntities            = 0x38
	PacketPlayClRemoveEntityEffect         = 0x39
	PacketPlayClResourcePackSend           = 0x3A
	PacketPlayClRespawn                    = 0x3B
	PacketPlayClEntityHeadLook             = 0x3C
	PacketPlayClSelectAdvancementTab       = 0x3D
	PacketPlayClWorldBorder                = 0x3E
	PacketPlayClCamera                     = 0x3F
	PacketPlayClHeldItemChange             = 0x40
	PacketPlayClUpdateViewPosition         = 0x41
	PacketPlayClUpdateViewDistance         = 0x42
	PacketPlayClDisplayScoreboard          = 0x43
	PacketPlayClEntityMetadata             = 0x44
	PacketPlayClAttachEntity               = 0x45
	PacketPlayClEntityVelocity             = 0x46
	PacketPlayClEntityEquipment            = 0x47
	PacketPlayClSetExperience              = 0x48
	PacketPlayClUpdateHealth               = 0x49
	PacketPlayClScoreboardObjective        = 0x4A
	PacketPlayClSetPassengers              = 0x4B
	PacketPlayClTeams                      = 0x4C
	PacketPlayClUpdateScore                = 0x4D
	PacketPlayClSpawnPosition              = 0x4E
	PacketPlayClTimeUpdate                 = 0x4F
	PacketPlayClTitle                      = 0x50
	PacketPlayClEntitySoundEffect          = 0x51
	PacketPlayClSoundEffect                = 0x52
	PacketPlayClStopSound                  = 0x53
	PacketPlayClPlayerListHeaderAndFooter  = 0x54
	PacketPlayClNBTQueryResponse           = 0x55
	PacketPlayClCollectItem                = 0x56
	PacketPlayClEntityTeleport             = 0x57
	PacketPlayClAdvancements               = 0x58
	PacketPlayClEntityProperties           = 0x59
	PacketPlayClEntityEffect               = 0x5A
	PacketPlayClDeclareRecipes             = 0x5B
	PacketPlayClTags                       = 0x5C
	PacketPlaySvTeleportConfirm            = 0x00
	PacketPlaySvQueryBlockNBT              = 0x01
	PacketPlaySvSetDifficulty              = 0x02
	PacketPlaySvChatMessage                = 0x03
	PacketPlaySvClientStatus               = 0x04
	PacketPlaySvClientSettings             = 0x05
	PacketPlaySvTabComplete                = 0x06
	PacketPlaySvWindowConfirmation         = 0x07
	PacketPlaySvClickWindowButton          = 0x08
	PacketPlaySvClickWindow                = 0x09
	PacketPlaySvCloseWindow                = 0x0A
	PacketPlaySvPluginMessage              = 0x0B
	PacketPlaySvEditBook                   = 0x0C
	PacketPlaySvEntityNBTRequest           = 0x0D
	PacketPlaySvInteractEntity             = 0x0E
	PacketPlaySvKeepAlive                  = 0x0F
	PacketPlaySvLockDifficulty             = 0x10
	PacketPlaySvPlayerPosition             = 0x11
	PacketPlaySvPlayerPositionAndRotation  = 0x12
	PacketPlaySvPlayerRotation             = 0x13
	PacketPlaySvPlayerMovement             = 0x14
	PacketPlaySvVehicleMove                = 0x15
	PacketPlaySvSteerBoat                  = 0x16
	PacketPlaySvPickItem                   = 0x17
	PacketPlaySvCraftRecipeRequest         = 0x18
	PacketPlaySvPlayerAbilities            = 0x19
	PacketPlaySvPlayerDigging              = 0x1A
	PacketPlaySvEntityAction               = 0x1B
	PacketPlaySvSteerVehicle               = 0x1C
	PacketPlaySvRecipeBookData             = 0x1D
	PacketPlaySvNameItem                   = 0x1E
	PacketPlaySvResourcePackStatus         = 0x1F
	PacketPlaySvAdvancementTab             = 0x20
	PacketPlaySvSelectTrade                = 0x21
	PacketPlaySvSetBeaconEffect            = 0x22
	PacketPlaySvHeldItemChange             = 0x23
	PacketPlaySvUpdateCommandBlock         = 0x24
	PacketPlaySvUpdateCommandBlockMinecart = 0x25
	PacketPlaySvCreativeInventoryAction    = 0x26
	PacketPlaySvUpdateJigsawBlock          = 0x27
	PacketPlaySvUpdateStructureBlock       = 0x28
	PacketPlaySvUpdateSign                 = 0x29
	PacketPlaySvAnimation                  = 0x2A
	PacketPlaySvSpectate                   = 0x2B
	PacketPlaySvPlayerBlockPlacement       = 0x2C
	PacketPlaySvUseItem                    = 0x2D
)

Constant packet IDs to avoid magic numbers Packet + [State] + [Binding (Cl = Clientbound; Sv = Serverbound)] + [Name]

Variables

This section is empty.

Functions

func Compress

func Compress(data []byte) []byte

Compress compresses a byte array using zlib

func ReadNBytes

func ReadNBytes(reader FieldReader, n int) (readBytes []byte, err error)

ReadNBytes reads n bytes from the given reader

Types

type Angle

type Angle int8

type Boolean

type Boolean bool

func (*Boolean) Decode

func (value *Boolean) Decode(reader FieldReader) error

Decode a wrapped boolean

func (Boolean) Encode

func (value Boolean) Encode() []byte

Encode a wrapped boolean

type Byte

type Byte int8

func (*Byte) Decode

func (value *Byte) Decode(reader FieldReader) error

Decode a wrapped byte

func (Byte) Encode

func (value Byte) Encode() []byte

Encode a wrapped byte

type ByteArray

type ByteArray []byte

TODO: Add NBT data type

func (*ByteArray) Decode

func (value *ByteArray) Decode(reader FieldReader) error

Decode a wrapped byte array

func (ByteArray) Encode

func (value ByteArray) Encode() []byte

Encode a wrapped byte array

type CFB8

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

CFB8 represents a CFB8 implementation

func NewCFB8Decrypt

func NewCFB8Decrypt(block cipher.Block, initialVector []byte) *CFB8

NewCFB8Decrypt returns a CFB8 decryption implementation

func NewCFB8Encrypt

func NewCFB8Encrypt(block cipher.Block, initialVector []byte) *CFB8

NewCFB8Encrypt returns a CFB8 encryption implementation

func (*CFB8) XORKeyStream

func (cfb *CFB8) XORKeyStream(dst, src []byte)

XORKeyStream performs an XOR key stream

type Chat

type Chat = String

type Connection

type Connection struct {
	Socket net.Conn
	io.ByteReader
	io.Writer
	// contains filtered or unexported fields
}

Connection represents a Minecraft connection

func (Connection) Close

func (connection Connection) Close() error

Close closes a Minecraft connection

func (*Connection) ReadPacket

func (connection *Connection) ReadPacket() (Packet, error)

ReadPacket reads a packet from a Minecraft connection

func (*Connection) SetCipher

func (connection *Connection) SetCipher(encodeStream, decodeStream cipher.Stream)

SetCipher defines the cipher streams for a Minecraft connection

func (*Connection) SetThreshold

func (connection *Connection) SetThreshold(threshold int)

SetThreshold sets the threshold for a Minecraft connection

func (*Connection) WritePacket

func (connection *Connection) WritePacket(packet Packet) error

WritePacket writes a packet to to a Minecraft connection

type Decodable

type Decodable interface {
	Decode(reader FieldReader) error
}

Decodable represents an decodable field

type Double

type Double float64

func (*Double) Decode

func (value *Double) Decode(reader FieldReader) error

Decode a wrapped double

func (Double) Encode

func (value Double) Encode() []byte

Encode a wrapped double

type Encodable

type Encodable interface {
	Encode() []byte
}

Encodable represents an encodable field

type Field

type Field interface {
	Encodable
	Decodable
}

Field represents a packet field

type FieldReader

type FieldReader interface {
	io.ByteReader
	io.Reader
}

FieldReader represents an object that can read packet contents

type Float

type Float float32

func (*Float) Decode

func (value *Float) Decode(reader FieldReader) error

Decode a wrapped float

func (Float) Encode

func (value Float) Encode() []byte

Encode a wrapped float

type Identifier

type Identifier = String

type Int

type Int int32

func (*Int) Decode

func (value *Int) Decode(reader FieldReader) error

Decode a wrapped integer

func (Int) Encode

func (value Int) Encode() []byte

Encode a wrapped integer

type Listener

type Listener struct {
	net.Listener
}

Listener represents a connection listener

func Listen

func Listen(address string) (*Listener, error)

Listen listens for new Minecraft connections

func (Listener) Accept

func (listener Listener) Accept() (Connection, error)

Accept accepts a new Minecraft connection

type Long

type Long int64

func (*Long) Decode

func (value *Long) Decode(reader FieldReader) error

Decode a wrapped long

func (Long) Encode

func (value Long) Encode() []byte

Encode a wrapped long

type Packet

type Packet struct {
	ID   byte
	Data []byte
}

Packet represents a protocol packet

func Decompress

func Decompress(data []byte) (*Packet, error)

Decompress decompresses a byte array into a packet

func GeneratePacket

func GeneratePacket(id byte, data ...Encodable) (packet Packet)

GeneratePacket generates a new packet with the given fields

func ReadPacket

func ReadPacket(reader io.ByteReader, compressed bool) (*Packet, error)

ReadPacket reads a packet from a byte reader

func (*Packet) Pack

func (packet *Packet) Pack(threshold int) (packed []byte)

Pack packs a packet

func (Packet) Unwrap

func (packet Packet) Unwrap(fields ...Decodable) error

Unwrap decodes a packet and splits it up into multiple fields

type Position

type Position struct {
	X, Y, Z int
}

func (*Position) Decode

func (value *Position) Decode(reader FieldReader) error

Decode a Position

func (Position) Encode

func (value Position) Encode() []byte

Encode a Position

type Short

type Short int16

func (*Short) Decode

func (value *Short) Decode(reader FieldReader) error

Decode a wrapped short

func (Short) Encode

func (value Short) Encode() []byte

Encode a wrapped short

type String

type String string

func (*String) Decode

func (value *String) Decode(reader FieldReader) error

Decode a wrapped string

func (String) Encode

func (value String) Encode() (encoded []byte)

Encode a wrapped string

type UUID

type UUID uuid.UUID

func (*UUID) Decode

func (value *UUID) Decode(reader FieldReader) error

Decode a UUID

func (UUID) Encode

func (value UUID) Encode() []byte

Encode a UUID

type UnsignedByte

type UnsignedByte uint8

func (*UnsignedByte) Decode

func (value *UnsignedByte) Decode(reader FieldReader) error

Decode a wrapped unsigned byte

func (UnsignedByte) Encode

func (value UnsignedByte) Encode() []byte

Encode a wrapped unsigned byte

type UnsignedShort

type UnsignedShort uint16

func (*UnsignedShort) Decode

func (value *UnsignedShort) Decode(reader FieldReader) error

Decode a wrapped unsigned short

func (UnsignedShort) Encode

func (value UnsignedShort) Encode() []byte

Encode a wrapped unsigned short

type VarInt

type VarInt int32

func (*VarInt) Decode

func (value *VarInt) Decode(reader FieldReader) error

Decode a VarInt

func (VarInt) Encode

func (value VarInt) Encode() (encoded []byte)

Encode a VarInt

type VarLong

type VarLong int64

func (*VarLong) Decode

func (value *VarLong) Decode(reader FieldReader) error

Decode a VarLong

func (VarLong) Encode

func (value VarLong) Encode() (encoded []byte)

Encode a VarLong

Jump to

Keyboard shortcuts

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