Update packetid name

This commit is contained in:
Tnze
2021-12-09 20:24:39 +08:00
parent 805ca37a67
commit 0cc5695aa3
15 changed files with 203 additions and 474 deletions

View File

@ -18,9 +18,9 @@ type Player struct {
func NewPlayer(c *bot.Client, settings Settings) *Player {
b := &Player{c: c, Settings: settings}
c.Events.AddListener(
bot.PacketHandler{Priority: 0, ID: packetid.Login, F: b.handleJoinGamePacket},
bot.PacketHandler{Priority: 0, ID: packetid.KeepAliveClientbound, F: b.handleKeepAlivePacket},
bot.PacketHandler{Priority: 0, ID: packetid.PositionClientbound, F: b.handlePlayerPositionAndLook},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundLogin, F: b.handleJoinGamePacket},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundKeepAlive, F: b.handleKeepAlivePacket},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundPlayerPosition, F: b.handlePlayerPositionAndLook},
)
return b
}
@ -29,7 +29,7 @@ func (p *Player) Respawn() error {
const PerformRespawn = 0
err := p.c.Conn.WritePacket(pk.Marshal(
packetid.ClientCommand,
packetid.ServerboundClientCommand,
pk.VarInt(PerformRespawn),
))
if err != nil {

View File

@ -19,10 +19,10 @@ type EventsListener struct {
func (e EventsListener) Attach(c *bot.Client) {
c.Events.AddListener(
bot.PacketHandler{Priority: 64, ID: packetid.Login, F: e.onJoinGame},
bot.PacketHandler{Priority: 64, ID: packetid.ChatClientbound, F: e.onChatMsg},
bot.PacketHandler{Priority: 64, ID: packetid.KickDisconnect, F: e.onDisconnect},
bot.PacketHandler{Priority: 64, ID: packetid.UpdateHealth, F: e.onUpdateHealth},
bot.PacketHandler{Priority: 64, ID: packetid.ClientboundLogin, F: e.onJoinGame},
bot.PacketHandler{Priority: 64, ID: packetid.ClientboundChat, F: e.onChatMsg},
bot.PacketHandler{Priority: 64, ID: packetid.ClientboundDisconnect, F: e.onDisconnect},
bot.PacketHandler{Priority: 64, ID: packetid.ClientboundSetHealth, F: e.onUpdateHealth},
)
}

View File

@ -73,7 +73,7 @@ func (p *Player) handleJoinGamePacket(packet pk.Packet) error {
p.WorldNames = *(*[]string)(unsafe.Pointer(&WorldNames))
err = p.c.Conn.WritePacket(pk.Marshal( //PluginMessage packet
packetid.CustomPayloadServerbound,
packetid.ServerboundCustomPayload,
pk.Identifier("minecraft:brand"),
pk.String(p.Settings.Brand),
))
@ -82,7 +82,7 @@ func (p *Player) handleJoinGamePacket(packet pk.Packet) error {
}
err = p.c.Conn.WritePacket(pk.Marshal(
packetid.Settings, // Client settings
packetid.ServerboundClientInformation, // Client settings
pk.String(p.Settings.Locale),
pk.Byte(p.Settings.ViewDistance),
pk.VarInt(p.Settings.ChatMode),

View File

@ -12,7 +12,7 @@ func (p Player) handleKeepAlivePacket(packet pk.Packet) error {
}
// Response
err := p.c.Conn.WritePacket(pk.Packet{
ID: packetid.KeepAliveServerbound,
ID: packetid.ServerboundKeepAlive,
Data: packet.Data,
})
if err != nil {
@ -35,7 +35,7 @@ func (p *Player) handlePlayerPositionAndLook(packet pk.Packet) error {
// Teleport Confirm
err := p.c.Conn.WritePacket(pk.Marshal(
packetid.TeleportConfirm,
packetid.ServerboundAcceptTeleportation,
TeleportID,
))
if err != nil {
@ -45,7 +45,7 @@ func (p *Player) handlePlayerPositionAndLook(packet pk.Packet) error {
if !p.isSpawn {
// PlayerPositionAndRotation to confirm the spawn position
err = p.c.Conn.WritePacket(pk.Marshal(
packetid.PositionLook,
packetid.ServerboundMoveVehicle,
X, Y-1.62, Z,
Yaw, Pitch,
pk.Boolean(true),

View File

@ -111,7 +111,7 @@ func (c *Client) join(d *net.Dialer, addr string) error {
//Handle Packet
switch p.ID {
case packetid.Disconnect: //Disconnect
case packetid.LoginDisconnect: //LoginDisconnect
var reason chat.Message
err = p.Scan(&reason)
if err != nil {
@ -119,12 +119,12 @@ func (c *Client) join(d *net.Dialer, addr string) error {
}
return LoginErr{"disconnect", DisconnectErr(reason)}
case packetid.EncryptionBeginClientbound: //Encryption Request
case packetid.LoginEncryptionRequest: //Encryption Request
if err := handleEncryptionRequest(c, p); err != nil {
return LoginErr{"encryption", err}
}
case packetid.Success: //Login Success
case packetid.LoginSuccess: //Login Success
err := p.Scan(
(*pk.UUID)(&c.UUID),
(*pk.String)(&c.Name),
@ -134,7 +134,7 @@ func (c *Client) join(d *net.Dialer, addr string) error {
}
return nil
case packetid.Compress: //Set Compression
case packetid.SetCompression: //Set Compression
var threshold pk.VarInt
if err := p.Scan(&threshold); err != nil {
return LoginErr{"compression", err}

View File

@ -77,7 +77,7 @@ func pingAndList(addr string, conn *mcnet.Conn) ([]byte, time.Duration, error) {
//LIST
//请求服务器状态
err = conn.WritePacket(pk.Marshal(
packetid.PingStart,
packetid.StatusRequest,
))
if err != nil {
return nil, 0, fmt.Errorf("bot: send list packect fail: %v", err)
@ -97,7 +97,7 @@ func pingAndList(addr string, conn *mcnet.Conn) ([]byte, time.Duration, error) {
//PING
startTime := time.Now()
err = conn.WritePacket(pk.Marshal(
packetid.PingServerbound,
packetid.StatusPing,
pk.Long(startTime.Unix()),
))
if err != nil {

View File

@ -25,10 +25,10 @@ func NewManager(c *bot.Client, e EventsListener) *Manager {
}
m.Screens[0] = &m.Inventory
c.Events.AddListener(
bot.PacketHandler{Priority: 0, ID: packetid.OpenWindow, F: m.onOpenScreen},
bot.PacketHandler{Priority: 0, ID: packetid.WindowItems, F: m.onSetContentPacket},
bot.PacketHandler{Priority: 0, ID: packetid.CloseWindowClientbound, F: m.onCloseScreen},
bot.PacketHandler{Priority: 0, ID: packetid.SetSlot, F: m.onSetSlot},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundOpenScreen, F: m.onOpenScreen},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundContainerSetContent, F: m.onSetContentPacket},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundContainerClose, F: m.onCloseScreen},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundContainerSetSlot, F: m.onSetSlot},
)
return m
}