utils

package
v1.31.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2023 License: GPL-3.0 Imports: 56 Imported by: 0

Documentation

Overview

Package utils ...

Index

Constants

View Source
const TokenFile = "token.json"

Variables

View Source
var Auth authsrv
View Source
var CmdName = "bedrocktool"
View Source
var DisconnectReason = "Connection lost"
View Source
var MakeGui = func() UI {
	return &InteractiveCLI{}
}
View Source
var NewDebugLogger func(bool) *ProxyHandler
View Source
var NewPacketCapturer func() *ProxyHandler
View Source
var Options struct {
	Debug              bool
	Preload            bool
	IsInteractive      bool
	ExtraDebug         bool
	Capture            bool
	PathCustomUserData string
}
View Source
var PackFromBase = func(pack *resource.Pack) Pack {
	b := &Packb{pack}
	return b
}
View Source
var RealmsEnv string
View Source
var UpdateAvailable string
View Source
var Updater = &selfupdate.Updater{
	CurrentVersion: Version,
	ApiURL:         updateServer,
	BinURL:         updateServer,
	Dir:            "update/",
	CmdName:        CmdName,
	Requester:      &trequester{},
}
View Source
var ValidCMDs = make(map[string]Command, 0)
View Source
var Version string

Functions

func BlendColors

func BlendColors(c1, c2 color.RGBA) (ret color.RGBA)

func CfbDecrypt added in v1.28.0

func CfbDecrypt(data []byte, key []byte) []byte

func Chunk2Img added in v1.28.1

func Chunk2Img(c *chunk.Chunk) *image.RGBA

func Clamp

func Clamp(a, b int) int

func CleanupName

func CleanupName(name string) string

CleanupName cleans name so it can be used as a filename

func DecodePacket added in v1.29.0

func DecodePacket(pool packet.Pool, header packet.Header, payload []byte) packet.Packet

func DrawImgScaledPos added in v1.28.0

func DrawImgScaledPos(dst *image.RGBA, src *image.RGBA, bottomLeft image.Point, sizeScaled int)

DrawImgScaledPos draws src onto dst at bottomLeft, scaled to size

func DumpStruct added in v1.28.0

func DumpStruct(level int, inputStruct any, withType bool, isInList bool) (s string)

func GetLocalIP

func GetLocalIP() string

GetLocalIP returns the non loopback local IP of the host

func GetRealmsAPI added in v1.28.0

func GetRealmsAPI() *realms.Client

func IPPrivate

func IPPrivate(ip net.IP) bool

IPPrivate checks if ip is private

func Img2rgba

func Img2rgba(img *image.RGBA) []color.RGBA

func LERP

func LERP(p1, p2, alpha float64) float64

LERP is a linear interpolation function

func RandSeededUUID added in v1.28.0

func RandSeededUUID(str string) string

func RegisterCommand

func RegisterCommand(sub Command)

func ServerInput

func ServerInput(ctx context.Context, server string) (string, string, error)

func SetCurrentUI added in v1.28.0

func SetCurrentUI(ui UI)

func ShowFile added in v1.28.1

func ShowFile(path string)

func SizeofFmt added in v1.28.1

func SizeofFmt(num float32) string

func SplitExt

func SplitExt(filename string) (name, ext string)

SplitExt splits path to filename and extension

func UnpackZip

func UnpackZip(r io.ReaderAt, size int64, unpackFolder string)

func UserInput added in v1.28.0

func UserInput(ctx context.Context, q string, validator func(string) bool) (string, bool)

func ValidateServerInput added in v1.30.0

func ValidateServerInput(server string) bool

func WriteManifest added in v1.28.0

func WriteManifest(manifest *resource.Manifest, fpath string) error

func WriteReplayHeader added in v1.28.0

func WriteReplayHeader(f io.Writer)

func ZipFolder

func ZipFolder(filename, folder string) error

Types

type BaseUI added in v1.28.0

type BaseUI struct {
	UI
}

func (*BaseUI) Message added in v1.28.0

