resourcepack

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BundleDelimiterHandler

type BundleDelimiterHandler struct {
	Player interface {
		proto.PacketWriter
		BackendState() *states.State
	}
	// contains filtered or unexported fields
}

func (*BundleDelimiterHandler) BundlePackets

func (b *BundleDelimiterHandler) BundlePackets(sendPackets Runnable) *future.Chan[error]

BundlePackets bundles all packets sent in the given function.

func (*BundleDelimiterHandler) InBundleSession

func (b *BundleDelimiterHandler) InBundleSession() bool

InBundleSession returns true if the player is in the process of receiving multiple packets.

func (*BundleDelimiterHandler) ToggleBundleSession

func (b *BundleDelimiterHandler) ToggleBundleSession()

ToggleBundleSession toggles the player to be in the process of receiving multiple packets from the backend server via a packet bundle.

type Future

type Future = future.Chan[error]

type Handler

type Handler interface {
	FirstAppliedPack() *Info
	FirstPendingPack() *Info
	AppliedResourcePacks() []*Info
	PendingResourcePacks() []*Info
	// ClearAppliedResourcePacks clears the applied resource pack field.
	ClearAppliedResourcePacks()
	Remove(id uuid.UUID) bool
	// QueueResourcePack queues a resource-pack for sending to
	// the player and sends it immediately if the queue is empty.
	QueueResourcePack(*Info) error
	// QueueResourcePackRequest queues a resource pack request to be sent to the player.
	// Sends it immediately if the queue is empty.
	QueueResourcePackRequest(*packet.ResourcePackRequest) error
	SendResourcePackRequestPacket(pack *Info) error
	// OnResourcePackResponse processes a client response to a sent resource-pack.
	// No action will be taken in the following cases:
	//
	//  - DOWNLOADED: The resource pack is downloaded and will be applied to the client,
	// 	no action is required in Velocity.
	// 	- INVALID_URL: The client has received a resource pack request
	// 	and the first check it performs is if the URL is valid, if not,
	// 	it will return this value.
	// 	- FAILED_RELOAD: When trying to reload the client's resources,
	// 	an error occurred while reloading a resource pack.
	// 	- DECLINED: Only in modern versions, as the resource pack has already been rejected,
	// 	there is nothing to do, if the resource pack is required,
	// 	the client will be kicked out of the server.
	OnResourcePackResponse(bundle *ResponseBundle) (bool, error)
	HandleResponseResult(queued *Info, bundle *ResponseBundle) (handled bool, err error)
	// HasPackAppliedByHash checks if a resource pack with the given hash has already been applied.
	HasPackAppliedByHash(hash []byte) bool
	CheckAlreadyAppliedPack(hash []byte) error
}

Handler is an internal interface implemented by resource pack handlers of different protocol versions.

func NewHandler

func NewHandler(player Player, eventMgr event.Manager) Handler

NewHandler creates a new resource pack handler appropriate for the player's protocol version.

type Hash

type Hash []byte

Hash is a SHA-1 hash of a resource-pack.

func (Hash) Validate

func (h Hash) Validate() bool

Validate returns true if the given hash is a plausible SHA-1 hash used for resource-packs.

type Info

type Info struct {
	ID uuid.UUID // The ID of this resource-pack.
	// The download link the resource-pack can be found at.
	URL string
	// The SHA-1 hash of the provided resource pack.
	//
	// Note: It is recommended to always set this hash.
	// If this hash is not set/not present then the client will always download
	// the resource pack even if it may still be cached. By having this hash present,
	// the client will check first whether a resource pack by this hash is cached
	// before downloading.
	Hash Hash
	// Whether the acceptance of the resource-pack is enforced.
	//
	// Sets the resource-pack as required to play on the network.
	// This feature was introduced in 1.17.
	// Setting this to true has one of two effects:
	// If the client is on 1.17 or newer:
	//  - The resource-pack prompt will display without a decline button
	//  - Accept or disconnect are the only available options but players may still press escape.
	//  - Forces the resource-pack offer prompt to display even if the player has
	//    previously declined or disabled resource packs
	//  - The player will be disconnected from the network if they close/skip the prompt.
	// If the client is on a version older than 1.17:
	//   - If the player accepts the resource pack or has previously accepted a resource-pack
	//     then nothing else will happen.
	//   - If the player declines the resource pack or has previously declined a resource-pack
	//     the player will be disconnected from the network
	ShouldForce bool
	// The optional message that is displayed on the resource-pack prompt.
	// This is only displayed if the client version is 1.17 or newer.
	Prompt component.Component
	Origin Origin // The origin of the resource-pack.
}

Info is resource-pack info for a resource-pack.

func InfoForRequest

func InfoForRequest(r *packet.ResourcePackRequest) (*Info, error)

