packet

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2019 License: MIT Imports: 14 Imported by: 157

Documentation

Index

Constants

View Source
const (
	IDLogin = iota + 0x01
	IDPlayStatus
	IDServerToClientHandshake
	IDClientToServerHandshake
	IDDisconnect
	IDResourcePacksInfo
	IDResourcePackStack
	IDResourcePackClientResponse
	IDText
	IDSetTime
	IDStartGame
)
View Source
const (
	IDRequestChunkRadius = iota + 0x45
	IDChunkRadiusUpdated
)

...

View Source
const (
	IDResourcePackDataInfo = iota + 0x52
	IDResourcePackChunkData
	IDResourcePackChunkRequest
	IDTransfer
)

...

View Source
const (
	IDModalFormRequest = iota + 0x64
	IDModalFormResponse
	IDServerSettingsRequest
	IDServerSettingsResponse
)

...

View Source
const (
	PlayStatusLoginSuccess int32 = iota
	PlayStatusLoginFailedClient
	PlayStatusLoginFailedServer
	PlayStatusPlayerSpawn
	PlayStatusLoginFailedInvalidTenant
	PlayStatusLoginFailedVanillaEdu
	PlayStatusLoginFailedEduVanilla
	PlayStatusLoginFailedServerFull
)
View Source
const (
	PackResponseRefused = iota + 1
	PackResponseSendPacks
	PackResponseAllPacksDownloaded
	PackResponseCompleted
)
View Source
const (
	TextTypeRaw = iota
	TextTypeChat
	TextTypeTranslation
	TextTypePopup
	TextTypeJukeboxPopup
	TextTypeTip
	TextTypeSystem
	TextTypeWhisper
	TextTypeAnnouncement
	TextTypeJSON
)
View Source
const (
	IDFullChunkData = iota + 0x3a
)

...

View Source
const (
	IDSetLocalPlayerAsInitialised = iota + 0x71
)

...

Variables

This section is empty.

Functions

func ChainErr added in v0.1.0

func ChainErr(err ...error) error

ChainErr chains together a variadic amount of errors into a single error and returns it. If all errors passed are nil, the error returned will also be nil.

Types

type BlockEntry added in v0.1.0

type BlockEntry struct {
	// Name is the name of the block. It looks like 'minecraft:stone'.
	Name string
	// Data is the metadata value of the block. A lot of blocks only have 0 as data value, but some blocks
	// carry specific variants or properties encoded in the metadata.
	Data int16
}

BlockEntry is a block sent in the StartGame packet block runtime ID table. It holds a name and a metadata value of a block.

type ChunkRadiusUpdated

type ChunkRadiusUpdated struct {
	// ChunkRadius is the final chunk radius that the client will adapt when it receives the packet. It does
	// not have to be the same as the requested chunk radius.
	ChunkRadius int32
}

ChunkRadiusUpdated is sent by the server in response to a RequestChunkRadius packet. It defines the chunk radius that the server allows the client to have. This may be lower than the chunk radius requested by the client in the RequestChunkRadius packet.

func (*ChunkRadiusUpdated) ID

func (*ChunkRadiusUpdated) ID() uint32

ID ...

func (*ChunkRadiusUpdated) Marshal

func (pk *ChunkRadiusUpdated) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ChunkRadiusUpdated) Unmarshal

func (pk *ChunkRadiusUpdated) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ClientToServerHandshake

type ClientToServerHandshake struct {
}

ClientToServerHandshake is sent by the client in response to a ServerToClientHandshake packet sent by the server. It is the first encrypted packet in the login handshake and serves as a confirmation that encryption is correctly initialised client side.

func (*ClientToServerHandshake) ID

ID ...

func (*ClientToServerHandshake) Marshal

func (*ClientToServerHandshake) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ClientToServerHandshake) Unmarshal

func (*ClientToServerHandshake) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type Decoder

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

Decoder handles the decoding of Minecraft packets sent through an io.Reader. These packets in turn contain multiple zlib compressed packets.

func NewDecoder

func NewDecoder(reader io.Reader) *Decoder

NewDecoder returns a new decoder decoding data from the reader passed. One read call from the reader is assumed to consume an entire packet.

func (*Decoder) Decode

func (decoder *Decoder) Decode() (packets [][]byte, err error)

