packet

package
v0.0.0-...-8eced28 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunkData

type ChunkData struct {
	// Column is the chunk column that is being referenced.
	Column *protocol.Column
}

ChunkData is sent by the server to update a chunk client-side

func (*ChunkData) ID

func (*ChunkData) ID() int32

ID ...

func (*ChunkData) Marshal

func (pk *ChunkData) Marshal(w *protocol.Writer)

Marshal ...

func (*ChunkData) Unmarshal

func (pk *ChunkData) Unmarshal(r *protocol.Reader)

Unmarshal ...

type ClientKeepAlive

type ClientKeepAlive struct {
	// PingID is the time in Unix milliseconds that the client sent the packet.
	PingID int64
}

ClientKeepAlive is a packet sent by the client to the server usually every two seconds to keep the connection alive.

func (*ClientKeepAlive) ID

func (*ClientKeepAlive) ID() int32

ID ...

func (*ClientKeepAlive) Marshal

func (pk *ClientKeepAlive) Marshal(w *protocol.Writer)

Marshal ...

func (*ClientKeepAlive) Unmarshal

func (pk *ClientKeepAlive) Unmarshal(r *protocol.Reader)

Unmarshal ...

type ClientStatusPing

type ClientStatusPing struct {
	// Payload a system-dependent time value which is counted in milliseconds.
	Payload int64
}

ClientStatusPing is sent by the client to the server to request a ServerStatusPong.

func (*ClientStatusPing) ID

func (*ClientStatusPing) ID() int32

ID ...

func (*ClientStatusPing) Marshal

func (pk *ClientStatusPing) Marshal(w *protocol.Writer)

Marshal ...

func (*ClientStatusPing) Unmarshal

func (pk *ClientStatusPing) Unmarshal(r *protocol.Reader)

Unmarshal ...

type ClientStatusRequest

type ClientStatusRequest struct{}

ClientStatusRequest is sent by the client to the server to request the server status.

func (*ClientStatusRequest) ID

func (*ClientStatusRequest) ID() int32

ID ...

func (*ClientStatusRequest) Marshal

func (*ClientStatusRequest) Marshal(*protocol.Writer)

Marshal ...

func (*ClientStatusRequest) Unmarshal

func (*ClientStatusRequest) Unmarshal(*protocol.Reader)

Unmarshal ...

type Direction

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

Direction represents what direction a packet is going.

func DirectionClient

func DirectionClient() Direction

DirectionClient is used when the packet is meant for clients.

func DirectionServer

func DirectionServer() Direction

DirectionServer is used when the packet is meant for servers.

type Disconnect

type Disconnect struct {
	// Reason is the reason for closing the connection.
	Reason text.Text
}

Disconnect is sent to the client when it's connection is closed.

func (*Disconnect) ID

func (*Disconnect) ID() int32

ID ...

func (*Disconnect) Marshal

func (pk *Disconnect) Marshal(w *protocol.Writer)

Marshal ...

func (*Disconnect) Unmarshal

func (pk *Disconnect) Unmarshal(r *protocol.Reader)

Unmarshal ...

type EncryptionRequest

type EncryptionRequest struct {
	// ServerID is always empty post 1.7.
	ServerID string
	// PublicKey is the public key of the server.
	PublicKey rsa.PublicKey
	// VerifyToken is always 4 random bytes generated by the server.
	VerifyToken []byte
}

EncryptionRequest is sent by the server to request encryption on future packets. If the client accepts, it will send back an EncryptionResponse packet.

func (*EncryptionRequest) ID

func (*EncryptionRequest) ID() int32

ID ...

func (*EncryptionRequest) Marshal

func (pk *EncryptionRequest) Marshal(w *protocol.Writer)

Marshal ...

func (*EncryptionRequest) Unmarshal

func (pk *EncryptionRequest) Unmarshal(r *protocol.Reader)

Unmarshal ...

type EncryptionResponse

type EncryptionResponse struct {
	// SharedSecret is a shared secret which was encrypted with the server's public key.
	SharedSecret []byte
	// VerifyToken is the same verify token value encrypted with the server's public key.
	VerifyToken []byte
}

EncryptionResponse is sent back by the client to agree to the encryption. Every future packet will use the agreed upon encryption.

func (*EncryptionResponse) ID

func (*EncryptionResponse) ID() int32

ID ...

func (*EncryptionResponse) Marshal

func (pk *EncryptionResponse) Marshal(w *protocol.Writer)

Marshal ...

