packets

package
v0.0.0-...-52436b7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPacket

type IPacket interface {
	SetBuffer([]byte)
	GetBuffer() []byte
	EncodeHeader()
	Encode()
	DecodeHeader()
	Decode()
	ResetStream()
	GetOffset() int
	SetOffset(int)
	Discard()
	IsDiscarded() bool
	EncodeId()
	DecodeId()
	GetId() int
}

IPacket gets implemented by every packet. Every packet can be encoded and decoded.

type MinecraftStream

type MinecraftStream struct {
	// MinecraftStream embeds binutils.Stream.
	// Usual binary encoding/decoding functions can
	// be called on a MinecraftStream.
	*binutils.Stream
}

MinecraftStream extends the binutils stream, and implements methods for writing types specific to the Minecraft bedrock.

func NewMinecraftStream

func NewMinecraftStream() *MinecraftStream

NewMinecraftStream reads a new MinecraftStream. This stream is pre-initialized and ready for usage.

func (*MinecraftStream) GetAttributeMap

func (stream *MinecraftStream) GetAttributeMap() data.AttributeMap

GetAttributeMap reads an attribute map of an entity. There may be attributes in this attribute map that are not set in the default attribute map, or missing attributes.

func (*MinecraftStream) GetBlockPosition

func (stream *MinecraftStream) GetBlockPosition() blocks.Position

GetBlockPosition reads a position of a block. Block positions are always rounded numbers, and the Y value is always positive.

func (*MinecraftStream) GetEntityData

func (stream *MinecraftStream) GetEntityData() map[uint32][]interface{}

GetEntityData reads an entity data property map from an entity.

func (*MinecraftStream) GetEntityRotation

func (stream *MinecraftStream) GetEntityRotation() data.Rotation

GetEntityRotation reads the rotation of an entity. The rotation of an entity has no different head yaw, which will therefore always be the same as the yaw when returned.

func (*MinecraftStream) GetEntityRotationBytes

func (stream *MinecraftStream) GetEntityRotationBytes() data.Rotation

GetEntityRotation reads the rotation of an entity in bytes. The rotation of an entity has no different head yaw, which will therefore always be the same as the yaw when returned.

func (*MinecraftStream) GetEntityRuntimeId

func (stream *MinecraftStream) GetEntityRuntimeId() uint64

GetEntityRuntimeId reads the runtime ID of an entity. Entity runtime IDs are an uint64, and can be looked up in the level they belong to.

func (*MinecraftStream) GetEntityUniqueId

func (stream *MinecraftStream) GetEntityUniqueId() int64

GetEntityUniqueId reads the unique ID of an entity. Unique IDs will currently always be identical to runtime IDs, and will therefore have the same result.

func (*MinecraftStream) GetItem

func (stream *MinecraftStream) GetItem() *items.Stack

GetItem reads a new item stack. The item stack returned may have NBT properties. If the item ID was unknown, an air item gets returned.

func (*MinecraftStream) GetPlayerRotation

func (stream *MinecraftStream) GetPlayerRotation() data.Rotation

GetPlayerRotation reads the rotation of a player. Players are supposed to have a different head yaw than normal yaw, but since recent updates the head yaw and yaw are always the same.

func (*MinecraftStream) GetUUID

func (stream *MinecraftStream) GetUUID() uuid.UUID

GetUUID reads a UUID. TODO: Re-order for little endian byte order. Order gets messed up.

func (*MinecraftStream) GetVector

func (stream *MinecraftStream) GetVector() r3.Vector

GetVector reads a float64 r3.Vector. Values read are actually float32, but converted to float64.

func (*MinecraftStream) PutAttributeMap

func (stream *MinecraftStream) PutAttributeMap(m data.AttributeMap)

PutAttributeMap writes the attribute map of an entity. The amount of attributes of the map is written, after which the attribute properties follow.

func (*MinecraftStream) PutBlockPosition

func (stream *MinecraftStream) PutBlockPosition(position blocks.Position)

PutBlockPosition writes a position of a block. Block positions are always rounded numbers, and the Y value is always positive.

func (*MinecraftStream) PutEntityData

func (stream *MinecraftStream) PutEntityData(entityData map[uint32][]interface{})

PutEntityData writes the data properties of an entity.

func (*MinecraftStream) PutEntityRotation

func (stream *MinecraftStream) PutEntityRotation(rotation data.Rotation)

PutEntityRotation writes the rotation of an entity. The rotation of an entity will only contain yaw and pitch.

func (*MinecraftStream) PutEntityRotationBytes

