utils

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2023 License: GPL-3.0 Imports: 47 Imported by: 0

Documentation

Overview

Package utils ...

Index

Constants

View Source
const TokenFile = "token.json"

Variables

View Source
var (
	ExtraVerbose []string
	FLog         io.Writer
)
View Source
var ClientAddr net.Addr
View Source
var CmdName = "bedrocktool"
View Source
var DisconnectReason = "Connection lost"
View Source
var MakeGui = func() UI {
	return &InteractiveCLI{}
}
View Source
var MutedPackets = []string{
	"packet.UpdateBlock",
	"packet.MoveActorAbsolute",
	"packet.SetActorMotion",
	"packet.SetTime",
	"packet.RemoveActor",
	"packet.AddActor",
	"packet.UpdateAttributes",
	"packet.Interact",
	"packet.LevelEvent",
	"packet.SetActorData",
	"packet.MoveActorDelta",
	"packet.MovePlayer",
	"packet.BlockActorData",
	"packet.PlayerAuthInput",
	"packet.LevelChunk",
	"packet.LevelSoundEvent",
	"packet.ActorEvent",
	"packet.NetworkChunkPublisherUpdate",
	"packet.UpdateSubChunkBlocks",
	"packet.SubChunk",
	"packet.SubChunkRequest",
	"packet.Animate",
	"packet.NetworkStackLatency",
	"packet.InventoryTransaction",
	"packet.PlaySound",
}
View Source
var Options struct {
	Debug              bool
	Preload            bool
	IsInteractive      bool
	ExtraDebug         bool
	EnableDNS          bool
	PathCustomUserData string
}
View Source
var PackFromBase = func(pack *resource.Pack) Pack {
	b := &Packb{pack}
	return b
}
View Source
var PrivateIPNetworks = []net.IPNet{
	{
		IP:   net.ParseIP("10.0.0.0"),
		Mask: net.CIDRMask(8, 32),
	},
	{
		IP:   net.ParseIP("172.16.0.0"),
		Mask: net.CIDRMask(12, 32),
	},
	{
		IP:   net.ParseIP("192.168.0.0"),
		Mask: net.CIDRMask(16, 32),
	},
}
View Source
var RealmsEnv 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 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 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(data interface{})

func GetLocalIP

func GetLocalIP() string

GetLocalIP returns the non loopback local IP of the host

func GetPacks

func GetPacks(server *minecraft.Conn) (packs map[string]*resource.Pack, err error)

func GetRealmsAPI added in v1.28.0

func GetRealmsAPI() *realms.Client

func GetTokenSource

func GetTokenSource() oauth2.TokenSource

func IPPrivate

func IPPrivate(ip net.IP) bool

IPPrivate checks if ip is private

func Img2rgba

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

func InitDNS

func InitDNS()

func InitExtraDebug added in v1.28.0

func InitExtraDebug(ctx context.Context)

func LERP

func LERP(p1, p2, alpha float64) float64

LERP is a linear interpolation function

func MarginLines

func MarginLines(lines []string) string

MarginLines makes text centered

func PacketLogger

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

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 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) (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(name string, 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 ClientConnectCallback added in v1.28.0

type ClientConnectCallback func(proxy *ProxyContext, hasClient bool)

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 ConnectCallback

type ConnectCallback func(proxy *ProxyContext, err error) bool

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 DNSServer

type DNSServer struct{}

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
}

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 PacketCallback

type PacketCallback func(pk packet.Packet, proxy *ProxyContext, toServer bool, timeReceived time.Time) (packet.Packet, error)

type PacketFunc

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

type ProxyContext

type ProxyContext struct {
	Server   *minecraft.Conn
	Client   *minecraft.Conn
	Listener *minecraft.Listener

	AlwaysGetPacks   bool
	WithClient       bool
	IgnoreDisconnect bool
	CustomClientData *login.ClientData

	// called for every packet
	PacketFunc PacketFunc
	// called after client connected
	OnClientConnect ClientConnectCallback
	// called after game started
	ConnectCB ConnectCallback
	// called on every packet after login
	PacketCB PacketCallback
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy() (*ProxyContext, error)

func (*ProxyContext) AddCommand

func (p *ProxyContext) AddCommand(cmd IngameCommand)

func (*ProxyContext) CommandHandlerPacketCB

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

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 string) (err error)

func (*ProxyContext) SendMessage

func (p *ProxyContext) SendMessage(text string)

func (*ProxyContext) SendPopup

func (p *ProxyContext) SendPopup(text string)

type RealmListCMD

type RealmListCMD struct{}

func (*RealmListCMD) Execute

func (c *RealmListCMD) Execute(ctx context.Context, ui UI) error

func (*RealmListCMD) Name

func (*RealmListCMD) Name() string

func (*RealmListCMD) SetFlags

func (c *RealmListCMD) SetFlags(f *flag.FlagSet)

func (*RealmListCMD) Synopsis

func (*RealmListCMD) Synopsis() string

type UI added in v1.28.0

type UI interface {
	Init() bool
	Start(context.Context, context.CancelFunc) error
	Message(name string, 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