Decode decodes one 'packet' from the reader passed in NewDecoder(), producing a slice of packets that it held and an error if not successful.

func (*Decoder) EnableEncryption

func (decoder *Decoder) EnableEncryption(keyBytes [32]byte)

EnableEncryption enables encryption for the Decoder using the secret key bytes passed. Each packet received will be decrypted.

type Disconnect

type Disconnect struct {
	// HideDisconnectionScreen specifies if the disconnection screen should be hidden when the client is
	// disconnected, meaning it will be sent directly to the main menu.
	HideDisconnectionScreen bool
	// Message is an optional message to show when disconnected. This message is only written if the
	// HIdeDisconnectionScreen field is set to true.
	Message string
}

Disconnect may be sent by the server to disconnect the client using an optional message to send as the disconnect screen.

func (*Disconnect) ID

func (*Disconnect) ID() uint32

ID ...

func (*Disconnect) Marshal

func (pk *Disconnect) Marshal(buf *bytes.Buffer)

Marshal ...

func (*Disconnect) Unmarshal

func (pk *Disconnect) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type Encoder

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

Encoder handles the encoding of Minecraft packets that are sent to an io.Writer. The packets are compressed and optionally encoded before they are sent to the io.Writer.

func NewEncoder

func NewEncoder(writer io.Writer) *Encoder

NewEncoder returns a new Encoder for the io.Writer passed. Each final packet produced by the Encoder is sent with a single call to io.Writer.Write().

func (*Encoder) EnableEncryption

func (encoder *Encoder) EnableEncryption(keyBytes [32]byte)

EnableEncryption enables encryption for the Encoder using the secret key bytes passed. Each packet sent after encryption is enabled will be encrypted.

func (*Encoder) Encode

func (encoder *Encoder) Encode(packets [][]byte) error

Encode encodes the packets passed. It writes all of them as a single packet which is zlib compressed and optionally encoded.

type FullChunkData added in v0.2.0

type FullChunkData struct {
	// ChunkX is the X coordinate of the chunk sent. (To translate a block's X to a chunk's X: x >> 4)
	ChunkX int32
	// ChunkZ is the Z coordinate of the chunk sent. (To translate a block's Z to a chunk's Z: z >> 4)
	ChunkZ int32
	// Data is a serialised string of chunk data. The chunk data is composed of multiple sub-chunks, each of
	// which carry a version which indicates the way they are serialised.
	Data string
}

FullChunkData is sent by the server to provide the client with a chunk of a world data (16xYx16 blocks). Typically a certain amount of chunks is sent to the client before sending it the spawn PlayStatus packet, so that the client spawns in a loaded world.

func (*FullChunkData) ID added in v0.2.0

func (*FullChunkData) ID() uint32

ID ...

func (*FullChunkData) Marshal added in v0.2.0

func (pk *FullChunkData) Marshal(buf *bytes.Buffer)

Marshal ...

func (*FullChunkData) Unmarshal added in v0.2.0

func (pk *FullChunkData) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type Header struct {
	PacketID        uint32
	SenderSubClient byte
	TargetSubClient byte
}

Header is the header of a packet. It exists out of a single varuint32 which is composed of a packet ID and a sender and target sub client ID. These IDs are used for split screen functionality.

func (*Header) Read

func (header *Header) Read(buf *bytes.Buffer) error

Read reads a varuint32 from buf and sets the corresponding values to the Header.

func (*Header) Write

func (header *Header) Write(buf *bytes.Buffer) error

Write writes the header as a single varuint32 to buf.

type Login

type Login struct {
	// ClientProtocol is the protocol version of the player. The player is disconnected if the protocol is
	// incompatible with the protocol of the server.
	ClientProtocol int32
	// ConnectionRequest is a string containing information about the player and JWTs that may be used to
	// verify if the player is connected to XBOX Live. The connection request also contains the necessary
	// client public key to initiate encryption.
	ConnectionRequest string
}

Login is sent when the client initially tries to join the server. It is the first packet sent and contains information specific to the player.

func (*Login) ID

func (*Login) ID() uint32

ID ...

func (*Login) Marshal

func (pk *Login) Marshal(buf *bytes.Buffer)

Marshal ...

func (*Login) Unmarshal

func (pk *Login) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ModalFormRequest