func (*EncryptionResponse) Unmarshal

func (pk *EncryptionResponse) Unmarshal(r *protocol.Reader)

Unmarshal ...

type Handshake

type Handshake struct {
	// Protocol is the protocol version of the player. The player is disconnected if the protocol is
	// incompatible with the protocol of the server.
	Protocol int32
	// Address is the address the player used to connect to the server.
	Address string
	// Port is the port of the server that the player used to connect with.
	Port int16
	// NextState is either one for status, or two for login.
	NextState int32
}

Handshake 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 (*Handshake) ID

func (*Handshake) ID() int32

ID ...

func (*Handshake) Marshal

func (pk *Handshake) Marshal(w *protocol.Writer)

Marshal ...

func (*Handshake) Unmarshal

func (pk *Handshake) Unmarshal(r *protocol.Reader)

Unmarshal ...

type JoinGame

type JoinGame struct {
	// EntityID is the ID of the player joining the game.
	EntityID int32
	// Hardcore is true if hardcore mode is enabled in the game.
	Hardcore bool
	// GameMode is the game mode of the game.
	GameMode byte
	// PreviousGameMode is the player's previous game mode.
	PreviousGameMode byte
	// Worlds contains all worlds on the server.
	Worlds []string
	// World is the name of the world the player is joining.
	World string
	// HashedSeed contains the first eight bytes of the world seed in an SHA-256 hash.
	HashedSeed int64
	// MaxPlayers was once used by the client to draw the player list, but now is ignored.
	MaxPlayers int32
	// ViewDistance is the maximum view distance the client can use. This ranges from two to thirty-two.
	ViewDistance int32
	// ReducedDebugInfo is true if the client should reduce the amount of debug information it shows on the F3 screen.
	ReducedDebugInfo bool
	// EnableRespawnScreen is true if the client should show the respawn screen when the player dies.
	EnableRespawnScreen bool
	// Debug is true if the world is in debug mode.
	Debug bool
	// Flat is true if the world is flat.
	Flat bool
}

JoinGame is sent by the server to the client to join a game.

func (*JoinGame) ID

func (*JoinGame) ID() int32

ID ...

func (*JoinGame) Marshal

func (pk *JoinGame) Marshal(w *protocol.Writer)

Marshal ...

func (*JoinGame) Unmarshal

func (pk *JoinGame) Unmarshal(r *protocol.Reader)

Unmarshal ...

type LoginDisconnect

type LoginDisconnect struct {
	// Reason is the reason for closing the connection.
	Reason text.Text
}

LoginDisconnect is sent to the client when it's connection is closed during login.

func (*LoginDisconnect) ID

func (*LoginDisconnect) ID() int32

ID ...

func (*LoginDisconnect) Marshal

func (pk *LoginDisconnect) Marshal(w *protocol.Writer)

Marshal ...

func (*LoginDisconnect) Unmarshal

func (pk *LoginDisconnect) Unmarshal(r *protocol.Reader)

Unmarshal ...

type LoginStart

type LoginStart struct {
	// Username is the username of the player.
	Username string
}

LoginStart is sent by the client to request starting a login.

func (*LoginStart) ID

func (*LoginStart) ID() int32

ID ...

func (*LoginStart) Marshal

func (pk *LoginStart) Marshal(w *protocol.Writer)

Marshal ...

func (*LoginStart) Unmarshal

func (pk *LoginStart) Unmarshal(r *protocol.Reader)

Unmarshal ...

type LoginSuccess

type LoginSuccess struct {
	// UUID is the UUID of the player logging in.
	UUID uuid.UUID
	// Username is the username of the player logging in.
	Username string
}

LoginSuccess is sent by the server to the client to notify it that it's login attempt was successful. It is the last packet of the login sequence, and is the indicator to switch to the play state.

func (*LoginSuccess) ID

func (*LoginSuccess) ID() int32

ID ...

func (*LoginSuccess) Marshal

func (pk *LoginSuccess) Marshal(w *protocol.Writer)

Marshal ...

func (*LoginSuccess) Unmarshal

func (pk *LoginSuccess) Unmarshal(r *protocol.Reader)

Unmarshal ...

type Packet

type Packet interface {
	// ID returns the ID of the packet. All of these identifiers of packets may be found in id.go.
	ID() int32
	// Marshal encodes the packet to its binary representation into buf.
	Marshal(w *protocol.Writer)
	// 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(r *protocol.Reader)
}

Packet represents a packet that may be sent over a Minecraft network connection.

