cookie

package
v0.62.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxPayloadSize        = cookie.MaxPayloadSize
	DefaultRequestTimeout = 10 * time.Second
)

Variables

View Source
var (
	ErrUnsupportedClientProtocol = errors.New("player version must be at least 1.20.5 to use cookies")
	ErrUnsupportedState          = fmt.Errorf("cookie can only be stored in %s or %s state", states.ConfigState, states.PlayState)
)

Functions

func Clear

func Clear(c Client, key key.Key) error

Clear clears a stored cookie from the player's client. This is a helper function that stores a cookie with an empty payload.

If the player's protocol is below 1.20.5, ErrUnsupportedClientProtocol is returned. If the player's state is not states.ConfigState or states.PlayState, ErrUnsupportedState is returned.

func RequestAndForget

func RequestAndForget(c Client, key key.Key) error

RequestAndForget works like Request but does not wait for a response.

The cookie response event will still be fired by Gate and can be listened to in the event manager.

func Store

func Store(c Client, cookie *Cookie) error

Store stores a cookie on the player's client.

If the player's protocol is below 1.20.5, ErrUnsupportedClientProtocol is returned. If the player's state is not states.ConfigState or states.PlayState, ErrUnsupportedState is returned.

Types

type Client

type Client interface {
	proto.PacketWriter
	Context() context.Context
}

Client is a player that can store and send stored cookies.

type Cookie struct {
	Key     key.Key
	Payload []byte
}

Cookie is cookie that can be sent and received from clients.

Use Store to save a cookie on the client. When the cookie is modified, Store must be called again to save the changes.

The maximum size of a cookie is 5 kiB.

func Request

func Request(ctx context.Context, c Client, key key.Key, eventMgr event.Manager) (*Cookie, error)

Request requests a stored cookie from the player's client by a given key. This is a blocking operation and the context should be used to timeout the request. The DefaultRequestTimeout always applies as a safety net.

The event manager is used to listen for the cookie response event fired by Gate. Use proxy.Event() to get the proxy's event manager.

Request only subscribes to the cookie response event only until Request returns.

Jump to

Keyboard shortcuts

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