diff --git a/bot/basic/basic.go b/bot/basic/basic.go index a923015..2054c23 100644 --- a/bot/basic/basic.go +++ b/bot/basic/basic.go @@ -40,6 +40,7 @@ func NewPlayer(c *bot.Client, settings Settings, events EventsListener) *Player bot.PacketHandler{Priority: 0, ID: packetid.ClientboundLogin, F: p.handleLoginPacket}, bot.PacketHandler{Priority: 0, ID: packetid.ClientboundKeepAlive, F: p.handleKeepAlivePacket}, bot.PacketHandler{Priority: 0, ID: packetid.ClientboundRespawn, F: p.handleRespawnPacket}, + bot.PacketHandler{Priority: 0, ID: packetid.ClientboundPing, F: p.handlePingPacket}, ) events.attach(p) return p diff --git a/bot/basic/ping.go b/bot/basic/ping.go new file mode 100644 index 0000000..f27538e --- /dev/null +++ b/bot/basic/ping.go @@ -0,0 +1,23 @@ +package basic + +import ( + "github.com/Tnze/go-mc/data/packetid" + pk "github.com/Tnze/go-mc/net/packet" +) + +func (p *Player) handlePingPacket(packet pk.Packet) error { + var pingID pk.Int + if err := packet.Scan(&pingID); err != nil { + return Error{err} + } + + // Response + err := p.c.Conn.WritePacket(pk.Packet{ + ID: int32(packetid.ServerboundPong), + Data: packet.Data, + }) + if err != nil { + return Error{err} + } + return nil +}