2022-02-12 22:27:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2022-03-08 22:06:19 +00:00
|
|
|
"context"
|
2022-02-12 22:27:49 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2022-03-08 22:06:19 +00:00
|
|
|
"os/signal"
|
2022-02-27 10:08:19 +00:00
|
|
|
"regexp"
|
2022-03-08 22:06:19 +00:00
|
|
|
"syscall"
|
2022-02-12 22:27:49 +00:00
|
|
|
|
2022-09-04 14:53:21 +00:00
|
|
|
"github.com/bedrock-tool/bedrocktool/utils"
|
|
|
|
|
|
|
|
_ "github.com/bedrock-tool/bedrocktool/subcommands"
|
|
|
|
_ "github.com/bedrock-tool/bedrocktool/subcommands/skins"
|
|
|
|
_ "github.com/bedrock-tool/bedrocktool/subcommands/world"
|
2022-09-04 14:26:32 +00:00
|
|
|
|
2022-08-14 20:55:52 +00:00
|
|
|
"github.com/google/subcommands"
|
2022-09-04 00:24:58 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2022-02-12 22:27:49 +00:00
|
|
|
)
|
|
|
|
|
2022-08-13 13:22:41 +00:00
|
|
|
func exit() {
|
2022-09-04 00:24:58 +00:00
|
|
|
logrus.Info("\nExiting\n")
|
2022-09-04 14:26:32 +00:00
|
|
|
for i := len(utils.G_exit) - 1; i >= 0; i-- { // go through cleanup functions reversed
|
|
|
|
utils.G_exit[i]()
|
2022-08-13 13:22:41 +00:00
|
|
|
}
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2022-02-27 10:08:19 +00:00
|
|
|
func main() {
|
2022-09-04 00:24:58 +00:00
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
2022-09-05 21:57:11 +00:00
|
|
|
if utils.Version != "" {
|
|
|
|
logrus.Infof("bedrocktool version: %s", utils.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
newVersion, err := utils.Updater.UpdateAvailable()
|
|
|
|
if err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == nil && newVersion != utils.Version {
|
|
|
|
logrus.Infof("Update Available: %s", newVersion)
|
2022-09-04 00:24:58 +00:00
|
|
|
}
|
2022-08-21 16:28:39 +00:00
|
|
|
|
2022-08-14 20:55:52 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
2022-09-04 14:26:32 +00:00
|
|
|
flag.BoolVar(&utils.G_debug, "debug", false, "debug mode")
|
|
|
|
flag.BoolVar(&utils.G_preload_packs, "preload", false, "preload resourcepacks for proxy")
|
2022-08-14 20:55:52 +00:00
|
|
|
enable_dns := flag.Bool("dns", false, "enable dns server for consoles")
|
2022-09-05 21:57:11 +00:00
|
|
|
|
2022-08-14 20:55:52 +00:00
|
|
|
subcommands.Register(subcommands.HelpCommand(), "")
|
|
|
|
subcommands.ImportantFlag("debug")
|
|
|
|
subcommands.ImportantFlag("dns")
|
2022-08-15 21:36:06 +00:00
|
|
|
subcommands.ImportantFlag("preload")
|
2022-08-15 00:29:01 +00:00
|
|
|
subcommands.HelpCommand()
|
2022-08-14 20:55:52 +00:00
|
|
|
|
|
|
|
{ // interactive input
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
fmt.Println("Available commands:")
|
2022-09-04 14:26:32 +00:00
|
|
|
for name, desc := range utils.ValidCMDs {
|
2022-08-14 20:55:52 +00:00
|
|
|
fmt.Printf("\t%s\t%s\n", name, desc)
|
|
|
|
}
|
|
|
|
fmt.Printf("Use '%s <command>' to run a command\n", os.Args[0])
|
|
|
|
|
|
|
|
fmt.Printf("Input Command: ")
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
target, _ := reader.ReadString('\n')
|
|
|
|
r, _ := regexp.Compile(`[\n\r]`)
|
|
|
|
target = string(r.ReplaceAll([]byte(target), []byte("")))
|
|
|
|
os.Args = append(os.Args, target)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-08 22:06:19 +00:00
|
|
|
|
2022-08-14 20:55:52 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *enable_dns {
|
2022-09-04 14:26:32 +00:00
|
|
|
utils.InitDNS()
|
2022-08-14 20:55:52 +00:00
|
|
|
}
|
2022-03-08 22:06:19 +00:00
|
|
|
|
2022-08-11 20:22:39 +00:00
|
|
|
// exit cleanup
|
2022-03-08 22:06:19 +00:00
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
go func() {
|
|
|
|
<-sigs
|
|
|
|
cancel()
|
2022-08-13 13:22:41 +00:00
|
|
|
exit()
|
2022-03-08 22:06:19 +00:00
|
|
|
}()
|
2022-02-20 11:39:02 +00:00
|
|
|
|
2022-08-14 20:55:52 +00:00
|
|
|
ret := subcommands.Execute(ctx)
|
2022-08-13 13:22:41 +00:00
|
|
|
exit()
|
2022-08-14 20:55:52 +00:00
|
|
|
os.Exit(int(ret))
|
2022-07-29 16:12:06 +00:00
|
|
|
}
|
2022-08-15 13:29:09 +00:00
|
|
|
|
2022-08-23 20:56:52 +00:00
|
|
|
type TransCMD struct {
|
|
|
|
auth bool
|
|
|
|
}
|
2022-08-15 13:29:09 +00:00
|
|
|
|
|
|
|
func (*TransCMD) Name() string { return "trans" }
|
|
|
|
func (*TransCMD) Synopsis() string { return "" }
|
|
|
|
|
2022-08-23 20:56:52 +00:00
|
|
|
func (c *TransCMD) SetFlags(f *flag.FlagSet) {
|
|
|
|
f.BoolVar(&c.auth, "auth", false, "if it should login to xbox")
|
|
|
|
}
|
2022-09-04 13:24:55 +00:00
|
|
|
|
2022-08-15 13:29:09 +00:00
|
|
|
func (c *TransCMD) Usage() string {
|
|
|
|
return c.Name() + ": " + c.Synopsis() + "\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *TransCMD) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
|
|
|
|
const (
|
|
|
|
BLACK_FG = "\033[30m"
|
|
|
|
BOLD = "\033[1m"
|
|
|
|
BLUE = "\033[46m"
|
|
|
|
PINK = "\033[45m"
|
|
|
|
WHITE = "\033[47m"
|
|
|
|
RESET = "\033[0m"
|
|
|
|
)
|
2022-08-23 20:56:52 +00:00
|
|
|
if c.auth {
|
2022-09-04 14:26:32 +00:00
|
|
|
utils.GetTokenSource()
|
2022-08-23 20:56:52 +00:00
|
|
|
}
|
2022-08-15 13:29:09 +00:00
|
|
|
fmt.Println(BLACK_FG + BOLD + BLUE + " Trans " + PINK + " Rights " + WHITE + " Are " + PINK + " Human " + BLUE + " Rights " + RESET)
|
|
|
|
return 0
|
|
|
|
}
|
2022-09-04 13:24:55 +00:00
|
|
|
|
2022-08-15 13:29:09 +00:00
|
|
|
func init() {
|
2022-09-04 14:26:32 +00:00
|
|
|
utils.RegisterCommand(&TransCMD{})
|
2022-08-15 13:29:09 +00:00
|
|
|
}
|