From a7f55ec2dce684eba0504072f4f935c566fce220 Mon Sep 17 00:00:00 2001 From: olebeck <31539311+olebeck@users.noreply.github.com> Date: Mon, 22 Jul 2024 02:10:32 +0200 Subject: [PATCH] a bit of cleanup --- cmd/bedrocktool/main.go | 12 + cmd/entity-test/main.go | 102 -------- gophertunnel | 2 +- handlers/worlds/world.go | 9 +- subcommands/realms-list.go | 2 +- subcommands/resourcepack-d/resourcepack-d.go | Bin 9889 -> 9681 bytes ui/gui/popups/realmsinput.go | 2 +- utils/auth.go | 253 +++++++++++++------ utils/fswriter.go | 15 +- utils/input.go | 2 +- utils/proxy/resourcepacks.go | 63 ++++- utils/proxy/session.go | 2 +- utils/zip.go | 50 ---- 13 files changed, 262 insertions(+), 252 deletions(-) delete mode 100644 cmd/entity-test/main.go diff --git a/cmd/bedrocktool/main.go b/cmd/bedrocktool/main.go index 7452750..bf0d9a5 100644 --- a/cmd/bedrocktool/main.go +++ b/cmd/bedrocktool/main.go @@ -7,6 +7,7 @@ import ( "flag" "fmt" "io" + "net/http" "os" "os/signal" "runtime/pprof" @@ -68,6 +69,15 @@ func setupLogging(isDebug bool) { })) } +type logTransport struct { + rt http.RoundTripper +} + +func (t *logTransport) RoundTrip(req *http.Request) (*http.Response, error) { + logrus.Tracef("Request %s", req.URL.String()) + return t.rt.RoundTrip(req) +} + func main() { isDebug := updater.Version == "" @@ -80,6 +90,8 @@ func main() { } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() + + http.DefaultTransport = &logTransport{rt: http.DefaultTransport} } log := logrus.WithField("part", "main") diff --git a/cmd/entity-test/main.go b/cmd/entity-test/main.go deleted file mode 100644 index 3ed5cb9..0000000 --- a/cmd/entity-test/main.go +++ /dev/null @@ -1,102 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/bedrock-tool/bedrocktool/utils" - "github.com/df-mc/dragonfly/server/block/cube" - "github.com/df-mc/dragonfly/server/world" - "github.com/df-mc/dragonfly/server/world/mcdb" - "github.com/go-gl/mathgl/mgl64" - "github.com/sirupsen/logrus" -) - -type entityReg struct{} - -func (r *entityReg) Config() world.EntityRegistryConfig { - return world.EntityRegistryConfig{} -} -func (r *entityReg) Lookup(name string) (world.EntityType, bool) { - return &serverEntityType{Encoded: name}, true -} -func (r *entityReg) Types() []world.EntityType { - return []world.EntityType{nil} -} - -type serverEntityType struct { - Encoded string -} - -func (t serverEntityType) EncodeEntity() string { - return t.Encoded -} - -func (t serverEntityType) BBox(e world.Entity) cube.BBox { - return cube.Box(-0.5, 0, -0.5, 0.5, 1, 0.5) -} - -func (t serverEntityType) DecodeNBT(m map[string]any) world.Entity { - return &serverEntity{ - EntityType: t, - NBT: m, - } -} - -func (t serverEntityType) EncodeNBT(e world.Entity) map[string]any { - se := e.(*serverEntity) - return se.NBT -} - -var _ world.SaveableEntityType = &serverEntityType{} - -type serverEntity struct { - EntityType serverEntityType - NBT map[string]any -} - -func (e serverEntity) Type() world.EntityType { - return e.EntityType -} - -func (e serverEntity) Position() mgl64.Vec3 { - return mgl64.Vec3{} -} -func (e serverEntity) Rotation() cube.Rotation { - return cube.Rotation{} -} - -func (e serverEntity) World() *world.World { - return nil -} - -func (e serverEntity) Close() error { - return nil -} - -func main() { - world, err := mcdb.Config{ - Entities: &entityReg{}, - ReadOnly: true, - }.Open(os.Args[1]) - if err != nil { - logrus.Fatal(err) - } - - it := world.NewColumnIterator(nil, false) - defer it.Release() - for it.Next() { - c := it.Column() - if err = it.Error(); err != nil { - logrus.Fatal(err) - } - - for _, e := range c.Entities { - se := e.(*serverEntity) - fmt.Printf("%s\n", e.Type().EncodeEntity()) - utils.DumpStruct(os.Stdout, se.NBT) - fmt.Print("\n\n") - } - } - -} diff --git a/gophertunnel b/gophertunnel index b3db337..3c67f15 160000 --- a/gophertunnel +++ b/gophertunnel @@ -1 +1 @@ -Subproject commit b3db337515e6d1bbf4a8c2b8cbc02dad3f770e4b +Subproject commit 3c67f15e0913bc5b1873090766582b7a5900db30 diff --git a/handlers/worlds/world.go b/handlers/worlds/world.go index 01c8c13..9653fde 100644 --- a/handlers/worlds/world.go +++ b/handlers/worlds/world.go @@ -443,15 +443,16 @@ func (w *worldsHandler) saveWorldState(worldState *worldstate.World) error { } defer f.Close() zw := zip.NewWriter(f) + utils.ZipCompressPool(zw) err = zw.AddFS(os.DirFS(worldState.Folder)) if err != nil { return err } - zfs := &utils.ZipWriter{Writer: zw} - ofs := &utils.OSWriter{Base: worldState.Folder} - mfs := &utils.MultiWriterFS{FSs: []utils.WriterFS{zfs, ofs}} - err = w.AddPacks(worldState.Name, mfs) + err = w.AddPacks(worldState.Name, utils.MultiWriterFS{FSs: []utils.WriterFS{ + utils.ZipWriter{Writer: zw}, + utils.OSWriter{Base: worldState.Folder}, + }}) if err != nil { return err } diff --git a/subcommands/realms-list.go b/subcommands/realms-list.go index 4c6dfdf..a08f0de 100644 --- a/subcommands/realms-list.go +++ b/subcommands/realms-list.go @@ -22,7 +22,7 @@ func (c *RealmListCMD) Execute(ctx context.Context) error { return err } } - realms, err := utils.Auth.Realms.Realms(ctx) + realms, err := utils.Auth.Realms().Realms(ctx) if err != nil { return err } diff --git a/subcommands/resourcepack-d/resourcepack-d.go b/subcommands/resourcepack-d/resourcepack-d.go index 69d1134bd7c14c96f0e6451cff42f4afa842fc06..2f41c4712fa8da833c6ede8d9d47b57e0aab8fb0 100644 GIT binary patch literal 9681 zcmV;?B`(?kM@dveQdv+`07ydaI=7~ZoBXYo>GL48w8kK5q8a@#sV0OOfmV9$u#|Cc zIKoOFzG9KvZKh#lyVQD{*Qtmjn(pVBWbhWT(q&Vu%x&^ANb}xK20u73ceX9N*{VE^ z78rAsR)=L+uWTZK`RBgQP$l-h3gRxhl-QUAKRobHDbaJD zPBKqSr8&wHOg|08rLb)cvLkOuCr?EP+GcA zp~T^_8pw*5eJZn-{yf=|R0jkt$k?I(9LxkFh2RHQQ8xV6nFXj-12B(|KmU+ohJMq= z$}2zsgc(6%3uUi~Ijp78xApSfG0tIOoA_+xkjn%+mJq_Rob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}f4zyzlIRjZL=S+IiAevZgmfBG> zQus@I=w174UP{FrS~9-lw?e9A)ZmVvfK8pKoa+h|6_e|g%QQa{MN(wD*_9xL4X}gN zp+!LGU-tWLTxx&v4k%zH(0{=zKXw89M7faNt<@imbGjB0A!l_A_87qm6InU8iA2Iw zi|2B)Da7MtyrL8i{?aJ>UZ;`#yBWS@U{U1|lQz*K?+cRjiRiCS&b^a7-2b-*99gsS zl-W}Q3(>p?z?Q*CzBQiWn3%~We*@#!CQr+6YqSsI%CCUZ{hDC#n|C`Z&$Ph#s+I9J z+1<7|n?^h1xL)_9w_Db_Au%piRz5YJ)|VP7|gRJ_GJ5_lI}4gR8mHb_V*zBv+EgoK8wgQrqe0oE=k zJBCdP1t~e#el3ws=E`rUiTbZ`ebnk>OU}h#C?zeUE*8)JI2Vg3)w!BdV8LbfaK0HqZIUsReWc$@aRFY4HAnF{U74hG_E5lkNU zIu6q~CIX5*}ie0&&Ri9bLfY1dBnP{h>k)L@V zP#m$jd*fxwMEw)j9e-Nf*FKaw`mqckiMptMq@WSKYNYrClo=6!Nd=o>p z)Urdx>Ts`okcRY3-+8tJxdj)_%gDUI?RteMP`&%;-933vOQ-uZL~eIPHccYW3wp}w zEu@}H*USyCQ(A>VHJO9Yun<7+uP$64L{{H3uZA)M&Tm1pnL>#`FK^F+RJ1Y@jk= int(pack.size) - if !lastData && uint32(len(frag.Data)) != pack.chunkSize { - // The chunk data didn't have the full size and wasn't the last data to be sent for the resource pack, - // meaning we got too little data. - return fmt.Errorf("resource pack chunk data had a length of %v, but expected %v", len(frag.Data), pack.chunkSize) - } + case frag, ok = <-pack.newFrag: + } + if !ok { + break + } - if frag.DataOffset != uint64(dataWritten) { - return fmt.Errorf("resourcepack current offset %d != %d fragment offset", dataWritten, frag.DataOffset) - } + // Write the fragment to the full buffer of the downloading resource pack. + lastData := dataWritten+int(pack.chunkSize) >= int(pack.size) + if !lastData && uint32(len(frag.Data)) != pack.chunkSize { + // The chunk data didn't have the full size and wasn't the last data to be sent for the resource pack, + // meaning we got too little data. + return fmt.Errorf("resource pack chunk data had a length of %v, but expected %v", len(frag.Data), pack.chunkSize) + } + + if frag.DataOffset != uint64(dataWritten) { + return fmt.Errorf("resourcepack current offset %d != %d fragment offset", dataWritten, frag.DataOffset) + } - _, err := f.Write(frag.Data) + _, err := f.Write(frag.Data) + if err != nil { + return err + } + dataWritten += len(frag.Data) + + if lastData { + break + } + + if chunksDone < int(chunkCount) { + err = r.Server.WritePacket(&packet.ResourcePackChunkRequest{ + UUID: pk.UUID, + ChunkIndex: uint32(chunksDone), + }) if err != nil { return err } - dataWritten += len(frag.Data) + chunksDone++ } } + /* + sf, ok := r.Server.(interface { + Stats() *raknet.RakNetStatistics + }) + if ok { + stats := sf.Stats() + utils.DumpStruct(os.Stdout, stats.Total) + } + */ + if dataWritten != int(pack.size) { return fmt.Errorf("incorrect resource pack size: expected %v, but got %v", pack.size, dataWritten) } diff --git a/utils/proxy/session.go b/utils/proxy/session.go index 6b3a121..a8fd0de 100644 --- a/utils/proxy/session.go +++ b/utils/proxy/session.go @@ -347,7 +347,7 @@ func (s *Session) connectServer(ctx context.Context, connect *utils.ConnectInfo) }, } for retry := 0; retry < 3; retry++ { - d.ChainKey, d.ChainData, err = minecraft.CreateChain(ctx, utils.Auth) + d.ChainKey, d.ChainData, err = utils.Auth.Chain(ctx) if err != nil { continue } diff --git a/utils/zip.go b/utils/zip.go index 6b8f209..33f4285 100644 --- a/utils/zip.go +++ b/utils/zip.go @@ -1,17 +1,10 @@ package utils import ( - "archive/zip" "io" - "io/fs" - "os" - "path/filepath" - "strings" "sync" "github.com/klauspost/compress/flate" - - "github.com/sirupsen/logrus" ) type closePutback struct { @@ -43,46 +36,3 @@ func (pool *DeflatePool) ReturnWriter(writer *flate.Writer) { _ = writer.Close() pool.pool.Put(writer) } - -func ZipFolder(filename, folder string) error { - f, err := os.Create(filename) - if err != nil { - return err - } - defer f.Close() - zw := zip.NewWriter(f) - - // Register a custom Deflate compressor. - zw.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) { - w := deflate.GetWriter(out) - return closePutback{w}, nil - }) - - err = filepath.WalkDir(folder, func(fpath string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if d.Type().IsDir() { - return nil - } - rel, err := filepath.Rel(folder, fpath) - if err != nil { - return err - } - rel = strings.ReplaceAll(rel, "\\", "/") - - zwf, _ := zw.Create(rel) - f, err := os.Open(fpath) - if err != nil { - logrus.Error(err) - return nil - } - _, err = io.Copy(zwf, f) - return err - }) - if err != nil { - return err - } - - return zw.Close() -}