func (u *BaseUI) Message(data interface{}) messages.MessageResponse

func (*BaseUI) ServerInput added in v1.28.0

func (u *BaseUI) ServerInput(ctx context.Context, server string) (string, string, error)

type Command added in v1.28.0

type Command interface {
	Name() string
	Synopsis() string
	SetFlags(f *flag.FlagSet)
	Execute(ctx context.Context, ui UI) error
}

type CustomClientData added in v1.28.0

type CustomClientData struct {
	// skin things
	CapeFilename         string
	SkinFilename         string
	SkinGeometryFilename string
	SkinID               string
	PlayFabID            string
	PersonaSkin          bool
	PremiumSkin          bool
	TrustedSkin          bool
	ArmSize              string
	SkinColour           string

	// misc
	IsEditorMode bool
	LanguageCode string
	DeviceID     string
}

type IngameCommand

type IngameCommand struct {
	Exec func(cmdline []string) bool
	Cmd  protocol.Command
}

type InteractiveCLI added in v1.28.0

type InteractiveCLI struct {
	BaseUI
}

func (*InteractiveCLI) Init added in v1.28.0

func (c *InteractiveCLI) Init() bool

func (*InteractiveCLI) Start added in v1.28.0

func (c *InteractiveCLI) Start(ctx context.Context, cancel context.CancelFunc) error

type Pack added in v1.28.0

type Pack interface {
	io.ReaderAt
	ReadAll() ([]byte, error)
	Decrypt() ([]byte, error)
	Encrypted() bool
	CanDecrypt() bool
	UUID() string
	Name() string
	Version() string
	ContentKey() string
	Len() int
	Manifest() resource.Manifest
	Base() *resource.Pack
}

func GetPacks

func GetPacks(server minecraft.IConn) (packs []Pack, err error)

type Packb added in v1.28.0

type Packb struct {
	*resource.Pack
}

func (*Packb) Base added in v1.28.0

func (p *Packb) Base() *resource.Pack

func (*Packb) CanDecrypt added in v1.28.0

func (p *Packb) CanDecrypt() bool

func (*Packb) Decrypt added in v1.28.0

func (p *Packb) Decrypt() ([]byte, error)

func (*Packb) ReadAll added in v1.28.0

func (p *Packb) ReadAll() ([]byte, error)

type PacketFunc

type PacketFunc func(header packet.Header, payload []byte, src, dst net.Addr)

type ProxyContext

