update ci to build gui

This commit is contained in:
olebeck 2023-03-06 02:03:31 +01:00
parent 5b5ddc92bb
commit 5a54b98fd7
20 changed files with 222 additions and 326 deletions

View File

@ -16,7 +16,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'
check-latest: true
cache: true
@ -33,8 +33,7 @@ jobs:
rm ../bedrock-repo-key.key
env:
REPO_KEY: ${{ secrets.REPO_KEY }}
- run: go install github.com/sanbornm/go-selfupdate/cmd/go-selfupdate
- run: go get ./cmd/bedrocktool
- name: Install SSH Key
@ -46,10 +45,10 @@ jobs:
- name: build
id: build
run: |
make -j dists updates
python build.py
- name: Deploy with rsync
run: rsync -avz ./public/ olebeck@${{ secrets.SSH_HOST }}:/var/www/updates/bedrocktool/
run: rsync -avz ./updates/ olebeck@${{ secrets.SSH_HOST }}:/var/www/updates/bedrocktool/
- name: 'Get Previous tag'
id: previoustag
@ -59,5 +58,5 @@ jobs:
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{ steps.previoustag.outputs.tag }}
files: dist/*
files: ./builds/*
prerelease: false

4
.gitignore vendored
View File

@ -18,7 +18,9 @@ keys.db
/skins/
/worlds/
/dist/
/public/
/builds/
/updates/
/fyne-cross/
packets.log.gpg
customdata.json

View File

@ -1,58 +0,0 @@
TAG = $(shell git describe --exclude "r-*" --tags --always)
NAME = bedrocktool-${TAG}
SRCS = $(wildcard **/*.go)
GC = go build -ldflags "-s -w -X github.com/bedrock-tool/bedrocktool/utils.Version=${TAG}"
.PHONY: dists clean updates
# check if packs are supported
HAVE_PACKS = false
ifeq ($(shell head -c 7 ./utils/resourcepack-ace.go),package)
HAVE_PACKS = true
endif
$(info pack support: ${HAVE_PACKS})
ifneq ($(HAVE_PACKS),true)
GC += -overlay overlay.json
endif
bedrocktool: $(SRCS)
$(GC) -o $@ ./cmd/bedrocktool
BUILDS=\
windows_386.exe\
windows_amd64.exe\
windows_arm64.exe\
windows_arm.exe\
darwin_amd64\
darwin_arm64\
linux_386\
linux_amd64\
linux_arm64\
linux_arm
DISTS=$(BUILDS:%=dist/$(NAME)_%)
dists: $(DISTS)
$(DISTS): OS = $(word 2,$(subst _, ,$@))
$(DISTS): ARCH = $(word 1,$(subst ., ,$(word 3,$(subst _, ,$@))))
$(DISTS): BUILD = builds/$(OS)-$(ARCH)
dist builds:
mkdir -p dist builds
$(DISTS): dist builds $(SRCS)
$(info building: $@)
GOOS=$(OS) GOARCH=$(ARCH) $(GC) -o $(BUILD) ./cmd/bedrocktool
cp $(BUILD) $@
UPDATES=$(BUILDS)
$(UPDATES): OS = $(word 1,$(subst _, ,$@))
$(UPDATES): ARCH = $(word 1,$(subst ., ,$(word 2,$(subst _, ,$@))))
updates: $(UPDATES)
$(UPDATES): $(DISTS)
go-selfupdate -platform $(OS)-$(ARCH) builds/ $(TAG)
clean:
rm -r dist builds public

74
build.py Normal file
View File