type ModalFormRequest struct {
	// FormID is an ID used to identify the form. The ID is saved by the client and sent back when the player
	// submits the form, so that the server can identify which form was submitted.
	FormID uint32
	// FormData is a JSON encoded object of form data. The content of the object differs, depending on the
	// type of the form sent, which is also set in the JSON.
	FormData string
}

ModalFormRequest is sent by the server to make the client open a form. This form may be either a modal form which has two options, a menu form for a selection of options and a custom form for properties.

func (*ModalFormRequest) ID

func (*ModalFormRequest) ID() uint32

ID ...

func (*ModalFormRequest) Marshal

func (pk *ModalFormRequest) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ModalFormRequest) Unmarshal

func (pk *ModalFormRequest) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ModalFormResponse

type ModalFormResponse struct {
	// FormID is the form ID of the form the client has responded to. It is the same as the ID sent in the
	// ModalFormRequest, and may be used to identify which form was submitted.
	FormID uint32
	// ResponseData is a JSON encoded value representing the response of the player. If the form was
	// cancelled, a JSON encoded 'null' is in the response. For a modal form, the response is either true or
	// false, for a menu form, the response is an integer specifying the index of the button clicked, and for
	// a custom form, the response is an array containing a value for each element.
	ResponseData string
}

ModalFormResponse is sent by the client in response to a ModalFormRequest, after the player has submitted the form sent. It contains the options/properties selected by the player, or a JSON encoded 'null' if the form was closed by clicking the X at the top right corner of the form.

func (*ModalFormResponse) ID

func (*ModalFormResponse) ID() uint32

ID ...

func (*ModalFormResponse) Marshal

func (pk *ModalFormResponse) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ModalFormResponse) Unmarshal

func (pk *ModalFormResponse) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type Packet

type Packet interface {
	ID() uint32
	// Marshal encodes the packet to its binary representation into buf.
	Marshal(buf *bytes.Buffer)
	// Unmarshal decodes a serialised packet in buf into the Packet instance. The serialised packet passed
	// into Unmarshal will not have a header in it.
	Unmarshal(buf *bytes.Buffer) error
}

Packet represents a packet that may be sent over a Minecraft network connection. The packet needs to hold a method to encode itself to binary and decode itself from binary.

type PlayStatus

type PlayStatus struct {
	// Status is the status of the packet. It is one of the constants found above.
	Status int32
}

PlayStatus is sent by the server to update a player on the play status. This includes failed statuses due to a mismatched version, but also success statuses.

func (*PlayStatus) ID

func (*PlayStatus) ID() uint32

ID ...

func (*PlayStatus) Marshal

func (pk *PlayStatus) Marshal(buf *bytes.Buffer)

Marshal ...

func (*PlayStatus) Unmarshal

func (pk *PlayStatus) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type Pool

type Pool map[uint32]Packet

Pool is a map holding packets indexed by a packet ID.

func NewPool

func NewPool() Pool

NewPool returns a new pool with all supported packets sent. Packets may be retrieved from it simply by indexing it with the packet ID.

type RequestChunkRadius

type RequestChunkRadius struct {
	// ChunkRadius is the requested chunk radius. This value is always the value set in the settings of the
	// player.
	ChunkRadius int32
}

RequestChunkRadius is sent by the client to the server to update the server on the chunk view radius that it has set in the settings. The server may respond with a ChunkRadiusUpdated packet with either the chunk radius requested, or a different chunk radius if the server chooses so.

func (*RequestChunkRadius) ID

func (*RequestChunkRadius) ID() uint32

ID ...

func (*RequestChunkRadius) Marshal

func (pk *RequestChunkRadius) Marshal(buf *bytes.Buffer)

Marshal ...

func (*RequestChunkRadius) Unmarshal

func (pk *RequestChunkRadius) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ResourcePack added in v0.1.0

type ResourcePack struct {
	// UUID is the UUID of the resource pack. Each resource pack downloaded must have a different UUID in
	// order for the client to be able to handle them properly.
	UUID string
	// Version is the version of the resource pack. The client will cache resource packs sent by the server as
	// long as they carry the same version. Sending a resource pack with a different version than previously
	// will force the client to re-download it.
	Version string
	// Size is the total size in bytes that the resource pack occupies. This is the size of the compressed
	// archive (zip) of the resource pack.
	Size int64
	// ContentKey is the key used to decrypt the resource pack if it is encrypted. This is generally the case
	// for marketplace resource packs.
	ContentKey string
	// SubPackName ...
	SubPackName string
	// ContentIdentity ...
	ContentIdentity string
	// HasScripts specifies if the resource packs has any scripts in it. A client will only download the
	// resource pack if it supports scripts, which, up to 1.11, only includes Windows 10.
	HasScripts bool
}

