Skip to content

Commit

Permalink
minecraft/protocol.go: Fixed bug causing server to still read all pac…
Browse files Browse the repository at this point in the history
…kets.
  • Loading branch information
Sandertv committed Sep 5, 2023
1 parent 46eecd9 commit daa1201
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions minecraft/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type unknownPacketError struct {
}

func (err unknownPacketError) Error() string {
return fmt.Sprintf("unknown packet with ID %v", err.id)
return fmt.Sprintf("unexpected packet with ID %v", err.id)
}

// decode decodes the packet payload held in the packetData and returns the packet.Packet decoded.
Expand All @@ -46,11 +46,7 @@ func (p *packetData) decode(conn *Conn) (pks []packet.Packet, err error) {
if err == nil {
return
}
if _, ok := err.(unknownPacketError); ok {
if conn.disconnectOnUnknownPacket {
_ = conn.Close()
}
} else if conn.disconnectOnInvalidPacket {
if _, ok := err.(unknownPacketError); ok || conn.disconnectOnInvalidPacket {
_ = conn.Close()
}
}()
Expand Down
2 changes: 1 addition & 1 deletion minecraft/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (proto) ID() int32 { return protocol.CurrentProtocol }
func (p proto) Ver() string { return protocol.CurrentVersion }
func (p proto) Packets(listener bool) packet.Pool {
if listener {
packet.NewClientPool()
return packet.NewClientPool()
}
return packet.NewServerPool()
}
Expand Down

0 comments on commit daa1201

Please sign in to comment.