type ServerKeepAlive

type ServerKeepAlive struct {
	// PingID is the time in Unix milliseconds that the server sent the packet.
	PingID int64
}

ServerKeepAlive is a packet sent by the server to the client usually every two seconds to keep the connection alive.

func (*ServerKeepAlive) ID

func (*ServerKeepAlive) ID() int32

ID ...

func (*ServerKeepAlive) Marshal

func (pk *ServerKeepAlive) Marshal(w *protocol.Writer)

Marshal ...

func (*ServerKeepAlive) Unmarshal

func (pk *ServerKeepAlive) Unmarshal(r *protocol.Reader)

Unmarshal ...

type ServerPlayerPositionRotation

type ServerPlayerPositionRotation struct {
	// X, Y, Z are the new coordinates of the player.
	X, Y, Z float64
	// Yaw, Pitch are the new rotation of the player.
	Yaw, Pitch float32

	// Flags are the flags sent by the server in a bitfield.
	Flags byte
	// TeleportID is used if the position update was caused by a teleport.
	TeleportID int32
	// DismountVehicle is used if the player should dismount their vehicle.
	DismountVehicle bool
}

ServerPlayerPositionRotation is sent by the server to update the player's position.

func (*ServerPlayerPositionRotation) ID

ID ...

func (*ServerPlayerPositionRotation) Marshal

Marshal ...

func (*ServerPlayerPositionRotation) Unmarshal

func (pk *ServerPlayerPositionRotation) Unmarshal(r *protocol.Reader)

Unmarshal ...

type ServerStatusPong

type ServerStatusPong struct {
	// Payload is usually the same payload as the one in ClientStatusPing.
	Payload int64
}

ServerStatusPong is sent by the server to the client as a response to a ClientStatusPing.

func (*ServerStatusPong) ID

func (*ServerStatusPong) ID() int32

ID ...

func (*ServerStatusPong) Marshal

func (pk *ServerStatusPong) Marshal(w *protocol.Writer)

Marshal ...

func (*ServerStatusPong) Unmarshal

func (pk *ServerStatusPong) Unmarshal(r *protocol.Reader)

Unmarshal ...

type ServerStatusResponse

type ServerStatusResponse struct {
	// Status is the JSON encoded status string.
	Status string
}

ServerStatusResponse is a response to the ClientStatusRequest packet, with the status sent as a string encoded in JSON.

func (*ServerStatusResponse) ID

ID ...

func (*ServerStatusResponse) Marshal

func (pk *ServerStatusResponse) Marshal(w *protocol.Writer)

Marshal ...

func (*ServerStatusResponse) Unmarshal

func (pk *ServerStatusResponse) Unmarshal(r *protocol.Reader)

Unmarshal ...

type SetCompression

type SetCompression struct {
	// Threshold is the compression threshold to be used.
	Threshold int32
}

SetCompression updates the compression threshold on the client to whatever threshold the server requests. This is usually done right after encryption.

func (*SetCompression) ID

func (*SetCompression) ID() int32

ID ...

func (*SetCompression) Marshal

func (pk *SetCompression) Marshal(w *protocol.Writer)

Marshal ...

func (*SetCompression) Unmarshal

func (pk *SetCompression) Unmarshal(r *protocol.Reader)

Unmarshal ...

type State

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

State represents the state the connection is on. These split up the packets that can be accessed to a specific selection based on the state.

func StateHandshaking

func StateHandshaking() State

StateHandshaking represents the handshaking state.

func StateLogin

func StateLogin() State

StateLogin represents the login state.

func StatePlay

func StatePlay() State

StatePlay represents the play state.

func StateStatus

func StateStatus() State

StateStatus represents the status state.

func (State) Packet

func (s State) Packet(direction Direction, id int32) Packet

Packet finds a packet in the state. based on the target direction and ID.

type UpdateViewPosition

type UpdateViewPosition struct {
	// X, Z are the coordinates of the new chunk to be viewed.
	X, Z int32
}

UpdateViewPosition is sent by the server to update the client's view position.

func (*UpdateViewPosition) ID

func (*UpdateViewPosition) ID() int32

ID ...

func (*UpdateViewPosition) Marshal

func (pk *UpdateViewPosition) Marshal(w *protocol.Writer)

Marshal ...

func (*UpdateViewPosition) Unmarshal

func (pk *UpdateViewPosition) Unmarshal(r *protocol.Reader)

Unmarshal ...

Jump to

Keyboard shortcuts

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