ResourcePack represents a resource pack sent over network. It holds information about the resource pack such as its name, description and version.

type ResourcePackChunkData

type ResourcePackChunkData struct {
	// UUID is the unique ID of the resource pack that the chunk of data is taken out of.
	UUID string
	// ChunkIndex is the current chunk index of the chunk. It is a number that starts at 0 and is incremented
	// for each resource pack data chunk sent to the client.
	ChunkIndex int32
	// DataOffset is the current progress in bytes or offset in the data that the resource pack data chunk is
	// taken from.
	DataOffset int64
	// Data is a byte slice containing a chunk of data from the resource pack. It must be of the same size or
	// less than the DataChunkSize set in the ResourcePackDataInfo packet.
	Data []byte
}

ResourcePackChunkData is sent to the client so that the client can download the resource pack. Each packet holds a chunk of the compressed resource pack, of which the size is defined in the ResourcePackDataInfo packet sent before.

func (*ResourcePackChunkData) ID

ID ...

func (*ResourcePackChunkData) Marshal

func (pk *ResourcePackChunkData) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ResourcePackChunkData) Unmarshal

func (pk *ResourcePackChunkData) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ResourcePackChunkRequest

type ResourcePackChunkRequest struct {
	// UUID is the unique ID of the resource pack that the chunk of data is requested from.
	UUID string
	// ChunkIndex is the requested chunk index of the chunk. It is a number that starts at 0 and is
	// incremented for each resource pack data chunk requested.
	ChunkIndex int32
}

ResourcePackChunkRequest is sent by the client to request a chunk of data from a particular resource pack, that it has obtained information about in a ResourcePackDataInfo packet.

func (*ResourcePackChunkRequest) ID

ID ...

func (*ResourcePackChunkRequest) Marshal

func (pk *ResourcePackChunkRequest) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ResourcePackChunkRequest) Unmarshal

func (pk *ResourcePackChunkRequest) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ResourcePackClientResponse

type ResourcePackClientResponse struct {
	// Response is the response type of the response. It is one of the constants found above.
	Response byte
	// PacksToDownload is a list of resource pack UUIDs combined with their version that need to be downloaded
	// (for example SomePack_1.0.0), if the Response field is PackResponseSendPacks.
	PacksToDownload []string
}

ResourcePackClientResponse is sent by the client in response to resource packets sent by the server. It is used to let the server know what action needs to be taken for the client to have all resource packs ready and set.

func (*ResourcePackClientResponse) ID

ID ...

func (*ResourcePackClientResponse) Marshal

func (pk *ResourcePackClientResponse) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ResourcePackClientResponse) Unmarshal

func (pk *ResourcePackClientResponse) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ResourcePackDataInfo

type ResourcePackDataInfo struct {
	// UUID is the unique ID of the resource pack that the info concerns.
	UUID string
	// DataChunkSize is the maximum size in bytes of the chunks in which the total size of the resource pack
	// to be sent will be divided. A size of 1MB (1024*1024) means that a resource pack of 15.5MB will be
	// split into 16 data chunks.
	DataChunkSize int32
	// ChunkCount is the total amount of data chunks that the sent resource pack will exist out of. It is the
	// total size of the resource pack divided by the DataChunkSize field.
	ChunkCount int32
	// Size is the total size in bytes that the resource pack occupies. This is the size of the compressed
	// archive (zip) of the resource pack.
	Size int64
	// Hash is a SHA256 hash of the content of the resource pack.
	Hash string
}

ResourcePackDataInfo is sent by the server to the client to inform the client about the data contained in one of the resource packs that are about to be sent.

func (*ResourcePackDataInfo) ID

ID ...

func (*ResourcePackDataInfo) Marshal

func (pk *ResourcePackDataInfo) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ResourcePackDataInfo) Unmarshal

func (pk *ResourcePackDataInfo) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ResourcePackStack