func (stream *MinecraftStream) PutEntityRotationBytes(rotation data.Rotation)

PutEntityRotation writes the rotation of an entity in bytes. The rotation of an entity will only contain yaw and pitch.

func (*MinecraftStream) PutEntityRuntimeId

func (stream *MinecraftStream) PutEntityRuntimeId(id uint64)

PutEntityRuntimeId writes the runtime ID of an entity. Entity runtime IDs are an uint64.

func (*MinecraftStream) PutEntityUniqueId

func (stream *MinecraftStream) PutEntityUniqueId(id int64)

PutEntityUniqueId writes the unique ID of an entity. Entity unique IDs are an int64, and remain the same through sessions.

func (*MinecraftStream) PutGameRules

func (stream *MinecraftStream) PutGameRules(gameRules map[string]types.GameRuleEntry)

PutGameRules writes a map of game rules. Game rules get prefixed by the type of the game rule, 1 being bool, 2 being uint32, 3 being float32.

func (*MinecraftStream) PutItem

func (stream *MinecraftStream) PutItem(item *items.Stack)

PutItem writes an item stack. Item stacks also get their NBT written to network, through the call of Stack.EmitNBT().

func (*MinecraftStream) PutPackInfo

func (stream *MinecraftStream) PutPackInfo(packs []types.ResourcePackInfoEntry)

PutPackInfo writes the info of an array of resource pack entries. The UUID, version and pack size gets written.

func (*MinecraftStream) PutPackStack

func (stream *MinecraftStream) PutPackStack(packs []types.ResourcePackStackEntry)

PutPackStack writes an array of resource pack entries. The order of this array specifies the order the client should apply those, with index 0 meaning highest priority.

func (*MinecraftStream) PutPlayerRotation

func (stream *MinecraftStream) PutPlayerRotation(rot data.Rotation)

PutPlayerRotation writes the rotation of a player. Players have a head yaw too, which gets written.

func (*MinecraftStream) PutRotationByte

func (stream *MinecraftStream) PutRotationByte(rot byte)

func (*MinecraftStream) PutUUID

func (stream *MinecraftStream) PutUUID(uuid uuid.UUID)

PutUUID writes a UUID. UUIDs are first re-ordered for little endian byte order, after which they get written.

func (*MinecraftStream) PutVector

func (stream *MinecraftStream) PutVector(vector r3.Vector)

PutVector writes a float64 r3.Vector. Vector values are first converted to a float32, after which they are written little endian.

type Packet

type Packet struct {
	*MinecraftStream
	// PacketId is the ID of the packet.
	// Packet IDs may differ for different protocols.
	PacketId int
	// SenderIdentifier is used for split screen.
	// It specifies the sender sub ID.
	SenderIdentifier byte
	// ReceiverIdentifier is used for split screen.
	// It specifies the receiver sub ID.
	ReceiverIdentifier byte
	// contains filtered or unexported fields
}

Packet is a Minecraft bedrock packet. Packets have a given ID and contain two prefix bytes, which are used for split screen. Packets can be discarded during handling of the packets to stop other handlers from handling those packets.

func NewPacket

func NewPacket(id int) *Packet

NewPacket returns a new packet with packet ID. The packet's stream gets pre-initialized.

func (*Packet) Decode

func (pk *Packet) Decode()

func (*Packet) DecodeHeader

func (pk *Packet) DecodeHeader()

DecodeHeader decodes a header of a packet, with bedrock >= 200. First the packet ID gets decoded, after which the sender and receiver ID bytes.

func (*Packet) DecodeId

func (pk *Packet) DecodeId()

DecodeId decodes the packet ID of the packet. The function panics if the packet ID and read ID do not match.

func (*Packet) Discard

func (pk *Packet) Discard()

Discard discards the packet. Once discarded, handlers will no longer handle this packet.

func (*Packet) Encode

func (pk *Packet) Encode()

func (*Packet) EncodeHeader

func (pk *Packet) EncodeHeader()

EncodeHeader encodes the header of a packet, with bedrock >= 200. First the packet ID gets encoded, after which the sender and receiver ID bytes get written.

func (*Packet) EncodeId

func (pk *Packet) EncodeId()

EncodeId encodes the ID of the packet.

func (*Packet) GetId

func (pk *Packet) GetId() int

GetId returns the packet ID of the packet.

func (*Packet) IsDiscarded

func (pk *Packet) IsDiscarded() bool

IsDiscard checks if a packet has been discarded. Discarded packets are no longer processed, and get disposed immediately.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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