Skip to content

Commit

Permalink
add client-cache option
Browse files Browse the repository at this point in the history
  • Loading branch information
olebeck committed Dec 14, 2024
1 parent fd43e29 commit 61c96f6
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 38 deletions.
6 changes: 4 additions & 2 deletions subcommands/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import (
)

type CaptureCMD struct {
ServerAddress string
ServerAddress string
EnableClientCache bool
}

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.BoolVar(&c.EnableClientCache, "client-cache", true, "Enable Client Cache")
}

func (c *CaptureCMD) Execute(ctx context.Context) error {
p, err := proxy.New(true)
p, err := proxy.New(true, c.EnableClientCache)
if err != nil {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions subcommands/chat_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ import (
)

type ChatLogCMD struct {
ServerAddress string
Verbose bool
ServerAddress string
Verbose bool
EnableClientCache 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.BoolVar(&c.EnableClientCache, "client-cache", true, "Enable Client Cache")
}

func (c *ChatLogCMD) Execute(ctx context.Context) error {
proxyContext, err := proxy.New(true)
proxyContext, err := proxy.New(true, c.EnableClientCache)
if err != nil {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions subcommands/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import (
)

type DebugProxyCMD struct {
ServerAddress string
ListenAddress string
ServerAddress string
ListenAddress string
EnableClientCache bool
}

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.ListenAddress, "listen", "0.0.0.0:19132", "example :19132 or 127.0.0.1:19132")
f.BoolVar(&c.EnableClientCache, "client-cache", true, "Enable Client Cache")
}

func (c *DebugProxyCMD) Execute(ctx context.Context) error {
proxyContext, err := proxy.New(true)
proxyContext, err := proxy.New(true, c.EnableClientCache)
if err != nil {
return err
}
Expand Down
14 changes: 8 additions & 6 deletions subcommands/resourcepack-d.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
)

type ResourcePackCMD struct {
ServerAddress string
SaveEncrypted bool
OnlyKeys bool
writeFolders bool
f *flag.FlagSet
ServerAddress string
SaveEncrypted bool
OnlyKeys bool
writeFolders bool
EnableClientCache bool
f *flag.FlagSet
}

func (*ResourcePackCMD) Name() string { return "packs" }
Expand All @@ -27,11 +28,12 @@ func (c *ResourcePackCMD) SetFlags(f *flag.FlagSet) {
f.BoolVar(&c.SaveEncrypted, "save-encrypted", false, locale.Loc("save_encrypted", nil))
f.BoolVar(&c.OnlyKeys, "only-keys", false, locale.Loc("only_keys", nil))
f.BoolVar(&c.writeFolders, "folders", false, "folders instead of zips")
f.BoolVar(&c.EnableClientCache, "client-cache", true, "Enable Client Cache")
c.f = f
}

func (c *ResourcePackCMD) Execute(ctx context.Context) error {
return resourcepackd.Execute_cmd(ctx, c.ServerAddress, c.OnlyKeys, c.SaveEncrypted, c.writeFolders, c.f)
return resourcepackd.Execute_cmd(ctx, c.ServerAddress, c.OnlyKeys, c.SaveEncrypted, c.writeFolders, c.EnableClientCache, c.f)
}

func init() {
Expand Down
Binary file modified subcommands/resourcepack-d/resourcepack-d.go
Binary file not shown.
12 changes: 7 additions & 5 deletions subcommands/skins/skins.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
)

type SkinCMD struct {
ServerAddress string
ListenAddress string
Filter string
NoProxy bool
ServerAddress string
ListenAddress string
Filter string
NoProxy bool
EnableClientCache bool
}

func (*SkinCMD) Name() string { return "skins" }
Expand All @@ -27,10 +28,11 @@ func (c *SkinCMD) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.ListenAddress, "listen", "0.0.0.0:19132", "example :19132 or 127.0.0.1:19132")
f.StringVar(&c.Filter, "filter", "", locale.Loc("name_prefix", nil))
f.BoolVar(&c.NoProxy, "no-proxy", false, "use headless version")
f.BoolVar(&c.EnableClientCache, "client-cache", true, "Enable Client Cache")
}