type ResourcePackStack struct {
	// TexturePackRequired specifies if the client must accept the texture packs the server has in order to
	// join the server. If set to true, the client gets the option to either download the resource packs and
	// join, or quit entirely. Behaviour packs never have to be downloaded.
	TexturePackRequired bool
	// BehaviourPack is a list of behaviour packs that the client needs to download before joining the server.
	// All of these behaviour packs will be applied together, and the order does not necessarily matter.
	BehaviourPacks []ResourcePack
	// TexturePacks is a list of texture packs that the client needs to download before joining the server.
	// The order of these texture packs specifies the order that they are applied in on the client side. The
	// first in the list will be applied first.
	TexturePacks []ResourcePack
	// Experimental specifies if the resource packs in the stack are experimental. This is internal and should
	// always be set to false.
	Experimental bool
}

ResourcePackStack is sent by the server to send the order in which resource packs and behaviour packs should be applied (and downloaded) by the client.

func (*ResourcePackStack) ID

func (*ResourcePackStack) ID() uint32

ID ...

func (*ResourcePackStack) Marshal

func (pk *ResourcePackStack) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ResourcePackStack) Unmarshal

func (pk *ResourcePackStack) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ResourcePacksInfo

type ResourcePacksInfo struct {
	// TexturePackRequired specifies if the client must accept the texture packs the server has in order to
	// join the server. If set to true, the client gets the option to either download the resource packs and
	// join, or quit entirely. Behaviour packs never have to be downloaded.
	TexturePackRequired bool
	// HasScripts specifies if any of the resource packs contain scripts in them. If set to true, only clients
	// that support scripts will be able to download them.
	HasScripts bool
	// BehaviourPack is a list of behaviour packs that the client needs to download before joining the server.
	// All of these behaviour packs will be applied together.
	BehaviourPacks []ResourcePack
	// TexturePacks is a list of texture packs that the client needs to download before joining the server.
	// The order of these texture packs is not relevant in this packet. It is however important in the
	// ResourcePackStack packet.
	TexturePacks []ResourcePack
}

ResourcePacksInfo is sent by the server to inform the client on what resource packs the server has. It sends a list of the resource packs it has and basic information on them like the version and description.

func (*ResourcePacksInfo) ID

func (*ResourcePacksInfo) ID() uint32

ID ...

func (*ResourcePacksInfo) Marshal

func (pk *ResourcePacksInfo) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ResourcePacksInfo) Unmarshal

func (pk *ResourcePacksInfo) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ServerSettingsRequest

type ServerSettingsRequest struct {
}

ServerSettingsRequest is sent by the client to request the settings specific to the server. These settings are shown in a separate tab client-side, and have the same structure as a custom form.

func (*ServerSettingsRequest) ID

ID ...

func (*ServerSettingsRequest) Marshal

func (*ServerSettingsRequest) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ServerSettingsRequest) Unmarshal

func (*ServerSettingsRequest) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ServerSettingsResponse

type ServerSettingsResponse struct {
	// FormID is an ID used to identify the form. The ID is saved by the client and sent back when the player
	// submits the form, so that the server can identify which form was submitted.
	FormID uint32
	// FormData is a JSON encoded object of form data. The content of the object differs, depending on the
	// type of the form sent, which is also set in the JSON.
	FormData string
}

ServerSettingsResponse is optionally sent by the server in response to a ServerSettingsRequest from the client. It is structured the same as a ModalFormRequest packet, and if filled out correctly, will show a specific tab for the server in the settings of the client. A ModalFormResponse packet is sent by the client in response to a ServerSettingsResponse, when the client fills out the settings and closes the settings again.

func (*ServerSettingsResponse) ID

ID ...

func (*ServerSettingsResponse) Marshal

func (pk *ServerSettingsResponse) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ServerSettingsResponse) Unmarshal

func (pk *ServerSettingsResponse) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type ServerToClientHandshake

type ServerToClientHandshake struct {
	// JWT is a raw JWT token containing data such as the public key from the server, the algorithm used and
	// the server's token. It is used for the client to produce a shared secret.
	JWT string
}

ServerToClientHandshake is sent by the server to the client to complete the key exchange in order to initialise encryption on client and server side. It is followed up by a ClientToServerHandshake packet from the client.

func (*ServerToClientHandshake) ID

ID ...

