From 61f2079372726bf2ed1d2b7860f0f4f6d4f771c0 Mon Sep 17 00:00:00 2001 From: olebeck <31539311+olebeck@users.noreply.github.com> Date: Thu, 25 Jul 2024 23:22:19 +0200 Subject: [PATCH] packet violation fix --- handlers/worlds/packets.go | 34 +++++++++++++++++++++++++++++++++- handlers/worlds/world.go | 2 +- ui/gui/popups/gatherings.go | 37 +++++++++++++++++++++---------------- utils/proxy/context.go | 4 ++++ 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/handlers/worlds/packets.go b/handlers/worlds/packets.go index 59d518e..c502392 100644 --- a/handlers/worlds/packets.go +++ b/handlers/worlds/packets.go @@ -37,12 +37,44 @@ func (w *worldsHandler) packetCB(_pk packet.Packet, toServer bool, timeReceived switch pk := _pk.(type) { case *packet.CompressedBiomeDefinitionList: // for client side generation, disabled by proxy return nil, nil + case *packet.GameRulesChanged: + var haveGameRule = false + for i, gameRule := range pk.GameRules { + if gameRule.Name == "showCoordinates" { + haveGameRule = true + gameRule.Value = true + pk.GameRules[i] = gameRule + break + } + } + if !haveGameRule { + pk.GameRules = append(pk.GameRules, protocol.GameRule{ + Name: "showCoordinates", + Value: true, + }) + } case *packet.StartGame: if !w.serverState.haveStartGame { w.serverState.haveStartGame = true w.currentWorld.SetTime(timeReceived, int(pk.Time)) w.serverState.useHashedRids = pk.UseBlockNetworkIDHashes + var haveGameRule = false + for i, gameRule := range pk.GameRules { + if gameRule.Name == "showCoordinates" { + haveGameRule = true + gameRule.Value = true + pk.GameRules[i] = gameRule + break + } + } + if !haveGameRule { + pk.GameRules = append(pk.GameRules, protocol.GameRule{ + Name: "showCoordinates", + Value: true, + }) + } + w.serverState.blocks = world.DefaultBlockRegistry.Clone().(*world.BlockRegistryImpl) world.InsertCustomItems(pk.Items) @@ -128,7 +160,7 @@ func (w *worldsHandler) packetCB(_pk packet.Packet, toServer bool, timeReceived switch pk := _pk.(type) { case *packet.RequestChunkRadius: pk.ChunkRadius = w.settings.ChunkRadius - pk.MaxChunkRadius = w.settings.ChunkRadius + //pk.MaxChunkRadius = w.settings.ChunkRadius case *packet.ChunkRadiusUpdated: w.serverState.radius = pk.ChunkRadius diff --git a/handlers/worlds/world.go b/handlers/worlds/world.go index a854a1d..837c64e 100644 --- a/handlers/worlds/world.go +++ b/handlers/worlds/world.go @@ -103,7 +103,7 @@ func NewWorldsHandler(settings WorldSettings) *proxy.Handler { }) if settings.ChunkRadius == 0 { - settings.ChunkRadius = 80 + settings.ChunkRadius = 76 } ctx, cancel := context.WithCancel(context.Background()) diff --git a/ui/gui/popups/gatherings.go b/ui/gui/popups/gatherings.go index e4ea1ad..ee7e7e8 100644 --- a/ui/gui/popups/gatherings.go +++ b/ui/gui/popups/gatherings.go @@ -196,22 +196,27 @@ func (g *Gatherings) Layout(gtx C, th *material.Theme) D { Button: click, CornerRadius: 8, } - return b.Layout(gtx, func(gtx C) D { - return layout.UniformInset(8).Layout(gtx, func(gtx C) D { - return layout.Flex{Axis: layout.Vertical}.Layout(gtx, - layout.Rigid(func(gtx C) D { - return material.Label(th, th.TextSize, gatheringName).Layout(gtx) - }), - layout.Rigid(func(gtx C) D { - var text string - if hasStarted { - text = fmt.Sprintf("Ends in %s", time.Until(end).Truncate(time.Second)) - } else { - text = fmt.Sprintf("Starts in %s", time.Until(start).Truncate(time.Second)) - } - return material.Label(th, th.TextSize, text).Layout(gtx) - }), - ) + + return layout.Inset{ + Bottom: 8, + }.Layout(gtx, func(gtx layout.Context) layout.Dimensions { + return b.Layout(gtx, func(gtx C) D { + return layout.UniformInset(8).Layout(gtx, func(gtx C) D { + return layout.Flex{Axis: layout.Vertical}.Layout(gtx, + layout.Rigid(func(gtx C) D { + return material.Label(th, th.TextSize, gatheringName).Layout(gtx) + }), + layout.Rigid(func(gtx C) D { + var text string + if hasStarted { + text = fmt.Sprintf("Ends in %s", time.Until(end).Truncate(time.Second)) + } else { + text = fmt.Sprintf("Starts in %s", time.Until(start).Truncate(time.Second)) + } + return material.Label(th, th.TextSize, text).Layout(gtx) + }), + ) + }) }) }) }) diff --git a/utils/proxy/context.go b/utils/proxy/context.go index 6274f1d..7a2e554 100644 --- a/utils/proxy/context.go +++ b/utils/proxy/context.go @@ -147,6 +147,10 @@ func (p *Context) Run(ctx context.Context, connect *utils.ConnectInfo) (err erro return nil }, PacketCallback: func(pk packet.Packet, toServer bool, timeReceived time.Time, preLogin bool) (packet.Packet, error) { + if pk, ok := pk.(*packet.PacketViolationWarning); ok { + logrus.Infof("%+#v\n", pk) + } + haveMoved := p.session.Player.handlePackets(pk) if haveMoved { for _, cb := range p.PlayerMoveCB {