Skip to content

Commit

Permalink
packet violation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olebeck committed Jul 25, 2024
1 parent 35f0a19 commit 61f2079
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
34 changes: 33 additions & 1 deletion handlers/worlds/packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion handlers/worlds/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
37 changes: 21 additions & 16 deletions ui/gui/popups/gatherings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}),
)
})
})
})
})
Expand Down
4 changes: 4 additions & 0 deletions utils/proxy/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 61f2079

Please sign in to comment.