func (*ServerToClientHandshake) Marshal

func (pk *ServerToClientHandshake) Marshal(buf *bytes.Buffer)

Marshal ...

func (*ServerToClientHandshake) Unmarshal

func (pk *ServerToClientHandshake) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type SetLocalPlayerAsInitialised

type SetLocalPlayerAsInitialised struct {
	// EntityRuntimeID is the entity runtime ID the player was assigned earlier in the login sequence in the
	// StartGame packet.
	EntityRuntimeID uint64
}

SetLocalPlayerAsInitialised is sent by the client in response to a PlayStatus packet with the status set to 3. The packet marks the moment at which the client is fully initialised and can receive any packet without discarding it.

func (*SetLocalPlayerAsInitialised) ID

ID ...

func (*SetLocalPlayerAsInitialised) Marshal

func (pk *SetLocalPlayerAsInitialised) Marshal(buf *bytes.Buffer)

Marshal ...

func (*SetLocalPlayerAsInitialised) Unmarshal

func (pk *SetLocalPlayerAsInitialised) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type SetTime

type SetTime struct {
	// Time is the current time. The time is not limited to 24000 (time of day), but continues progressing
	// after that.
	Time int32
}

SetTime is sent by the server to update the current time client-side. The client actually advances time client-side by itself, so this packet does not need to be sent each tick. It is merely a means of synchronising time between server and client.

func (*SetTime) ID

func (*SetTime) ID() uint32

ID ...

func (*SetTime) Marshal

func (pk *SetTime) Marshal(buf *bytes.Buffer)

Marshal ...

func (*SetTime) Unmarshal

func (pk *SetTime) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type StartGame

