session

package
v0.0.0-...-10637f8 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientPacket = 0x01 // Identifier for client packets
	ServerPacket = 0x02 // Identifier for server packets
	ACPacket     = 0x03
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AntiCheatInfo

type AntiCheatInfo struct {
	Identity        string     `json:"identity"`
	DeviceOs        int        `json:"device_os"`
	TitleId         string     `json:"title_id"`
	DisplayName     string     `json:"display_name"`
	EntityRuntimeId uint64     `json:"entity_runtime_id"`
	EntityUniqueId  int64      `json:"entity_unique_id"`
	PlayerPosition  mgl32.Vec3 `json:"player_position"`
	Pitch           float32    `json:"pitch"`
	Yaw             float32    `json:"yaw"`
	GameMode        int32      `json:"game_mode"`
}

type Client

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

Client represents a persistent connection to the server.

func NewClient

func NewClient(address string, proto minecraft.Protocol, registry *Registry) (*Client, error)

NewClient establishes a persistent connection to the server.

func (*Client) Close

func (c *Client) Close()

Close gracefully closes the connection.

func (*Client) SendAC

func (c *Client) SendAC(data []byte) error

func (*Client) SendClient

func (c *Client) SendClient(data []byte, id string) error

SendClient sends data to the server, marking it as a client packet.

func (*Client) SendServer

func (c *Client) SendServer(data []byte, id string) error

SendServer sends data to the server, marking it as a server packet.

type Context

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

func NewContext() *Context

NewContext returns a new context.

func (*Context) Cancel

func (c *Context) Cancel()

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

func (*Context) Cancelled

func (c *Context) Cancelled() bool

Cancelled returns whether the context has been cancelled.

type NopProcessor

type NopProcessor struct{}

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

func (NopProcessor) ProcessClient

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

func (NopProcessor) ProcessClientEncoded

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

func (NopProcessor) ProcessDisconnection

func (NopProcessor) ProcessDisconnection(_ *Context)

func (NopProcessor) ProcessPostTransfer

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

func (NopProcessor) ProcessPreTransfer

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

func (NopProcessor) ProcessServer

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

func (NopProcessor) ProcessServerEncoded

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

func (NopProcessor) ProcessStartGame

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

func (NopProcessor) ProcessTransferFailure

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

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)
	// ProcessTransferFailure is called when the player transfer to a different server fails.
	ProcessTransferFailure(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, client *Client) *Session

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

func (*Session) Animation

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

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

func (*Session) Client

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. 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

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

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

func (*Session) LoginContext

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

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

LoginTimeout initiates the login sequence with the specified timeout duration.

func (*Session) Opts

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

Opts returns the current session options.

func (*Session) Processor

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

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

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

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