session

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	// HandleClientBoundPacket handles a packet that's sent by the session's connected server. ctx.Cancel()
	// may be called to cancel the packet.
	HandleClientBoundPacket(ctx *event.Context, pk packet.Packet)
	// HandleServerBoundPacket handles a packet that's sent by the session. ctx.Cancel() may be called to
	// cancel the packet.
	HandleServerBoundPacket(ctx *event.Context, pk packet.Packet)
	// HandleServerDisconnect handles the server connection getting closed. ctx.Cancel() may be called after
	// transferring the player to cancel disconnecting them.
	HandleServerDisconnect(ctx *event.Context)
	// HandleTransfer handles a session being transferred to another server. ctx.Cancel() may be called to
	// cancel the transfer.
	HandleTransfer(ctx *event.Context, svr *server.Server)
	// HandleQuit handles the closing of a session. It is always called when the session is disconnected,
	// regardless of the reason.
	HandleQuit()
}

Handler handles events that are called by a player's session.

type LoadBalancer

type LoadBalancer interface {
	// FindServer finds a server for the session to connect to when they first join. If nil is returned, the
	// player is kicked from the proxy.
	FindServer(session *Session) *server.Server
}

LoadBalancer represents a load balancer which helps balance the load of players on the proxy.

type NopHandler

type NopHandler struct{}

NopHandler implements the Handler interface but does not execute any code when an event is called. The default handler of sessions is set to NopHandler. Users may embed NopHandler to avoid having to implement each method.

func (NopHandler) HandleClientBoundPacket

func (NopHandler) HandleClientBoundPacket(*event.Context, packet.Packet)

HandleClientBoundPacket ...

func (NopHandler) HandleQuit

func (NopHandler) HandleQuit()

HandleQuit ...

func (NopHandler) HandleServerBoundPacket

func (NopHandler) HandleServerBoundPacket(*event.Context, packet.Packet)

HandleServerBoundPacket ...

func (NopHandler) HandleServerDisconnect added in v0.1.4

func (NopHandler) HandleServerDisconnect(*event.Context)

HandleServerDisconnect ...

func (NopHandler) HandleTransfer

func (NopHandler) HandleTransfer(*event.Context, *server.Server)

HandleTransfer ...

type Session

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

Session stores the data for an active session on the proxy.

func New

func New(conn *minecraft.Conn, store *Store, loadBalancer LoadBalancer, log internal.Logger) (s *Session, err error)

New creates a new Session with the provided connection.

func (*Session) Close

func (s *Session) Close()

Close closes the session and any linked connections/counters.

func (*Session) Conn

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

Conn returns the active connection for the session.

func (*Session) Disconnect added in v0.2.0

func (s *Session) Disconnect(message string)

Disconnect disconnects the session from the proxy and shows them the provided message. If the message is empty, the player will be immediately sent to the server list instead of seeing the disconnect screen.

func (*Session) Handle

func (s *Session) Handle(h Handler)

Handle sets the handler for the current session which can be used to handle different events from the session. If the handler is nil, a NopHandler is used instead.

func (*Session) Server

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

Server returns the server the session is currently connected to.

func (*Session) ServerConn

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

ServerConn returns the connection for the session's current server.

func (*Session) Transfer

func (s *Session) Transfer(srv *server.Server) (err error)

Transfer transfers the session to the provided server, returning any error that may have occurred during the initial transfer.

func (*Session) Transferring

func (s *Session) Transferring() bool

Transferring returns if the session is currently transferring to a different server or not.

func (*Session) UUID

func (s *Session) UUID() uuid.UUID

UUID returns the UUID from the session's connection.

type SimpleWhitelist added in v0.2.0

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

SimpleWhitelist is a whitelist that, if enabled, only allows a set list of players to join.

func NewSimpleWhitelist added in v0.2.0

func NewSimpleWhitelist(enabled bool, players []string) *SimpleWhitelist

NewSimpleWhitelist returns a simple whitelist from the enabled status and a player list passed.

func (*SimpleWhitelist) Authorize added in v0.2.0

func (s *SimpleWhitelist) Authorize(conn *minecraft.Conn) (bool, string)

Authorize ...

type SplitLoadBalancer added in v0.2.0

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

SplitLoadBalancer attempts to split players evenly across all the servers.

func NewSplitLoadBalancer added in v0.2.0

func NewSplitLoadBalancer(registry *server.Registry) *SplitLoadBalancer

NewSplitLoadBalancer creates a "split" load balancer with the provided server registry.

func (*SplitLoadBalancer) FindServer added in v0.2.0

func (b *SplitLoadBalancer) FindServer(*Session) (srv *server.Server)

FindServer ...

type Store added in v0.2.0

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

Store represents a store which holds all the open sessions on the proxy.

func NewDefaultStore added in v0.2.0

func NewDefaultStore() *Store

NewDefaultStore creates a new Store and returns it.

func (*Store) All added in v0.2.0

func (s *Store) All() (all []*Session)

All returns all the sessions stored on the proxy.

func (*Store) Delete added in v0.2.0

func (s *Store) Delete(x uuid.UUID)

Delete deletes a session from the store.

func (*Store) Load added in v0.2.0

func (s *Store) Load(x uuid.UUID) (*Session, bool)

Load attempts to load a session from the UUID of a player.

func (*Store) LoadFromName added in v0.2.0

func (s *Store) LoadFromName(x string) (*Session, bool)

LoadFromName attempts to load a session from the username of a player.

func (*Store) Store added in v0.2.0

func (s *Store) Store(x *Session)

Store stores the session on the proxy.

type Whitelist added in v0.2.0

type Whitelist interface {
	// Authorize returns whether a player with the given connection is allowed to join the proxy and a message
	// to display to the player on their disconnection screen.
	Authorize(conn *minecraft.Conn) (bool, string)
}

Whitelist handles the players joining the proxy to decide which are allowed join.

Jump to

Keyboard shortcuts

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