bedrocktool/subcommands/skins/skins.go

66 lines
1.6 KiB
Go
Raw Normal View History

2022-09-04 14:26:32 +00:00
package skins
2022-03-05 11:59:36 +00:00
import (
"context"
"flag"
"github.com/bedrock-tool/bedrocktool/locale"
2023-03-18 11:12:54 +00:00
"github.com/bedrock-tool/bedrocktool/ui/messages"
2022-09-04 14:53:21 +00:00
"github.com/bedrock-tool/bedrocktool/utils"
2023-04-02 14:49:24 +00:00
"github.com/bedrock-tool/bedrocktool/utils/handlers"
2022-09-04 14:26:32 +00:00
2023-04-02 14:49:24 +00:00
"github.com/sandertv/gophertunnel/minecraft"
2022-03-05 11:59:36 +00:00
)
2023-02-08 18:08:26 +00:00
type skinsSession struct {
2022-03-18 18:22:31 +00:00
}
type SkinCMD struct {
2023-03-06 01:03:31 +00:00
ServerAddress string
Filter string
NoProxy bool
}
2022-07-29 16:12:06 +00:00
func (*SkinCMD) Name() string { return "skins" }
func (*SkinCMD) Synopsis() string { return locale.Loc("skins_synopsis", nil) }
2022-07-29 16:12:06 +00:00
func (c *SkinCMD) SetFlags(f *flag.FlagSet) {
2023-03-06 01:03:31 +00:00
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")
2023-03-05 21:50:58 +00:00
}
func (c *SkinCMD) Execute(ctx context.Context, ui utils.UI) error {
2023-03-06 01:03:31 +00:00
address, hostname, err := utils.ServerInput(ctx, c.ServerAddress)
2022-08-13 14:30:46 +00:00
if err != nil {
return err
2022-08-13 14:30:46 +00:00
}
2023-03-06 01:03:31 +00:00
proxy, _ := utils.NewProxy()
proxy.WithClient = !c.NoProxy
2023-04-02 14:49:24 +00:00
proxy.AddHandler(handlers.NewSkinSaver(func(sa handlers.SkinAdd) {
ui.Message(messages.NewSkin{
PlayerName: sa.PlayerName,
Skin: sa.Skin,
})
}))
proxy.AddHandler(&utils.ProxyHandler{
Name: "Skin CMD",
OnClientConnect: func(conn *minecraft.Conn) {
ui.Message(messages.SetUIState(messages.UIStateConnecting))
},
})
2023-03-18 11:12:54 +00:00
if proxy.WithClient {
2023-04-01 22:22:50 +00:00
ui.Message(messages.SetUIState(messages.UIStateConnect))
2023-03-18 11:12:54 +00:00
} else {
2023-04-01 22:22:50 +00:00
ui.Message(messages.SetUIState(messages.UIStateConnecting))
2023-03-18 11:12:54 +00:00
}
2023-04-02 14:49:24 +00:00
err = proxy.Run(ctx, address, hostname)
return err
2022-03-05 11:59:36 +00:00
}
func init() {
2022-09-04 14:26:32 +00:00
utils.RegisterCommand(&SkinCMD{})
}