type ProxyContext struct {
	Server minecraft.IConn
	Client minecraft.IConn

	Listener *minecraft.Listener

	AlwaysGetPacks   bool
	WithClient       bool
	IgnoreDisconnect bool
	CustomClientData *login.ClientData
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy() (*ProxyContext, error)

func (*ProxyContext) AddCommand

func (p *ProxyContext) AddCommand(cmd IngameCommand)

func (*ProxyContext) AddHandler added in v1.28.1

func (p *ProxyContext) AddHandler(handler *ProxyHandler)

func (*ProxyContext) ClientWritePacket added in v1.28.1

func (p *ProxyContext) ClientWritePacket(pk packet.Packet) error

func (*ProxyContext) CommandHandlerPacketCB

func (p *ProxyContext) CommandHandlerPacketCB(pk packet.Packet, toServer bool, _ time.Time) (packet.Packet, error)

func (*ProxyContext) Disconnect added in v1.28.1

func (p *ProxyContext) Disconnect()

Disconnect disconnects both the client and server

func (*ProxyContext) DisconnectClient added in v1.28.1

func (p *ProxyContext) DisconnectClient()

Disconnect disconnects the client

func (*ProxyContext) DisconnectServer added in v1.28.1

func (p *ProxyContext) DisconnectServer()

Disconnect disconnects from the server

func (*ProxyContext) IsClient added in v1.28.1

func (p *ProxyContext) IsClient(addr net.Addr) bool

func (*ProxyContext) LoadCustomUserData added in v1.28.0

func (p *ProxyContext) LoadCustomUserData(path string) error

func (*ProxyContext) Run

func (p *ProxyContext) Run(ctx context.Context, serverAddress, name string) (err error)

func (*ProxyContext) SendMessage

func (p *ProxyContext) SendMessage(text string)

func (*ProxyContext) SendPopup

func (p *ProxyContext) SendPopup(text string)

type ProxyHandler added in v1.28.1

type ProxyHandler struct {
	Name     string
	ProxyRef func(pc *ProxyContext)
	//
	AddressAndName func(address, hostname string) error

	// called to change game data
	GameDataModifier func(gd *minecraft.GameData)

	// called for every packet
	PacketFunc func(header packet.Header, payload []byte, src, dst net.Addr)

	// called on every packet after login
	PacketCB func(pk packet.Packet, toServer bool, timeReceived time.Time) (packet.Packet, error)

	// called after client connected
	OnClientConnect   func(conn minecraft.IConn)
	SecondaryClientCB func(conn minecraft.IConn)

	// called after server connected & downloaded resource packs
	OnServerConnect func() (cancel bool)
	// called after game started
	ConnectCB func(err error) bool

	// called when the proxy stops
	OnEnd func()
}

func NewTransferHandler added in v1.31.0

func NewTransferHandler() *ProxyHandler

type Skin added in v1.28.1

type Skin struct {
	*protocol.Skin
}

func (*Skin) Complex added in v1.28.1

func (skin *Skin) Complex() bool

func (*Skin) Hash added in v1.28.1

func (skin *Skin) Hash() uuid.UUID

func (*Skin) HaveAnimations added in v1.28.1

func (skin *Skin) HaveAnimations() bool

func (*Skin) HaveCape added in v1.28.1

func (skin *Skin) HaveCape() bool

func (*Skin) HaveGeometry added in v1.28.1

func (skin *Skin) HaveGeometry() bool

func (*Skin) HaveTint added in v1.28.1

func (skin *Skin) HaveTint() bool

func (*Skin) WriteCapePng added in v1.28.1

func (skin *Skin) WriteCapePng(output_path string) error

WriteCape writes the cape as a png at output_path

type SkinGeometry added in v1.28.1

type SkinGeometry struct {
	SkinGeometryDescription
	Bones []any `json:"bones"`
}

type SkinGeometryDescription added in v1.31.0

type SkinGeometryDescription struct {
	Identifier          string    `json:"identifier,omitempty"`
	Texturewidth        int       `json:"texturewidth"`
	Textureheight       int       `json:"textureheight"`
	VisibleBoundsWidth  float64   `json:"visible_bounds_width"`
	VisibleBoundsHeight float64   `json:"visible_bounds_height"`
	VisibleBoundsOffset []float64 `json:"visible_bounds_offset,omitempty"`
}

type SkinGeometry_1_12 added in v1.31.0

type SkinGeometry_1_12 struct {
	Description SkinGeometryDescription `json:"description"`
	Bones       []any                   `json:"bones"`
}

type SkinMeta added in v1.28.1

type SkinMeta struct {
	SkinID        string
	PlayFabID     string
	PremiumSkin   bool
	PersonaSkin   bool
	CapeID        string
	SkinColour    string
	ArmSize       string
	Trusted       bool
	PersonaPieces []protocol.PersonaPiece
}

type SkinPack added in v1.28.1

type SkinPack struct {
	Name string
	// contains filtered or unexported fields
}

func NewSkinPack added in v1.28.1

func NewSkinPack(name, fpath string) *SkinPack

func (*SkinPack) AddSkin added in v1.28.1

func (s *SkinPack) AddSkin(skin *Skin) bool

func (*SkinPack) Save added in v1.28.1

func (s *SkinPack) Save(fpath, serverName string) error

type UI added in v1.28.0

type UI interface {
	Init() bool
	Start(context.Context, context.CancelFunc) error
	Message(data interface{}) messages.MessageResponse
	ServerInput(context.Context, string) (string, string, error)
}
var CurrentUI UI

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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