Disconnect method, SendPacket and ReceivePacket.

This commit is contained in:
Tnze
2019-08-16 12:46:09 +08:00
parent 78a50b7160
commit 0c48980309
5 changed files with 34 additions and 15 deletions

View File

@ -2,6 +2,7 @@ package bot
import (
"errors"
"github.com/Tnze/go-mc/chat"
"strconv"
"github.com/Tnze/go-mc/data"
@ -178,3 +179,17 @@ func (c *Client) UseItemEnd() error {
func (c *Client) SwapItem() error {
return c.playerAction(6, 0, 0, 0, 0)
}
// Disconnect send disconnect packet to server.
// Server will close the connection after receive this packet.
func (c *Client) Disconnect(reason chat.Message) error {
return c.conn.WritePacket(pk.Marshal(
data.DisconnectPlay,
reason,
))
}
// SendPacket send the packet to server.
func (c *Client) SendPacket(packet pk.Packet) error {
return c.conn.WritePacket(packet)
}