portaldf

package module
v0.0.3 Latest Latest
Warning

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

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

README

portal-df

A golang implementation of the Portal protocol.

This library is still a work in progress and does not implement all of Portal's features.

Connecting to Portal

package main

import "github.com/paroxity/portal"

func main() {
    // First create a connection to portal. The address provided should be the address of a running Portal instance.
    proxy, err := portal.New("127.0.0.1:19132")
    if err != nil {
        panic(err)
    }
    // After connecting to portal, you need to run the client to be able to read messages coming from portal.
    go func() {
        if err := proxy.Run(); err != nil {
            panic(err)
        }
    }()
    // Next you need to authenticate with a unique name and the secret configured on the Portal instance.
    if err := proxy.Authenticate("name", "secret"); err != nil {
        panic(err)
    }
    // If you are connecting as a server, you will need to send portal the address of the server.
    if err := proxy.RegisterServerInfo("127.0.0.1:19133"); err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthResponseHandler

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

AuthResponseHandler is responsible for handling the AuthResponse packet sent by the proxy.

func (*AuthResponseHandler) Handle

func (h *AuthResponseHandler) Handle(p packet.Packet, _ *Portal) error

Handle ...

type FindPlayerResponseHandler

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

FindPlayerResponseHandler is responsible for handling the FindPlayer packet sent by the proxy.

func (*FindPlayerResponseHandler) Handle

Handle ...

type PacketHandler

type PacketHandler interface {
	// Handle is responsible for handling an incoming packet for the client.
	Handle(p packet.Packet, portal *Portal) error
}

PacketHandler represents a type which handles a specific packet coming from a client.

type PlayerInfoResponse

type PlayerInfoResponse struct {
	PlayerUuid    uuid.UUID
	PlayerAddress string
	Status        byte
	XUID          string
}

type PlayerInfoResponseHandler

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

PlayerInfoResponseHandler is responsible for handling the PlayerInfoResponse packet sent by the proxy.

func (*PlayerInfoResponseHandler) Handle

Handle ...

type Portal

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

Portal represents a client that connections to a portal proxy over a TCP socket connection.

func New

func New(address string, log *logrus.Logger) (*Portal, error)

New returns a new portal client and attempts to connect to the proxy's socket connection on the provided added.

func (*Portal) Authenticate

func (portal *Portal) Authenticate(name, secret string) error

Authenticate attempts to authenticate the client with the proxy's socket server. The method blocks until it receives an auth response from the proxy.

func (*Portal) Authenticated

func (portal *Portal) Authenticated() bool

Authenticated returns if the client is authenticated with the proxy's socket server.

func (*Portal) FindPlayerFromName

func (portal *Portal) FindPlayerFromName(playerName string) (string, error)

FindPlayerFromName returns the name of the server the player is connected to. If they are not connected to portal, an empty string and false will be returned.

func (*Portal) FindPlayerFromUUID

func (portal *Portal) FindPlayerFromUUID(playerUuid uuid.UUID) (string, error)

FindPlayerFromUUID returns the name of the server the player is connected to. If they are not connected to portal, an empty string and false will be returned.

func (*Portal) Name

func (portal *Portal) Name() string

Name returns the name of the client if it is connected to the proxy's socket server. If not connected, an empty string will be returned.

func (*Portal) PlayerInfo

func (portal *Portal) PlayerInfo(p *player.Player) (*PlayerInfoResponse, error)

PlayerInfo returns the information of the player provided. This information includes their IP address and their XUID.

func (*Portal) PlayerLatency

func (portal *Portal) PlayerLatency(p *player.Player) int64

PlayerLatency returns the latency of the player provided.

func (*Portal) RegisterServerInfo

func (portal *Portal) RegisterServerInfo(address string) error

RegisterServerInfo registers the provided address to the proxy to make it a joinable server.

func (*Portal) Run

func (portal *Portal) Run() error

Run is a blocking function that constantly attempts to read packets from the client's socket connection.

func (*Portal) ServerList

func (portal *Portal) ServerList() ([]packet.ServerEntry, error)

ServerList returns a list of servers that are registered to the connected portal.

func (*Portal) Transfer

func (portal *Portal) Transfer(p *player.Player, server string) (byte, error)

Transfer sends a transfer request to portal, requesting to transfer the player to the server with the provided name. The returned byte is the response status from the transfer. The possible values for this can be found above packet.TransferResponse.

func (*Portal) WritePacket

func (portal *Portal) WritePacket(pk packet.Packet) error

WritePacket writes a packet to the client. Since it's a TCP connection, the payload is prefixed with a length so the client can read the exact length of the packet.

type ServerListResponseHandler

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

ServerListResponseHandler is responsible for handling the ServerListResponse packet sent by the proxy.

func (*ServerListResponseHandler) Handle

Handle ...

type TransferResponseHandler

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

TransferResponseHandler is responsible for handling the TransferResponse packet sent by the proxy.

func (*TransferResponseHandler) Handle

Handle ...

type UpdatePlayerLatencyHandler

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

UpdatePlayerLatencyHandler is responsible for handling the UpdatePlayerLatency packet sent by the proxy.

func NewUpdatePlayerLatencyHandler

func NewUpdatePlayerLatencyHandler(defaultExpiration, cleanupInterval time.Duration) *UpdatePlayerLatencyHandler

func (*UpdatePlayerLatencyHandler) Handle

Handle ...

Jump to

Keyboard shortcuts

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