Skip to content

Commit

Permalink
session/handler_sub_chunk_request.go: Fixed crash when SubChunkReques…
Browse files Browse the repository at this point in the history
…t was sent for old dimension.
  • Loading branch information
Sandertv committed Dec 23, 2024
1 parent c270627 commit 20a1e6d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/session/handler_sub_chunk_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package session

import (
"github.com/df-mc/dragonfly/server/world"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
)

Expand All @@ -12,6 +13,16 @@ type SubChunkRequestHandler struct{}
// Handle ...
func (*SubChunkRequestHandler) Handle(p packet.Packet, s *Session, tx *world.Tx, _ Controllable) error {
pk := p.(*packet.SubChunkRequest)
if dimID, _ := world.DimensionID(tx.World().Dimension()); pk.Dimension != int32(dimID) {
// Outdated sub chunk request from a previous dimension.
s.writePacket(&packet.SubChunk{
Dimension: pk.Dimension,
Position: pk.Position,
CacheEnabled: s.conn.ClientCacheEnabled(),
SubChunkEntries: []protocol.SubChunkEntry{},
})
return nil
}
s.ViewSubChunks(world.SubChunkPos(pk.Position), pk.Offsets, tx)
return nil
}

0 comments on commit 20a1e6d

Please sign in to comment.