session

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context added in v0.0.23

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

Context represents the context of an action. It holds the state of whether the action has been canceled.

func NewContext added in v0.0.23

func NewContext() *Context

NewContext returns a new context.

func (*Context) Cancel added in v0.0.23

func (c *Context) Cancel()

Cancel marks the context as canceled. This function is used to stop further processing of an action.

func (*Context) Cancelled added in v0.0.23

func (c *Context) Cancelled() bool

Cancelled returns whether the context has been cancelled.

type NopProcessor added in v0.0.23

type NopProcessor struct{}

NopProcessor is a no-operation implementation of the Processor interface.

func (NopProcessor) ProcessClient added in v0.0.23

func (NopProcessor) ProcessClient(_ *Context, _ packet.Packet)

func (NopProcessor) ProcessClientEncoded added in v0.0.26

func (NopProcessor) ProcessClientEncoded(_ *Context, _ *[]byte)

func (NopProcessor) ProcessDisconnection added in v0.0.23

func (NopProcessor) ProcessDisconnection(_ *Context)

func (NopProcessor) ProcessPostTransfer added in v0.0.23

func (NopProcessor) ProcessPostTransfer(_ *Context, _ *string, _ *string)

func (NopProcessor) ProcessPreTransfer added in v0.0.23

func (NopProcessor) ProcessPreTransfer(_ *Context, _ *string, _ *string)

func (NopProcessor) ProcessServer added in v0.0.23

func (NopProcessor) ProcessServer(_ *Context, _ packet.Packet)

func (NopProcessor) ProcessServerEncoded added in v0.0.26

func (NopProcessor) ProcessServerEncoded(_ *Context, _ *[]byte)

func (NopProcessor) ProcessStartGame added in v0.0.23

func (NopProcessor) ProcessStartGame(_ *Context, _ *minecraft.GameData)

type Processor

type Processor interface {
	// ProcessStartGame is called only once during the login sequence.
	ProcessStartGame(ctx *Context, data *minecraft.GameData)
	// ProcessServer is called before forwarding the server-sent packets to the client.
	ProcessServer(ctx *Context, pk packet.Packet)
	// ProcessServerEncoded is called before forwarding the server-sent packets to the client.
	ProcessServerEncoded(ctx *Context, pk *[]byte)
	// ProcessClient is called before forwarding the client-sent packets to the server.
	ProcessClient(ctx *Context, pk packet.Packet)
	// ProcessClientEncoded is called before forwarding the client-sent packets to the server.
	ProcessClientEncoded(ctx *Context, pk *[]byte)
	// ProcessPreTransfer is called before transferring the player to a different server.
	ProcessPreTransfer(ctx *Context, origin *string, target *string)
	// ProcessPostTransfer is called after transferring the player to a different server.
	ProcessPostTransfer(ctx *Context, origin *string, target *string)
	// ProcessDisconnection is called when the player disconnects from the proxy.
	ProcessDisconnection(ctx *Context)
}

Processor defines methods for processing various actions within a proxy session.

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) AddSession

func (r *Registry) AddSession(xuid string, session *Session)

func (*Registry) GetSession

func (r *Registry) GetSession(xuid string) *Session

func (*Registry) GetSessionByUsername

func (r *Registry) GetSessionByUsername(username string) *Session

func (*Registry) GetSessions

func (r *Registry) GetSessions() []*Session

func (*Registry) RemoveSession

func (r *Registry) RemoveSession(xuid string)

type Session

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

Session represents a player session within the proxy, managing client and server interactions, including transfers, fallbacks, and tracking various session states.

func NewSession

func NewSession(clientConn *minecraft.Conn, logger *slog.Logger, registry *Registry, discovery server.Discovery, opts util.Opts, transport transport.Transport) *Session

NewSession creates a new Session instance using the provided minecraft.Conn.

func (*Session) Animation added in v0.0.4

func (s *Session) Animation() animation.Animation

Animation returns the animation set to be played during server transfers.

func (*Session) Client added in v0.0.8

func (s *Session) Client() *minecraft.Conn

Client returns the client connection.

func (*Session) Close

func (s *Session) Close() (err error)

Close closes the session, including the server and client connections.

func (*Session) Disconnect

func (s *Session) Disconnect(message string)

Disconnect sends a packet.Disconnect to the client and closes the session.

func (*Session) Latency

func (s *Session) Latency() int64

Latency returns the total latency experienced by the session, combining client and server latencies. Note: The client's latency is derived from half of RakNet's round-trip time (RTT). To calculate the total latency, we multiply this value by 2.

func (*Session) Login added in v0.0.18

func (s *Session) Login() (err error)

Login initiates the login sequence with a default timeout of 1 minute.

func (*Session) LoginContext added in v0.0.23

func (s *Session) LoginContext(ctx context.Context) (err error)

LoginContext initiates the login sequence for the session, including server discovery, establishing a connection, and spawning the player in the game. The process is performed using the provided context for cancellation.

func (*Session) LoginTimeout added in v0.0.23

func (s *Session) LoginTimeout(duration time.Duration) (err error)

LoginTimeout initiates the login sequence with the specified timeout duration.

func (*Session) Opts added in v0.0.18

func (s *Session) Opts() util.Opts

Opts returns the current session options.

func (*Session) Processor added in v0.0.8

func (s *Session) Processor() Processor

Processor returns the current processor.

func (*Session) Server

func (s *Session) Server() *server.Conn

Server returns the current server connection.

func (*Session) SetAnimation

func (s *Session) SetAnimation(animation animation.Animation)

SetAnimation sets the animation to be played during server transfers.

func (*Session) SetOpts added in v0.0.18

func (s *Session) SetOpts(opts util.Opts)

SetOpts updates the session options.

func (*Session) SetProcessor

func (s *Session) SetProcessor(processor Processor)

SetProcessor sets a new processor for the session.

func (*Session) Transfer

func (s *Session) Transfer(addr string) (err error)

Transfer initiates a transfer to a different server using the specified address. It sets a default timeout of 1 minute for the transfer operation.

func (*Session) TransferContext added in v0.0.23

func (s *Session) TransferContext(ctx context.Context, addr string) (err error)

TransferContext initiates a transfer to a different server using the specified address. It ensures that only one transfer occurs at a time, returning an error if another transfer is already in progress. The process is performed using the provided context for cancellation.

func (*Session) TransferTimeout added in v0.0.23

func (s *Session) TransferTimeout(addr string, duration time.Duration) (err error)

TransferTimeout initiates a transfer to a different server using the specified address and a custom timeout duration for the transfer operation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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