Handle ping in bot/basic
This commit is contained in:
@ -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.ClientboundLogin, F: p.handleLoginPacket},
|
||||||
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundKeepAlive, F: p.handleKeepAlivePacket},
|
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.ClientboundRespawn, F: p.handleRespawnPacket},
|
||||||
|
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundPing, F: p.handlePingPacket},
|
||||||
)
|
)
|
||||||
events.attach(p)
|
events.attach(p)
|
||||||
return p
|
return p
|
||||||
|
23
bot/basic/ping.go
Normal file
23
bot/basic/ping.go
Normal file
@ -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
|
||||||
|
}
|
Reference in New Issue
Block a user