v0.0.4 Latest Latest

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 41 Imported by: 0




View Source
const (
	CameraShakePositional = iota


View Source
var ErrSelfRuntimeID = errors.New("invalid entity runtime ID: runtime ID for self must always be 1")

ErrSelfRuntimeID is an error returned during packet handling for fields that refer to the player itself and must therefore always be 1.

View Source
var Nop = &Session{}

Nop represents a no-operation session. It does not do anything when sending a packet to it.


This section is empty.


type BlockPickRequestHandler

type BlockPickRequestHandler struct{}

BlockPickRequestHandler handles the BlockPickRequest packet.

func (BlockPickRequestHandler) Handle

Handle ...

type CameraShakeType

type CameraShakeType uint8

CameraShakeType is the type of camera shake that the player receives

type ClientCacheBlobStatusHandler

type ClientCacheBlobStatusHandler struct {

ClientCacheBlobStatusHandler handles the ClientCacheBlobStatus packet.

func (*ClientCacheBlobStatusHandler) Handle

Handle ...

type CommandRequestHandler

type CommandRequestHandler struct {
	// contains filtered or unexported fields

CommandRequestHandler handles the CommandRequest packet.

func (*CommandRequestHandler) Handle

func (h *CommandRequestHandler) Handle(p packet.Packet, s *Session) error

Handle ...

type ContainerCloseHandler

type ContainerCloseHandler struct{}

ContainerCloseHandler handles the ContainerClose packet.

func (*ContainerCloseHandler) Handle

func (h *ContainerCloseHandler) Handle(p packet.Packet, s *Session) error

Handle ...

type Controllable

type Controllable interface {
	SetHeldItems(right, left item.Stack)

	Move(deltaPos mgl64.Vec3)
	Speed() float64
	EyeHeight() float64
	Rotate(deltaYaw, deltaPitch float64)

	Chat(msg ...interface{})
	ExecuteCommand(commandLine string)
	GameMode() gamemode.GameMode
	SetGameMode(mode gamemode.GameMode)

	UseItemOnBlock(pos world.BlockPos, face world.Face, clickPos mgl64.Vec3)
	UseItemOnEntity(e world.Entity)
	BreakBlock(pos world.BlockPos)
	PickBlock(pos world.BlockPos)
	AttackEntity(e world.Entity)
	Drop(s item.Stack) (n int)


	Sneaking() bool
	Sprinting() bool
	Swimming() bool

	StartBreaking(pos world.BlockPos, face world.Face)
	ContinueBreaking(face world.Face)

	Exhaust(points float64)

	// UUID returns the UUID of the controllable. It must be unique for all controllable entities present in
	// the server.
	UUID() uuid.UUID
	// XUID returns the XBOX Live User ID of the controllable. Every controllable must have one of these if
	// they are authenticated via XBOX Live, as they must be connected to an XBOX Live account.
	XUID() string
	// Skin returns the skin of the controllable. Each controllable must have a skin, as it defines how the
	// entity looks in the world.
	Skin() skin.Skin

Controllable represents an entity that may be controlled by a Session. Generally, a Controllable is implemented in the form of a Player. Methods in Controllable will be added as Session needs them in order to handle packets.

type EmoteHandler

type EmoteHandler struct {
	LastEmote time.Time

EmoteHandler handles the Emote packet.

func (*EmoteHandler) Handle

func (h *EmoteHandler) Handle(p packet.Packet, s *Session) error

Handle ...

type InteractHandler

type InteractHandler struct{}

InteractHandler handles the Interact packet.

func (*InteractHandler) Handle

func (h *InteractHandler) Handle(p packet.Packet, s *Session) error

Handle ...

type InventoryTransactionHandler

type InventoryTransactionHandler struct {
	// contains filtered or unexported fields

InventoryTransactionHandler handles the InventoryTransaction packet.

func (*InventoryTransactionHandler) Handle

Handle ...

type ItemStackRequestHandler

type ItemStackRequestHandler struct {
	// contains filtered or unexported fields

ItemStackRequestHandler handles the ItemStackRequest packet. It handles the actions done within the inventory.

func (*ItemStackRequestHandler) Handle

Handle ...

type MobEquipmentHandler

type MobEquipmentHandler struct{}

MobEquipmentHandler handles the MobEquipment packet.

func (*MobEquipmentHandler) Handle

Handle ...

type ModalFormResponseHandler

type ModalFormResponseHandler struct {
	// contains filtered or unexported fields

ModalFormResponseHandler handles the ModalFormResponse packet.

func (*ModalFormResponseHandler) Handle

Handle ...

type PlayerActionHandler

type PlayerActionHandler struct{}

PlayerActionHandler handles the PlayerAction packet.

func (*PlayerActionHandler) Handle

Handle ...

type PlayerAuthInputHandler

type PlayerAuthInputHandler struct{}

PlayerAuthInputHandler handles the PlayerAuthInput packet.

func (PlayerAuthInputHandler) Handle

Handle ...

type RequestChunkRadiusHandler

type RequestChunkRadiusHandler struct{}

RequestChunkRadiusHandler handles the RequestChunkRadius packet.

func (*RequestChunkRadiusHandler) Handle

Handle ...

type RespawnHandler

type RespawnHandler struct{}

RespawnHandler handles the Respawn packet.

func (*RespawnHandler) Handle

func (*RespawnHandler) Handle(p packet.Packet, s *Session) error

Handle ...

type Session

type Session struct {
	// contains filtered or unexported fields

Session handles incoming packets from connections and sends outgoing packets by providing a thin layer of abstraction over direct packets. A Session basically 'controls' an entity.

func New

func New(conn *minecraft.Conn, maxChunkRadius int, log *logrus.Logger, joinMessage, quitMessage *atomic.String) *Session

New returns a new session using a controllable entity. The session will control this entity using the packets that it receives. New takes the connection from which to accept packets. It will start handling these packets after a call to Session.Start().

func (*Session) ClientData

func (s *Session) ClientData() login.ClientData

ClientData returns the login.ClientData of the underlying *minecraft.Conn.

func (*Session) Close

func (s *Session) Close() error

Close closes the session, which in turn closes the controllable and the connection that the session manages.

func (*Session) CloseConnection

func (s *Session) CloseConnection()

CloseConnection closes the underlying connection of the session so that the session ends up being closed eventually.

func (*Session) Disconnect

func (s *Session) Disconnect(message string)

Disconnect disconnects the client and ultimately closes the session. If the message passed is non-empty, it will be shown to the client.

func (*Session) EnableCoordinates

func (s *Session) EnableCoordinates(enable bool)

EnableCoordinates will either enable or disable coordinates for the player depending on the value given.

func (*Session) HandleInventories

func (s *Session) HandleInventories() (inv, offHand *inventory.Inventory, armour *inventory.Armour, heldSlot *atomic.Uint32)

HandleInventories starts handling the inventories of the Controllable of the session. It sends packets when slots in the inventory are changed.

func (*Session) HideEntity

func (s *Session) HideEntity(e world.Entity)

HideEntity ...

func (*Session) Latency

func (s *Session) Latency() time.Duration

Latency returns the latency of the connection.

func (*Session) OpenBlockContainer

func (s *Session) OpenBlockContainer(pos world.BlockPos)

OpenBlockContainer ...

func (*Session) Position

func (s *Session) Position() mgl64.Vec3

Position ...

func (*Session) RemoveBossBar

func (s *Session) RemoveBossBar()

RemoveBossBar removes any boss bar currently active on the player's screen.

func (*Session) RemoveScoreboard

func (s *Session) RemoveScoreboard()

RemoveScoreboard ...

func (*Session) SendAbsorption

func (s *Session) SendAbsorption(value float64)

SendAbsorption sends the absorption value passed to the player.

func (*Session) SendActionBarMessage

func (s *Session) SendActionBarMessage(text string)

SendActionBarMessage ...

func (*Session) SendAnnouncement

func (s *Session) SendAnnouncement(message string)

SendAnnouncement ...

func (*Session) SendAvailableCommands

func (s *Session) SendAvailableCommands()

SendAvailableCommands sends all available commands of the server. Once sent, they will be visible in the /help list and will be auto-completed.

func (*Session) SendBossBar

func (s *Session) SendBossBar(text string, healthPercentage float64)

SendBossBar sends a boss bar to the player with the text passed and the health percentage of the bar. SendBossBar removes any boss bar that might be active before sending the new one.

func (*Session) SendCameraShake

func (s *Session) SendCameraShake(Intensity, Duration float32, Type CameraShakeType)

SendCameraShake sends a shake amount for the players camera

func (*Session) SendCommandOutput

func (s *Session) SendCommandOutput(output *cmd.Output)

SendCommandOutput sends the output of a command to the player. It will be shown to the caller of the command, which might be the player or a websocket server.

func (*Session) SendEffect

func (s *Session) SendEffect(e effect.Effect)

SendEffect sends an effects passed to the player.

func (*Session) SendEffectRemoval

func (s *Session) SendEffectRemoval(e effect.Effect)

SendEffectRemoval sends the removal of an effect passed.

func (*Session) SendFood

func (s *Session) SendFood(food int, saturation, exhaustion float64)

SendFood ...

func (*Session) SendForm

func (s *Session) SendForm(f form.Form)

SendForm sends a form to the client of the connection. The Submit method of the form is called when the client submits the form.

func (*Session) SendGameMode

func (s *Session) SendGameMode(mode gamemode.GameMode)

SendGameMode sends the game mode of the Controllable of the session to the client. It makes sure the right flags are set to create the full game mode.

func (*Session) SendHealth

func (s *Session) SendHealth(health *entity_internal.HealthManager)

SendHealth sends the health and max health to the player.

func (*Session) SendJukeboxPopup

func (s *Session) SendJukeboxPopup(message string)

SendJukeboxPopup ...

func (*Session) SendMessage

func (s *Session) SendMessage(message string)

SendMessage ...

func (*Session) SendPopup

func (s *Session) SendPopup(message string)

SendPopup ...

func (*Session) SendRespawn

func (s *Session) SendRespawn()

SendRespawn spawns the controllable of the session client-side in the world, provided it is has died.

func (*Session) SendScoreboard

func (s *Session) SendScoreboard(displayName string)

SendScoreboard ...

func (*Session) SendScoreboardLines

func (s *Session) SendScoreboardLines(v []string)

SendScoreboardLines sends a list of scoreboard lines for the scoreboard currently active on the player's screen.

func (*Session) SendSpeed

func (s *Session) SendSpeed(speed float64)

SendSpeed sends the speed of the player in an UpdateAttributes packet, so that it is updated client-side.

func (*Session) SendSubtitle

func (s *Session) SendSubtitle(text string)

SendSubtitle ...

func (*Session) SendTip

func (s *Session) SendTip(message string)

SendTip ...

func (*Session) SendTitle

func (s *Session) SendTitle(text string)

SendTitle ...

func (*Session) SendVelocity

func (s *Session) SendVelocity(velocity mgl64.Vec3)

SendVelocity sends the velocity of the player to the client.

func (*Session) SetHeldSlot

func (s *Session) SetHeldSlot(slot int) error

SetHeldSlot sets the currently held hotbar slot.

func (*Session) SetTitleDurations

func (s *Session) SetTitleDurations(fadeInDuration, remainDuration, fadeOutDuration time.Duration)

SetTitleDurations ...

func (*Session) Start

func (s *Session) Start(c Controllable, w *world.World, onStop func(controllable Controllable))

Start makes the session start handling incoming packets from the client and initialises the controllable of the session in the world. The function passed will be called when the session stops running.

func (*Session) Transfer

func (s *Session) Transfer(ip net.IP, port int)

Transfer transfers the player to a server with the IP and port passed.

func (*Session) ViewBlockAction

func (s *Session) ViewBlockAction(pos world.BlockPos, a blockAction.Action)

ViewBlockAction ...

func (*Session) ViewBlockUpdate

func (s *Session) ViewBlockUpdate(pos world.BlockPos, b world.Block, layer int)

ViewBlockUpdate ...

func (*Session) ViewChunk

func (s *Session) ViewChunk(pos world.ChunkPos, c *chunk.Chunk, blockEntities map[world.BlockPos]world.Block)

ViewChunk ...

func (*Session) ViewEmote

func (s *Session) ViewEmote(player world.Entity, emote uuid.UUID)

ViewEmote ...

func (*Session) ViewEntity

func (s *Session) ViewEntity(e world.Entity)

ViewEntity ...

func (*Session) ViewEntityAction

func (s *Session) ViewEntityAction(e world.Entity, a action.Action)

ViewEntityAction ...

func (*Session) ViewEntityArmour

func (s *Session) ViewEntityArmour(e world.Entity)

ViewEntityArmour ...

func (*Session) ViewEntityItems

func (s *Session) ViewEntityItems(e world.Entity)

ViewEntityItems ...

func (*Session) ViewEntityMovement

func (s *Session) ViewEntityMovement(e world.Entity, deltaPos mgl64.Vec3, deltaYaw, deltaPitch float64)

ViewEntityMovement ...

func (*Session) ViewEntityState

func (s *Session) ViewEntityState(e world.Entity, states []state.State)

ViewEntityState ...

func (*Session) ViewEntityTeleport

func (s *Session) ViewEntityTeleport(e world.Entity, position mgl64.Vec3)

ViewEntityTeleport ...

func (*Session) ViewEntityVelocity

func (s *Session) ViewEntityVelocity(e world.Entity, velocity mgl64.Vec3)

ViewEntityVelocity ...

func (*Session) ViewParticle

func (s *Session) ViewParticle(pos mgl64.Vec3, p world.Particle)

ViewParticle ...

func (*Session) ViewSlotChange

func (s *Session) ViewSlotChange(slot int, newItem item.Stack)

ViewSlotChange ...

func (*Session) ViewSound

func (s *Session) ViewSound(pos mgl64.Vec3, soundType world.Sound)

ViewSound ...

func (*Session) ViewTime

func (s *Session) ViewTime(time int)

ViewTime ...

type TextHandler

type TextHandler struct{}

TextHandler handles the Text packet.

func (TextHandler) Handle

func (TextHandler) Handle(p packet.Packet, s *Session) error

Handle ...

Jump to

Keyboard shortcuts

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