add -capture for all commands

This commit is contained in:
olebeck 2023-04-21 00:55:52 +02:00
parent 5149487c18
commit 63b94197ec
5 changed files with 12 additions and 5 deletions

View File

@ -99,11 +99,11 @@ func main() {
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))
flag.BoolVar(&utils.Options.Capture, "capture", false, "Capture Packet log")
subcommands.Register(subcommands.HelpCommand(), "")
subcommands.ImportantFlag("debug")
subcommands.ImportantFlag("dns")
subcommands.ImportantFlag("capture")
subcommands.ImportantFlag("preload")
subcommands.HelpCommand()

View File

@ -65,3 +65,7 @@ func NewPacketCapturer() *utils.ProxyHandler {
},
}
}
func init() {
utils.NewPacketCapturer = NewPacketCapturer
}

View File

@ -4,7 +4,6 @@ import (
"context"
"flag"
"github.com/bedrock-tool/bedrocktool/handlers"
"github.com/bedrock-tool/bedrocktool/locale"
"github.com/bedrock-tool/bedrocktool/utils"
)
@ -34,6 +33,6 @@ func (c *CaptureCMD) Execute(ctx context.Context, ui utils.UI) error {
return err
}
proxy.AlwaysGetPacks = true
proxy.AddHandler(handlers.NewPacketCapturer())
utils.Options.Capture = true
return proxy.Run(ctx, address, hostname)
}

View File

@ -282,6 +282,7 @@ func (p *ProxyContext) IsClient(addr net.Addr) bool {
}
var NewDebugLogger func(bool) *ProxyHandler
var NewPacketCapturer func() *ProxyHandler
func (p *ProxyContext) connectClient(ctx context.Context, serverAddress string, cdpp **login.ClientData) (err error) {
GetTokenSource() // ask for login before listening
@ -337,6 +338,9 @@ func (p *ProxyContext) Run(ctx context.Context, serverAddress, name string) (err
if Options.Debug || Options.ExtraDebug {
p.AddHandler(NewDebugLogger(Options.ExtraDebug))
}
if Options.Capture {
p.AddHandler(NewPacketCapturer())
}
p.AddHandler(&ProxyHandler{
Name: "Commands",
PacketCB: p.CommandHandlerPacketCB,

View File

@ -30,7 +30,7 @@ var Options struct {
Preload bool
IsInteractive bool
ExtraDebug bool
EnableDNS bool
Capture bool
PathCustomUserData string
}