type StartGame struct {
	// EntityUniqueID is the unique ID of the player. The unique ID is a value that remains consistent across
	// different sessions of the same world, but most servers simply fill the runtime ID of the entity out for
	// this field.
	EntityUniqueID int64
	// EntityRuntimeID is the runtime ID of the player. The runtime ID is unique for each world session, and
	// entities are generally identified in packets using this runtime ID.
	EntityRuntimeID uint64
	// PlayerGameMode is the game mode the player currently has. It is a value from 0-4, with 0 being
	// survival mode, 1 being creative mode, 2 being adventure mode, 3 being survival spectator and 4 being
	// creative spectator.
	PlayerGameMode int32
	// PlayerPosition is the spawn position of the player in the world. In servers this is often the same as
	// the world's spawn position found below.
	PlayerPosition mgl32.Vec3
	// Pitch is the vertical rotation of the player. Facing straight forward yields a pitch of 0. Pitch is
	// measured in degrees.
	Pitch float32
	// Yaw is the horizontal rotation of the player. Yaw is also measured in degrees.
	Yaw float32
	// WorldSeed is the seed used to generate the world. Unlike in PC edition, the seed is a 32bit integer
	// here.
	WorldSeed int32
	// Dimension is the ID of the dimension that the player spawns in. It is a value from 0-2, with 0 being
	// the overworld, 1 being the nether and 2 being the end.
	Dimension int32
	// Generator is the generator used for the world. It is a value from 0-4, with 0 being old limited worlds,
	// 1 being infinite worlds, 2 being flat worlds, 3 being nether worlds and 4 being end worlds. A value of
	// 0 will actually make the client stop rendering chunks you send beyond the world limit.
	Generator int32
	// WorldGameMode is the game mode that a player gets when it first spawns in the world. It has no effect
	// on the actual game mode the player spawns with. See PlayerGameMode for that.
	WorldGameMode int32
	// Difficulty is the difficulty of the world. It is a value from 0-3, with 0 being peaceful, 1 being easy,
	// 2 being normal and 3 being hard.
	Difficulty int32
	// WorldSpawn is the block on which the world spawn of the world. This coordinate has no effect on the
	// place that the client spawns, but it does have an effect on the direction that a compass points.
	WorldSpawn protocol.BlockPos
	// AchievementsDisabled defines if achievements are disabled in the world. The client crashes if this
	// value is set to true while the player's or the world's game mode is creative, and it's recommended to
	// simply always set this to false as a server.
	AchievementsDisabled bool
	// DayCycleLockTime is the time at which the day cycle was locked if the day cycle is disabled using the
	// respective game rule. The client will maintain this time as long as the day cycle is disabled.
	DayCycleLockTime int32
	// EducationMode specifies if the world is specifically for education edition clients. Setting this to
	// true for normal editions actually temporarily 'transforms' the client into Education Edition, with even
	// the ability to see that title on the home screen.
	EducationMode bool
	// EducationFeaturesEnabled specifies if the world has education edition features enabled, such as the
	// blocks or entities specific to education edition.
	EducationFeaturesEnabled bool
	// RainLevel is the level specifying the intensity of the rain falling. When set to 0, no rain falls at
	// all.
	RainLevel float32
	// LightningLevel is the level specifying the intensity of the thunder. This may actually be set
	// independently from the RainLevel, meaning dark clouds can be produced without rain.
	LightningLevel float32
	// ConfirmedPlatformLockedContent ...
	ConfirmedPlatformLockedContent bool
	// MultiPlayerGame specifies if the world is a multi-player game. This should always be set to true for
	// servers.
	MultiPlayerGame bool
	// LANBroadcastEnabled specifies if LAN broadcast was intended to be enabled for the world.
	LANBroadcastEnabled bool
	// XBLBroadcastMode is the mode used to broadcast the joined game across XBOX Live.
	XBLBroadcastMode int32
	// PlatformBroadcastMode is the mode used to broadcast the joined game across the platform.
	PlatformBroadcastMode int32
	// CommandsEnabled specifies if commands are enabled for the player. It is recommended to always set this
	// to true on the server, as setting it to false means the player cannot, under any circumstance, use a
	// command.
	CommandsEnabled bool
	// TexturePackRequired specifies if the texture pack the world might hold is required, meaning the client
	// was forced to download it before joining.
	TexturePackRequired bool
	// GameRules defines game rules currently active with their respective values. The value of these game
	// rules may be either 'bool', 'int32' or 'float32'. Some game rules are server side only, and don't
	// necessarily need to be sent to the client.
	GameRules map[string]interface{}
	// BonusChestEnabled specifies if the world had the bonus map setting enabled when generating it. It does
	// not have any effect client-side.
	BonusChestEnabled bool
	// StartWithMapEnabled specifies if the world has the start with map setting enabled, meaning each joining
	// player obtains a map. This should always be set to false, because the client obtains a map all on its
	// own accord if this is set to true.
	StartWithMapEnabled bool
	// PlayerPermissions is the permission level of the player. It is a value from 0-3, with 0 being visitor,
	// 1 being member, 2 being operator and 3 being custom.
	PlayerPermissions int32
	// ServerChunkTickRadius is the radius around the player in which chunks are ticked. Most servers set this
	// value to a fixed number, as it does not necessarily affect anything client-side.
	ServerChunkTickRadius int32
	// HasLockedBehaviourPack specifies if the behaviour pack of the world is locked, meaning it cannot be
	// disabled from the world. This is typically set for worlds on the marketplace that have a dedicated
	// behaviour pack.
	HasLockedBehaviourPack bool
	// HasLockedTexturePack specifies if the texture pack of the world is locked, meaning it cannot be
	// disabled from the world. This is typically set for worlds on the marketplace that have a dedicated
	// texture pack.
	HasLockedTexturePack bool
	// FromLockedWorldTemplate specifies if the world from the server was from a locked world template. For
	// servers this should always be set to false.
	FromLockedWorldTemplate bool
	// MSAGamerTagsOnly ..
	MSAGamerTagsOnly bool
	// FromWorldTemplate specifies if the world from the server was from a world template. For servers this
	// should always be set to false.
	FromWorldTemplate bool
	// WorldTemplateSettingsLocked specifies if the world was a template that locks all settings that change
	// properties above in the settings GUI. It is recommended to set this to true for servers that do not
	// allow things such as setting game rules through the GUI.
	WorldTemplateSettingsLocked bool
	// LevelID is a base64 encoded world ID that is used to identify the world.
	LevelID string
	// WorldName is the name of the world that the player is joining. Note that this field shows up above the
	// player list for the rest of the game session, and cannot be changed. Setting the server name to this
	// field is recommended.
	WorldName string
	// PremiumWorldTemplateID is a UUID specific to the premium world template that might have been used to
	// generate the world. Servers should always fill out an empty string for this.
	PremiumWorldTemplateID string
	// Trial specifies if the world was a trial world, meaning features are limited and there is a time limit
	// on the world.
	Trial bool
	// Time is the total time that has elapsed since the start of the world.
	Time int64
	// EnchantmentSeed is the seed used to seed the random used to produce enchantments in the enchantment
	// table. Note that the exact correct random implementation must be used to produce the correct results
	// both client- and server-side.
	EnchantmentSeed int32
	// Blocks is a list of all blocks and variants existing in the game. Failing to send any of the blocks
	// that are in the game, including any specific variants of that block, will crash mobile clients. It
	// seems Windows 10 games do not crash.
	Blocks []BlockEntry
	// MultiPlayerCorrelationID is a unique ID specifying the multi-player session of the player. A random
	// UUID should be filled out for this field.
	MultiPlayerCorrelationID string
}