InfoForRequest creates a new resource-pack info from a resource-pack request.

func (*Info) RequestPacket

func (i *Info) RequestPacket(protocol proto.Protocol) *packet.ResourcePackRequest

RequestPacket creates a new resource-pack request from the info.

type Origin

type Origin byte

Origin represents the origin of the resource-pack.

const (
	PluginOnProxyOrigin Origin = iota
	DownstreamServerOrigin
)

Type of resource-pack origin.

type Player

type Player interface {
	ID() uuid.UUID
	// PacketWriter returns the writer to the player connection.
	proto.PacketWriter
	BundleHandler() *BundleDelimiterHandler
	State() *state.Registry
	// Protocol returns the protocol of the player.
	Protocol() proto.Protocol
	// BackendInFlight returns the writer to the in-flight backend server connection the player is connected to, if any.
	BackendInFlight() proto.PacketWriter
	Disconnect(reason component.Component)
}

Player is an internal player interface consumed by resource pack handlers

type PlayerResourcePackStatusEvent

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

PlayerResourcePackStatusEvent is fired when the status of a resource pack sent to the player by the server is changed. Depending on the result of this event (which the proxy will wait until completely fired), the player may be kicked from the server.

func (*PlayerResourcePackStatusEvent) OverwriteKick

func (p *PlayerResourcePackStatusEvent) OverwriteKick() bool

OverwriteKick returns whether to override the kick resulting from ResourcePackInfo.ShouldForce() being true.

func (*PlayerResourcePackStatusEvent) PackInfo

func (p *PlayerResourcePackStatusEvent) PackInfo() Info

PackInfo returns the ResourcePackInfo this response is for.

func (*PlayerResourcePackStatusEvent) PlayerID

func (p *PlayerResourcePackStatusEvent) PlayerID() uuid.UUID

PlayerID returns the id of the player affected by the change in resource pack status. To get the player, use the Proxy.Player method.

func (*PlayerResourcePackStatusEvent) SetOverwriteKick

func (p *PlayerResourcePackStatusEvent) SetOverwriteKick(overwriteKick bool)

SetOverwriteKick can set to true to prevent ResourcePackInfo.ShouldForce() from kicking the player. Overwriting this kick is only possible on versions older than 1.17, as the client or server will enforce this regardless. Cancelling the resulting kick-events will not prevent the player from disconnecting from the proxy.

func (*PlayerResourcePackStatusEvent) Status

Status returns the new status for the resource pack.

type ResponseBundle

type ResponseBundle struct {
	// The ID of the resource-pack.
	ID uuid.UUID
	// The hash of the resource-pack.
	Hash Hash
	// The status of the resource-pack.
	Status packet.ResponseStatus
}

ResponseBundle is a response bundle for a resource-pack.

func BundleForResponse

func BundleForResponse(r *packet.ResourcePackResponse) *ResponseBundle

BundleForResponse creates a new response bundle from a resource-pack response.

func (*ResponseBundle) ResponsePacket

func (r *ResponseBundle) ResponsePacket() *packet.ResourcePackResponse

ResponsePacket creates a new resource-pack response from the response bundle.

type ResponseStatus

type ResponseStatus = packet.ResponseStatus

ResponseStatus represents the possible statuses for the resource pack.

const (
	// SuccessfulResponseStatus indicates the resource pack was applied successfully.
	SuccessfulResponseStatus ResponseStatus = packet.SuccessfulResourcePackResponseStatus
	// DeclinedResponseStatus indicates the player declined to download the resource pack.
	DeclinedResponseStatus ResponseStatus = packet.DeclinedResourcePackResponseStatus
	// FailedDownloadResponseStatus indicates the player could not download the resource pack.
	FailedDownloadResponseStatus ResponseStatus = packet.FailedDownloadResourcePackResponseStatus
	// AcceptedResponseStatus indicates the player has accepted the resource pack and is now downloading it.
	AcceptedResponseStatus ResponseStatus = packet.AcceptedResourcePackResponseStatus
	// DownloadedResponseStatus indicates the player has downloaded the resource pack.
	DownloadedResponseStatus ResponseStatus = packet.DownloadedResourcePackResponseStatus
	// InvalidURLResponseStatus indicates the URL of the resource pack failed to load.
	InvalidURLResponseStatus ResponseStatus = packet.InvalidURLResourcePackResponseStatus
	// FailedToReloadResponseStatus indicates the player failed to reload the resource pack.
	FailedToReloadResponseStatus ResponseStatus = packet.FailedToReloadResourcePackResponseStatus
	// DiscardedResponseStatus indicates the resource pack was discarded.
	DiscardedResponseStatus ResponseStatus = packet.DiscardedResourcePackResponseStatus
)

Possible statuses for a resource pack.

type Runnable

type Runnable func() error

Jump to

Keyboard shortcuts

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