@ -0,0 +1,74 @@
import subprocess, re, sys, os, shutil, json, binascii, hashlib, gzip
VER_RE = re.compile(r"v(\d\.\d+\.\d+)")
NAME = "bedrocktool"
APP_ID = "yuv.pink.bedrocktool"
TAG = subprocess.run(["git", "describe", "--exclude", "r-*", "--tags", "--always"], stdout=subprocess.PIPE).stdout.decode("utf8").split("\n")[0]
VER = VER_RE.match(TAG).group(1)
with open("./utils/resourcepack-ace.go") as f:
PACK_SUPPORT = f.read(7) == "package"
print(f"Pack Support: {PACK_SUPPORT}")
LDFLAGS = f"-s -w -X github.com/bedrock-tool/bedrocktool/utils.Version={TAG}"
PLATFORMS = [
("windows", ["386", "amd64"], ".exe"),
("linux", ["386", "amd64", "arm", "arm64"], ""),
("darwin", ["amd64", "arm64"], ""),
]
platform_filter = ""
if len(sys.argv) > 1:
platform_filter = sys.argv[1]
if os.path.exists("./builds"):
shutil.rmtree("./builds")
os.mkdir("./builds")
if os.path.exists("./updates"):
shutil.rmtree("./updates")
os.mkdir("./updates")
os.mkdir(f"./updates/{TAG}")
for (platform_name, archs, ext) in PLATFORMS:
if platform_filter and platform_filter != platform_name:
continue
print(f"Building {platform_name}")
exe_name = f"{NAME}{ext}"
args = [
"fyne-cross", platform_name,
"-app-version", VER,
"-arch", ",".join(archs),
"-ldflags", LDFLAGS,
"-name", exe_name,
]
if platform_name == "windows":
args.append("-console")
if platform_name == "darwin":
args.extend(["-app-id", APP_ID])
args.append("./cmd/bedrocktool")
out = subprocess.run(args)
out.check_returncode()
for arch in archs:
exe_path = f"./fyne-cross/bin/{platform_name}-{arch}/{exe_name}"
with open(exe_path, "rb") as f:
exe_data = f.read()
sha = binascii.b2a_base64(hashlib.sha256(exe_data).digest()).decode("utf8").split("\n")[0]
with open(f"./updates/{platform_name}-{arch}.json", "w") as f:
f.write(json.dumps({
"Version": TAG,
"Sha256": sha,
}, indent=2))
with gzip.open(f"./updates/{TAG}/{platform_name}-{arch}.gz", "wb") as f:
f.write(exe_data)
with open(f"./builds/{NAME}-{platform_name}-{arch}-{TAG}{ext}", "wb") as f:
f.write(exe_data)

View File