StartGame is sent by the server to send information about the world the player will be spawned in. It contains information about the position the player spawns in, and information about the world in general such as its game rules.

func (*StartGame) ID

func (*StartGame) ID() uint32

ID ...

func (*StartGame) Marshal

func (pk *StartGame) Marshal(buf *bytes.Buffer)

Marshal ...

func (*StartGame) Unmarshal

func (pk *StartGame) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type Text

type Text struct {
	// TextType is the type of the text sent. When a client sends this to the server, it should always be
	// TextTypeChat. If the server sends it, it may be one of the other text types above.
	TextType byte
	// NeedsTranslation specifies if any of the messages need to be translated. It seems that where % is found
	// in translatable text types, these are translated regardless of this bool. Translatable text types
	// include TextTypeTip, TextTypePopup and TextTypeJukeboxPopup.
	NeedsTranslation bool
	// SourceName is the name of the source of the messages. This source is displayed in text types such as
	// the TextTypeChat and TextTypeWhisper, where typically the username is shown.
	SourceName string
	// Message is the message of the packet. This field is set for each TextType and is the main component of
	// the packet.
	Message string
	// Parameters is a list of parameters that should be filled into the message. These parameters are only
	// written if the type of the packet is TextTypeTip, TextTypePopup or TextTypeJukeboxPopup.
	Parameters []string
	// XUID is the XBOX Live user ID of the player that sent the message. It is only set for packets of
	// TextTypeChat. When sent to a player, the player will only be shown the chat message if a player with
	// this XUID is present in the player list and not muted, or if the XUID is empty.
	XUID string
	// PlatformChatID is an identifier only set for particular platforms when chatting (presumably only for
	// Nintendo Switch). It is otherwise an empty string, and is used to decide which players are able to
	// chat with each other.
	PlatformChatID string
}

Text is sent by the client to the server to send chat messages, and by the server to the client to forward or send messages, which may be chat, popups, tips etc.

func (*Text) ID

func (*Text) ID() uint32

ID ...

func (*Text) Marshal

func (pk *Text) Marshal(buf *bytes.Buffer)

Marshal ...

func (*Text) Unmarshal

func (pk *Text) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type Transfer

type Transfer struct {
	// Address is the address of the new server, which might be either a hostname or an actual IP address.
	Address string
	// Port is the UDP port of the new server.
	Port uint16
}

Transfer is sent by the server to transfer a player from the current server to another. Doing so will fully disconnect the client, bring it back to the main menu and make it connect to the next server.

func (*Transfer) ID

func (*Transfer) ID() uint32

ID ...

func (*Transfer) Marshal

func (pk *Transfer) Marshal(buf *bytes.Buffer)

Marshal ...

func (*Transfer) Unmarshal

func (pk *Transfer) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

type Unknown

type Unknown struct {
	// PacketID is the packet ID of the packet.
	PacketID uint32
	// Payload is the raw payload of the packet.
	Payload []byte
}

Unknown is an implementation of the Packet interface for unknown/unimplemented packets. It holds the packet ID and the raw payload. It serves as a way to read raw unknown packets and forward them to another connection, without necessarily implementing them.

func (*Unknown) ID

func (pk *Unknown) ID() uint32

ID ...

func (*Unknown) Marshal

func (pk *Unknown) Marshal(buf *bytes.Buffer)

Marshal ...

func (*Unknown) Unmarshal

func (pk *Unknown) Unmarshal(buf *bytes.Buffer) error

Unmarshal ...

Jump to

Keyboard shortcuts

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