func (c *SkinCMD) Execute(ctx context.Context) error {
p, err := proxy.New(!c.NoProxy)
p, err := proxy.New(!c.NoProxy, c.EnableClientCache)
if err != nil {
return err
}
Expand Down
28 changes: 15 additions & 13 deletions subcommands/world/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ import (
)

type WorldCMD struct {
ServerAddress string
ListenAddress string
EnableVoid bool
SaveEntities bool
SaveInventories bool
SaveImage bool
BlockUpdates bool
ExcludeMobs string
StartPaused bool
PreloadReplay string
ChunkRadius int
ScriptPath string
ServerAddress string
ListenAddress string
EnableVoid bool
SaveEntities bool
SaveInventories bool
SaveImage bool
BlockUpdates bool
ExcludeMobs string
StartPaused bool
PreloadReplay string
ChunkRadius int
ScriptPath string
EnableClientCache bool
}

func (*WorldCMD) Name() string { return "worlds" }
Expand All @@ -44,6 +45,7 @@ func (c *WorldCMD) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.PreloadReplay, "preload-replay", "", "preload from a replay")
f.IntVar(&c.ChunkRadius, "chunk-radius", 0, "the max chunk radius to force")
f.StringVar(&c.ScriptPath, "script", "", "path to script to use")
f.BoolVar(&c.EnableClientCache, "client-cache", true, "Enable Client Cache")
}

func (c *WorldCMD) Execute(ctx context.Context) error {
Expand All @@ -56,7 +58,7 @@ func (c *WorldCMD) Execute(ctx context.Context) error {
script = string(data)
}

proxy, err := proxy.New(true)
proxy, err := proxy.New(true, c.EnableClientCache)
if err != nil {
return err
}
Expand Down
12 changes: 7 additions & 5 deletions utils/proxy/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ func (e *errTransfer) Error() string {
}

type Context struct {
ExtraDebug bool
PlayerMoveCB []func()
ListenAddress string
withClient bool
ExtraDebug bool
PlayerMoveCB []func()
ListenAddress string
withClient bool
EnableClientCache bool

addedPacks []resource.Pack
handlers Handlers
Expand All @@ -40,7 +41,7 @@ type Context struct {
}

// New creates a new proxy context
func New(withClient bool) (*Context, error) {
func New(withClient, EnableClientCache bool) (*Context, error) {
p := &Context{
withClient: withClient,
ListenAddress: "0.0.0.0:19132",
Expand Down Expand Up @@ -80,6 +81,7 @@ func (p *Context) connect(ctx context.Context, connect *utils.ConnectInfo) (err
p.session.listenAddress = p.ListenAddress
p.session.handlers = p.handlers
p.session.OnHitBlobs = p.onHitBlobs
p.session.EnableClientCache = p.EnableClientCache

p.handlers.SessionStart(p.session, connect.Name())
err = p.session.Run(ctx, connect)
Expand Down
4 changes: 3 additions & 1 deletion utils/proxy/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type Session struct {
listenAddress string
handlers Handlers
OnHitBlobs func(hitBlobs []protocol.CacheBlob)

EnableClientCache bool
}

func NewSession() *Session {
Expand Down Expand Up @@ -360,7 +362,7 @@ func (s *Session) connectServer(ctx context.Context, connect *utils.ConnectInfo)
TokenSource: utils.Auth,
ErrorLog: slog.Default(),
PacketFunc: s.packetFunc,
EnableClientCache: true,
EnableClientCache: s.EnableClientCache,
GetClientData: func() login.ClientData {
if s.withClient {
select {
Expand Down

2 comments on commit 61c96f6

@PoopyHaters
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it take long to steal worlds?

@PoopyHaters
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and why cant i steal command block nbts

Please sign in to comment.