@ -33,8 +33,9 @@ type CLI struct {
func (c *CLI) Init() {
}
func (c *CLI) SetOptions() {
func (c *CLI) SetOptions() bool {
flag.Parse()
return false
}
func (c *CLI) Execute(ctx context.Context) error {
@ -86,6 +87,7 @@ func main() {
flag.BoolVar(&utils.Options.Debug, "debug", false, locale.Loc("debug_mode", nil))
flag.BoolVar(&utils.Options.Preload, "preload", false, locale.Loc("preload_packs", nil))
flag.BoolVar(&utils.Options.ExtraDebug, "extra-debug", false, locale.Loc("extra_debug", nil))
flag.StringVar(&utils.Options.PathCustomUserData, "userdata", "", locale.Loc("custom_user_data", nil))
flag.String("lang", "", "lang")
flag.BoolVar(&utils.Options.EnableDNS, "dns", false, locale.Loc("enable_dns", nil))
@ -105,7 +107,13 @@ func main() {
}
ui.Init()
ui.SetOptions()
if ui.SetOptions() {
return
}
if ctx.Err() != nil {
return
}
if utils.Options.EnableDNS {
utils.InitDNS()

View File

@ -7,9 +7,70 @@ import (
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
"github.com/bedrock-tool/bedrocktool/subcommands"
"github.com/bedrock-tool/bedrocktool/subcommands/skins"
"github.com/bedrock-tool/bedrocktool/subcommands/world"
"github.com/bedrock-tool/bedrocktool/utils"
)
var settings = map[string]func(utils.Command) *widget.Form{
"world": func(cc utils.Command) *widget.Form {
c := cc.(*world.WorldCMD)
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.ServerAddress)),
), widget.NewFormItem(
"", widget.NewCheckWithData("packs", binding.BindBool(&c.Packs)),
), widget.NewFormItem(
"", widget.NewCheckWithData("void", binding.BindBool(&c.EnableVoid)),
), widget.NewFormItem(
"", widget.NewCheckWithData("saveImage", binding.BindBool(&c.SaveImage)),
), widget.NewFormItem(
"", widget.NewCheckWithData("experimentInventory", binding.BindBool(&c.ExperimentInventory)),
),
)
},
"skins": func(cc utils.Command) *widget.Form {
c := cc.(*skins.SkinCMD)
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.ServerAddress)),
), widget.NewFormItem(
"filter", widget.NewEntryWithData(binding.BindString(&c.Filter)),
),
)
},
"capture": func(cc utils.Command) *widget.Form {
c := cc.(*subcommands.CaptureCMD)
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.ServerAddress)),
),
)
},
"chat-log": func(cc utils.Command) *widget.Form {
c := cc.(*subcommands.ChatLogCMD)
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.ServerAddress)),
),
widget.NewFormItem(
"", widget.NewCheckWithData("Verbose", binding.BindBool(&c.Verbose)),
),
)
},
"debug-proxy": func(cc utils.Command) *widget.Form {
c := cc.(*subcommands.DebugProxyCMD)
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.ServerAddress)),
), widget.NewFormItem(
"filter", widget.NewEntryWithData(binding.BindString(&c.Filter)),
),
)
},
}
type GUI struct {
UI
@ -20,7 +81,7 @@ func NewGUI() *GUI {
return &GUI{}
}
func (g *GUI) SetOptions() {
func (g *GUI) SetOptions() bool {
a := app.New()
w := a.NewWindow("Bedrocktool")
@ -41,8 +102,10 @@ func (g *GUI) SetOptions() {
forms := make(map[string]*widget.Form)
for k, c := range utils.ValidCMDs {
entries = append(entries, k)
s := c.SettingsUI()
if s != nil {
f := settings[k]
if f != nil {
s := f(c)
forms[k] = s
}
}
@ -51,15 +114,22 @@ func (g *GUI) SetOptions() {
forms_box := container.NewVBox()
var quit = true
w.SetContent(container.NewVBox(
widget.NewRichTextFromMarkdown("## Settings"),
container.NewHBox(
widget.NewCheckWithData("Debug", debug),
widget.NewCheckWithData("extra-debug", extra_debug),
),
container.NewHBox(
widget.NewRichTextFromMarkdown("Custom Userdata:"),
widget.NewEntryWithData(binding.BindString(&utils.Options.PathCustomUserData)),
),
widget.NewRichTextFromMarkdown("# Commands"),
widget.NewSelect(entries, func(s string) {
g.selected.Set(s)
quit = false
}),
forms_box,
widget.NewButton("Start", func() {
@ -82,6 +152,7 @@ func (g *GUI) SetOptions() {
}))
w.ShowAndRun()
return quit
}
func (g *GUI) Init() {
@ -93,7 +164,6 @@ func (g *GUI) Execute(ctx context.Context) error {
return err
}
cmd := utils.ValidCMDs[sub]
go cmd.MainWindow()
cmd.Execute(ctx, nil)
return nil
}

View File

@ -4,6 +4,6 @@ import "context"
type UI interface {
Init()
SetOptions()
SetOptions() bool
Execute(context.Context) error
}

View File

@ -11,8 +11,6 @@ import (
"sync"
"time"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
"github.com/bedrock-tool/bedrocktool/locale"
"github.com/bedrock-tool/bedrocktool/utils"
@ -46,30 +44,14 @@ func dumpPacket(f io.WriteCloser, toServer bool, payload []byte) {
}
type CaptureCMD struct {
serverAddress string
pathCustomUserData string
ServerAddress string
}
func (*CaptureCMD) Name() string { return "capture" }
func (*CaptureCMD) Synopsis() string { return locale.Loc("capture_synopsis", nil) }
func (c *CaptureCMD) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.serverAddress, "address", "", "remote server address")
f.StringVar(&c.pathCustomUserData, "userdata", "", locale.Loc("custom_user_data", nil))
}
func (c *CaptureCMD) SettingsUI() *widget.Form {
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.serverAddress)),
), widget.NewFormItem(
"pathCustomUserData", widget.NewEntryWithData(binding.BindString(&c.pathCustomUserData)),
),
)
}
func (c *CaptureCMD) MainWindow() error {
return nil
f.StringVar(&c.ServerAddress, "address", "", "remote server address")
}
func (c *CaptureCMD) Usage() string {
@ -77,7 +59,7 @@ func (c *CaptureCMD) Usage() string {
}
func (c *CaptureCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
address, hostname, err := utils.ServerInput(ctx, c.serverAddress)
address, hostname, err := utils.ServerInput(ctx, c.ServerAddress)
if err != nil {
logrus.Fatal(err)
return 1
@ -92,7 +74,7 @@ func (c *CaptureCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interfac
defer fio.Close()
utils.WriteReplayHeader(fio)
proxy, err := utils.NewProxy(c.pathCustomUserData)
proxy, err := utils.NewProxy()
if err != nil {
logrus.Fatal(err)
}

View File

@ -18,28 +18,24 @@ import (
)
type ChatLogCMD struct {
serverAddress string
verbose bool
pathCustomUserData string
ServerAddress string
Verbose bool
}
func (*ChatLogCMD) Name() string { return "chat-log" }
func (*ChatLogCMD) Synopsis() string { return locale.Loc("chat_log_synopsis", nil) }
func (c *ChatLogCMD) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.serverAddress, "address", "", "remote server address")
f.BoolVar(&c.verbose, "v", false, "verbose")
f.StringVar(&c.pathCustomUserData, "userdata", "", locale.Loc("custom_user_data", nil))
f.StringVar(&c.ServerAddress, "address", "", "remote server address")
f.BoolVar(&c.Verbose, "v", false, "verbose")
}
func (c *ChatLogCMD) SettingsUI() *widget.Form {
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.serverAddress)),
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.ServerAddress)),
), widget.NewFormItem(
"verbose", widget.NewCheckWithData("verbose", binding.BindBool(&c.verbose)),
), widget.NewFormItem(
"pathCustomUserData", widget.NewEntryWithData(binding.BindString(&c.pathCustomUserData)),
"", widget.NewCheckWithData("verbose", binding.BindBool(&c.Verbose)),
),
)
}
@ -52,7 +48,7 @@ func (c *ChatLogCMD) Usage() string {
}
func (c *ChatLogCMD) Execute(ctx context.Context, flags *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
address, hostname, err := utils.ServerInput(ctx, c.serverAddress)
address, hostname, err := utils.ServerInput(ctx, c.ServerAddress)
if err != nil {
logrus.Error(err)
return 1
@ -65,14 +61,14 @@ func (c *ChatLogCMD) Execute(ctx context.Context, flags *flag.FlagSet, _ ...inte
}
defer f.Close()
proxy, err := utils.NewProxy(c.pathCustomUserData)
proxy, err := utils.NewProxy()
if err != nil {
logrus.Fatal(err)
}
proxy.PacketCB = func(pk packet.Packet, proxy *utils.ProxyContext, toServer bool, _ time.Time) (packet.Packet, error) {
if text, ok := pk.(*packet.Text); ok {
logLine := text.Message
if c.verbose {
if c.Verbose {
logLine += fmt.Sprintf(" (TextType: %d | XUID: %s | PlatformChatID: %s)", text.TextType, text.XUID, text.PlatformChatID)
}
f.WriteString(fmt.Sprintf("[%s] ", time.Now().Format(time.RFC3339)))

View File

@ -5,8 +5,6 @@ import (
"flag"
"strings"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
"github.com/bedrock-tool/bedrocktool/locale"
"github.com/bedrock-tool/bedrocktool/utils"
@ -15,34 +13,16 @@ import (
)
type DebugProxyCMD struct {
serverAddress string
filter string
pathCustomUserData string
ServerAddress string
Filter string
}
func (*DebugProxyCMD) Name() string { return "debug-proxy" }
func (*DebugProxyCMD) Synopsis() string { return locale.Loc("debug_proxy_synopsis", nil) }
func (c *DebugProxyCMD) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.serverAddress, "address", "", locale.Loc("remote_address", nil))
f.StringVar(&c.filter, "filter", "", locale.Loc("packet_filter", nil))
f.StringVar(&c.pathCustomUserData, "userdata", "", locale.Loc("custom_user_data", nil))
}
func (c *DebugProxyCMD) SettingsUI() *widget.Form {
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.serverAddress)),
), widget.NewFormItem(
"filter", widget.NewEntryWithData(binding.BindString(&c.filter)),
), widget.NewFormItem(
"pathCustomUserData", widget.NewEntryWithData(binding.BindString(&c.pathCustomUserData)),
),
)
}
func (c *DebugProxyCMD) MainWindow() error {
return nil
f.StringVar(&c.ServerAddress, "address", "", locale.Loc("remote_address", nil))
f.StringVar(&c.Filter, "filter", "", locale.Loc("packet_filter", nil))
}
func (c *DebugProxyCMD) Usage() string {
@ -50,7 +30,7 @@ func (c *DebugProxyCMD) Usage() string {
}
func (c *DebugProxyCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
address, _, err := utils.ServerInput(ctx, c.serverAddress)
address, _, err := utils.ServerInput(ctx, c.ServerAddress)
if err != nil {
logrus.Error(err)
return 1
@ -58,7 +38,7 @@ func (c *DebugProxyCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...inter
utils.Options.Debug = true
filters := strings.Split(c.filter, ",")
filters := strings.Split(c.Filter, ",")
if len(filters) > 0 {
for _, v := range filters {
if len(v) == 0 {
@ -73,7 +53,7 @@ func (c *DebugProxyCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...inter
}
}
proxy, err := utils.NewProxy(c.pathCustomUserData)
proxy, err := utils.NewProxy()
if err != nil {
logrus.Error(err)
return 1

View File

@ -7,7 +7,6 @@ import (
"os"
"time"
"fyne.io/fyne/v2/widget"
"github.com/bedrock-tool/bedrocktool/locale"
"github.com/bedrock-tool/bedrocktool/utils"
@ -31,14 +30,6 @@ func (c *MergeCMD) SetFlags(f *flag.FlagSet) {
f.BoolVar(&c.legacy, "legacy", false, "if the worlds are before 1.18")
}
func (c *MergeCMD) SettingsUI() *widget.Form {
return nil // TODO
}
func (c *MergeCMD) MainWindow() error {
return nil
}
func (c *MergeCMD) Usage() string {
return c.Name() + ": " + c.Synopsis() + "\n"
}

View File

@ -1,93 +0,0 @@
package skins
import (
"context"
"flag"
"fmt"
"os"
"time"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
"github.com/bedrock-tool/bedrocktool/locale"
"github.com/bedrock-tool/bedrocktool/utils"
"github.com/google/subcommands"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
"github.com/sirupsen/logrus"
)
type SkinProxyCMD struct {
serverAddress string
filter string
only_with_geometry bool
pathCustomUserData string
}
func (*SkinProxyCMD) Name() string { return "skins-proxy" }
func (*SkinProxyCMD) Synopsis() string { return locale.Loc("skins_proxy_synopsis", nil) }
func (c *SkinProxyCMD) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.serverAddress, "address", "", locale.Loc("remote_address", nil))
f.StringVar(&c.filter, "filter", "", locale.Loc("name_prefix", nil))
f.BoolVar(&c.only_with_geometry, "only-geom", false, locale.Loc("only_with_geometry", nil))
f.StringVar(&c.pathCustomUserData, "userdata", "", locale.Loc("custom_user_data", nil))
}
func (c *SkinProxyCMD) SettingsUI() *widget.Form {
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.serverAddress)),
), widget.NewFormItem(
"filter", widget.NewEntryWithData(binding.BindString(&c.filter)),
), widget.NewFormItem(
"pathCustomUserData", widget.NewEntryWithData(binding.BindString(&c.pathCustomUserData)),
),
)
}
func (c *SkinProxyCMD) MainWindow() error {
return nil
}
func (c *SkinProxyCMD) Usage() string {
return c.Name() + ": " + c.Synopsis() + "\n" + locale.Loc("server_address_help", nil)
}
func (c *SkinProxyCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
address, hostname, err := utils.ServerInput(ctx, c.serverAddress)
if err != nil {
logrus.Error(err)
return 1
}
proxy, err := utils.NewProxy(c.pathCustomUserData)
if err != nil {
logrus.Error(err)
return 1
}
outPathBase := fmt.Sprintf("skins/%s", hostname)
os.MkdirAll(outPathBase, 0o755)
s := NewSkinsSession(proxy, hostname, outPathBase)
s.OnlyIfHasGeometry = c.only_with_geometry
s.PlayerNameFilter = c.filter
proxy.PacketCB = func(pk packet.Packet, proxy *utils.ProxyContext, toServer bool, _ time.Time) (packet.Packet, error) {
if !toServer {
s.ProcessPacket(pk)
}
return pk, nil
}
if err := proxy.Run(ctx, address); err != nil {
logrus.Error(err)
}
return 0
}
func init() {
utils.RegisterCommand(&SkinProxyCMD{})
}

View File

@ -9,8 +9,6 @@ import (
"strings"
"time"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
"github.com/bedrock-tool/bedrocktool/locale"
"github.com/bedrock-tool/bedrocktool/utils"
@ -112,34 +110,18 @@ func (s *skinsSession) ProcessPacket(pk packet.Packet) {
}
type SkinCMD struct {
serverAddress string
filter string
pathCustomUserData string
ServerAddress string
Filter string
NoProxy bool
}
func (*SkinCMD) Name() string { return "skins" }
func (*SkinCMD) Synopsis() string { return locale.Loc("skins_synopsis", nil) }
func (c *SkinCMD) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.serverAddress, "address", "", locale.Loc("remote_address", nil))
f.StringVar(&c.filter, "filter", "", locale.Loc("name_prefix", nil))
f.StringVar(&c.pathCustomUserData, "userdata", "", locale.Loc("custom_user_data", nil))
}
func (c *SkinCMD) SettingsUI() *widget.Form {
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.serverAddress)),
), widget.NewFormItem(
"filter", widget.NewEntryWithData(binding.BindString(&c.filter)),
), widget.NewFormItem(
"pathCustomUserData", widget.NewEntryWithData(binding.BindString(&c.pathCustomUserData)),
),
)
}
func (c *SkinCMD) MainWindow() error {
return nil
f.StringVar(&c.ServerAddress, "address", "", locale.Loc("remote_address", nil))
f.StringVar(&c.Filter, "filter", "", locale.Loc("name_prefix", nil))
f.BoolVar(&c.NoProxy, "no-proxy", false, "use headless version")
}
func (c *SkinCMD) Usage() string {
@ -147,14 +129,14 @@ func (c *SkinCMD) Usage() string {
}
func (c *SkinCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
address, hostname, err := utils.ServerInput(ctx, c.serverAddress)
address, hostname, err := utils.ServerInput(ctx, c.ServerAddress)
if err != nil {
logrus.Error(err)
return 1
}
proxy, _ := utils.NewProxy(c.pathCustomUserData)
proxy.WithClient = false
proxy, _ := utils.NewProxy()
proxy.WithClient = !c.NoProxy
proxy.ConnectCB = func(proxy *utils.ProxyContext, err error) bool {
if err != nil {
return false

View File

@ -5,7 +5,6 @@ import (
"context"
"flag"
"fyne.io/fyne/v2/widget"
"github.com/bedrock-tool/bedrocktool/locale"
"github.com/bedrock-tool/bedrocktool/utils"
"github.com/sirupsen/logrus"
@ -20,14 +19,6 @@ func (*UpdateCMD) Synopsis() string { return locale.Loc("update_synopsis", nil)
func (c *UpdateCMD) SetFlags(f *flag.FlagSet) {}
func (c *UpdateCMD) SettingsUI() *widget.Form {
return nil
}
func (c *UpdateCMD) MainWindow() error {
return nil
}
func (c *UpdateCMD) Usage() string {
return c.Name() + ": " + c.Synopsis() + "\n"
}

View File

@ -16,8 +16,6 @@ import (
"strings"
"time"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
"github.com/bedrock-tool/bedrocktool/locale"
"github.com/bedrock-tool/bedrocktool/utils"
"github.com/bedrock-tool/bedrocktool/utils/behaviourpack"
@ -114,46 +112,22 @@ func init() {
}
type WorldCMD struct {
serverAddress string
packs bool
enableVoid bool
saveImage bool
experimentInventory bool
pathCustomUserData string
ServerAddress string
Packs bool
EnableVoid bool
SaveImage bool
ExperimentInventory bool
}
func (*WorldCMD) Name() string { return "worlds" }
func (*WorldCMD) Synopsis() string { return locale.Loc("world_synopsis", nil) }
func (c *WorldCMD) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.serverAddress, "address", "", locale.Loc("remote_address", nil))
f.BoolVar(&c.packs, "packs", false, locale.Loc("save_packs_with_world", nil))
f.BoolVar(&c.enableVoid, "void", true, locale.Loc("enable_void", nil))
f.BoolVar(&c.saveImage, "image", false, locale.Loc("save_image", nil))
f.BoolVar(&c.experimentInventory, "inv", false, locale.Loc("test_block_inv", nil))
f.StringVar(&c.pathCustomUserData, "userdata", "", locale.Loc("custom_user_data", nil))
}
func (c *WorldCMD) SettingsUI() *widget.Form {
return widget.NewForm(
widget.NewFormItem(
"serverAddress", widget.NewEntryWithData(binding.BindString(&c.serverAddress)),
), widget.NewFormItem(
"packs", widget.NewCheckWithData("packs", binding.BindBool(&c.packs)),
), widget.NewFormItem(
"void", widget.NewCheckWithData("void", binding.BindBool(&c.enableVoid)),
), widget.NewFormItem(
"saveImage", widget.NewCheckWithData("saveImage", binding.BindBool(&c.saveImage)),
), widget.NewFormItem(
"experimentInventory", widget.NewCheckWithData("experimentInventory", binding.BindBool(&c.experimentInventory)),
), widget.NewFormItem(
"pathCustomUserData", widget.NewEntryWithData(binding.BindString(&c.pathCustomUserData)),
),
)
}
func (c *WorldCMD) MainWindow() error {
return nil
f.StringVar(&c.ServerAddress, "address", "", locale.Loc("remote_address", nil))
f.BoolVar(&c.Packs, "packs", false, locale.Loc("save_packs_with_world", nil))
f.BoolVar(&c.EnableVoid, "void", true, locale.Loc("enable_void", nil))
f.BoolVar(&c.SaveImage, "image", false, locale.Loc("save_image", nil))
f.BoolVar(&c.ExperimentInventory, "inv", false, locale.Loc("test_block_inv", nil))
}
func (c *WorldCMD) Usage() string {
@ -161,23 +135,23 @@ func (c *WorldCMD) Usage() string {
}
func (c *WorldCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
serverAddress, hostname, err := utils.ServerInput(ctx, c.serverAddress)
serverAddress, hostname, err := utils.ServerInput(ctx, c.ServerAddress)
if err != nil {
logrus.Error(err)
return 1
}
proxy, err := utils.NewProxy(c.pathCustomUserData)
proxy, err := utils.NewProxy()
if err != nil {
logrus.Error(err)
return 1
}
w := NewWorldState(ctx, proxy, hostname)
w.voidGen = c.enableVoid
w.withPacks = c.packs
w.saveImage = c.saveImage
w.experimentInventory = c.experimentInventory
w.voidGen = c.EnableVoid
w.withPacks = c.Packs
w.saveImage = c.SaveImage
w.experimentInventory = c.ExperimentInventory
proxy.AlwaysGetPacks = true
proxy.ConnectCB = w.OnConnect

View File

@ -1,7 +1,6 @@
package utils
import (
"fyne.io/fyne/v2/widget"
"github.com/google/subcommands"
)
@ -9,8 +8,6 @@ var ValidCMDs = make(map[string]Command, 0)
type Command interface {
subcommands.Command
SettingsUI() *widget.Form
MainWindow() error
}
func RegisterCommand(sub Command) {

View File

@ -67,14 +67,14 @@ type ProxyContext struct {
PacketCB PacketCallback
}
func NewProxy(pathCustomData string) (*ProxyContext, error) {
func NewProxy() (*ProxyContext, error) {
p := &ProxyContext{
commands: make(map[string]IngameCommand),
WithClient: true,
IgnoreDisconnect: false,
}
if pathCustomData != "" {
if err := p.LoadCustomUserData(pathCustomData); err != nil {
if Options.PathCustomUserData != "" {
if err := p.LoadCustomUserData(Options.PathCustomUserData); err != nil {
return nil, err
}
}

View File

@ -63,7 +63,7 @@ func createReplayConnection(ctx context.Context, filename string, onConnect Conn
f.Seek(-4, io.SeekCurrent)
}
proxy, _ := NewProxy("")
proxy, _ := NewProxy()
proxy.Server = minecraft.NewConn()
gameStarted := false

Binary file not shown.

View File

@ -27,11 +27,12 @@ import (
)
var Options struct {
Debug bool
Preload bool
IsInteractive bool
ExtraDebug bool
EnableDNS bool
Debug bool
Preload bool
IsInteractive bool
ExtraDebug bool
EnableDNS bool
PathCustomUserData string
}
var nameRegexp = regexp.MustCompile(`\||(?:§.?)`)