diff --git a/capture.go b/capture.go index 424286c..5db58a4 100644 --- a/capture.go +++ b/capture.go @@ -85,7 +85,7 @@ func (p *CaptureCMD) SetFlags(f *flag.FlagSet) { f.StringVar(&p.server_address, "address", "", "remote server address") } func (c *CaptureCMD) Usage() string { - return c.Name() + ": " + c.Synopsis() + "\n" + return c.Name() + ": " + c.Synopsis() + "\n" + SERVER_ADDRESS_HELP } func (c *CaptureCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { diff --git a/main.go b/main.go index 96ed6d3..ba27b93 100644 --- a/main.go +++ b/main.go @@ -108,6 +108,7 @@ func main() { subcommands.Register(subcommands.HelpCommand(), "") subcommands.ImportantFlag("debug") subcommands.ImportantFlag("dns") + subcommands.HelpCommand() { // interactive input if len(os.Args) < 2 { diff --git a/realms.go b/realms.go index be54718..9477af9 100644 --- a/realms.go +++ b/realms.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "os" "strings" "github.com/google/subcommands" @@ -35,7 +36,7 @@ func realms_get(path string) ([]byte, error) { } defer resp.Body.Close() if resp.StatusCode != 200 { - return nil, fmt.Errorf("%d", resp.StatusCode) + return nil, fmt.Errorf("HTTP %d", resp.StatusCode) } data, err := io.ReadAll(resp.Body) if err != nil { @@ -82,7 +83,7 @@ func get_realms() ([]Realm, error) { return realms.Servers, nil } -func get_realm(realm_name string) (string, string, error) { +func get_realm(realm_name, id string) (string, string, error) { // returns: name, address, err realms, err := get_realms() if err != nil { @@ -90,6 +91,9 @@ func get_realm(realm_name string) (string, string, error) { } for _, realm := range realms { if strings.HasPrefix(realm.Name, realm_name) { + if id != "" && id != fmt.Sprint(id) { + continue + } address, err := realm.Address() if err != nil { return "", "", err @@ -100,17 +104,6 @@ func get_realm(realm_name string) (string, string, error) { return "", "", fmt.Errorf("realm not found") } -func list_realms() error { - realms, err := get_realms() - if err != nil { - return err - } - for _, realm := range realms { - fmt.Printf("%s\t\t(%d)\n", realm.Name, realm.Id) - } - return nil -} - type TokenCMD struct{} func (*TokenCMD) Name() string { return "realms-token" } @@ -126,6 +119,29 @@ func (c *TokenCMD) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) return 0 } +type RealmListCMD struct{} + +func (*RealmListCMD) Name() string { return "list-realms" } +func (*RealmListCMD) Synopsis() string { return "prints all realms you have access to" } + +func (c *RealmListCMD) SetFlags(f *flag.FlagSet) {} +func (c *RealmListCMD) Usage() string { + return c.Name() + ": " + c.Synopsis() + "\n" +} + +func (c *RealmListCMD) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { + realms, err := get_realms() + if err != nil { + fmt.Fprintln(os.Stderr, err) + return 1 + } + for _, realm := range realms { + fmt.Printf("Name: %s\tid: %d\n", realm.Name, realm.Id) + } + return 0 +} + func init() { register_command(&TokenCMD{}) + register_command(&RealmListCMD{}) } diff --git a/resourcepack-ace.go b/resourcepack-ace.go index fd1d03b..7aad3ef 100644 Binary files a/resourcepack-ace.go and b/resourcepack-ace.go differ diff --git a/skins-proxy.go b/skins-proxy.go index 97d4819..8d4bcc0 100644 --- a/skins-proxy.go +++ b/skins-proxy.go @@ -24,7 +24,7 @@ func (c *SkinProxyCMD) SetFlags(f *flag.FlagSet) { f.StringVar(&c.filter, "filter", "", "player name filter prefix") } func (c *SkinProxyCMD) Usage() string { - return c.Name() + ": " + c.Synopsis() + "\n" + return c.Name() + ": " + c.Synopsis() + "\n" + SERVER_ADDRESS_HELP } func (c *SkinProxyCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { diff --git a/utils.go b/utils.go index a1feaef..9b4a25d 100644 --- a/utils.go +++ b/utils.go @@ -19,6 +19,14 @@ import ( "golang.org/x/oauth2" ) +const SERVER_ADDRESS_HELP = `accepted server address formats: + 123.234.123.234 + 123.234.123.234:19132 + realm:Username + realm:Username:Id + +` + func send_popup(conn *minecraft.Conn, text string) { conn.WritePacket(&packet.Text{ TextType: packet.TextTypePopup, @@ -62,10 +70,19 @@ func server_input(server string) (address, name string, err error) { } if strings.HasPrefix(server, "realm:") { // for realms use api to get ip address - name, address, err = get_realm(strings.Split(server, ":")[1]) + realm_info := strings.Split(server, ":") + id := "" + if len(realm_info) == 3 { + id = realm_info[2] + } + name, address, err = get_realm(realm_info[1], id) if err != nil { return "", "", err } + } else if strings.HasSuffix(server, ".pcap") { + s := strings.Split(server, ".") + name = strings.Join(s[:len(s)-1], ".") + address = server } else { // if an actual server address if given // add port if necessary @@ -135,12 +152,6 @@ func spawn_conn(ctx context.Context, clientConn *minecraft.Conn, serverConn *min } func create_proxy(ctx context.Context, server_address string) (l *minecraft.Listener, clientConn, serverConn *minecraft.Conn, err error) { - /* - if strings.HasSuffix(server_address, ".pcap") { - return create_replay_connection(server_address) - } - */ - _status := minecraft.NewStatusProvider("Server") listener, err := minecraft.ListenConfig{ StatusProvider: _status, @@ -170,9 +181,9 @@ func create_proxy(ctx context.Context, server_address string) (l *minecraft.List G_exit = append(G_exit, func() { serverConn.Close() - listener.Disconnect(clientConn, "Closing") + l.Disconnect(clientConn, "Closing") clientConn.Close() - listener.Close() + l.Close() }) return l, clientConn, serverConn, nil diff --git a/world.go b/world.go index 82a7f5f..9b7d0c6 100644 --- a/world.go +++ b/world.go @@ -102,7 +102,7 @@ func (p *WorldCMD) SetFlags(f *flag.FlagSet) { f.StringVar(&p.server_address, "address", "", "remote server address") } func (c *WorldCMD) Usage() string { - return c.Name() + ": " + c.Synopsis() + "\n" + return c.Name() + ": " + c.Synopsis() + "\n" + SERVER_ADDRESS_HELP } func (c *WorldCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {