replace latency packet id name usage
This commit is contained in:
16
bot/login.go
16
bot/login.go
@ -46,7 +46,7 @@ func (c *Client) joinLogin(conn *net.Conn) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = conn.WritePacket(pk.Marshal(
|
err = conn.WritePacket(pk.Marshal(
|
||||||
packetid.ServerboundLoginStart,
|
packetid.ServerboundLoginHello,
|
||||||
pk.String(c.Auth.Name),
|
pk.String(c.Auth.Name),
|
||||||
pk.UUID(c.UUID),
|
pk.UUID(c.UUID),
|
||||||
))
|
))
|
||||||
@ -63,7 +63,7 @@ func (c *Client) joinLogin(conn *net.Conn) error {
|
|||||||
|
|
||||||
// Handle Packet
|
// Handle Packet
|
||||||
switch packetid.ClientboundPacketID(p.ID) {
|
switch packetid.ClientboundPacketID(p.ID) {
|
||||||
case packetid.ClientboundLoginDisconnect: // LoginDisconnect
|
case packetid.ClientboundLoginLoginDisconnect: // LoginDisconnect
|
||||||
var reason chat.JsonMessage
|
var reason chat.JsonMessage
|
||||||
err = p.Scan(&reason)
|
err = p.Scan(&reason)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -71,13 +71,13 @@ func (c *Client) joinLogin(conn *net.Conn) error {
|
|||||||
}
|
}
|
||||||
return LoginErr{"disconnect", DisconnectErr(reason)}
|
return LoginErr{"disconnect", DisconnectErr(reason)}
|
||||||
|
|
||||||
case packetid.ClientboundLoginEncryptionRequest: // Encryption Request
|
case packetid.ClientboundLoginHello: // Encryption Request
|
||||||
if err := handleEncryptionRequest(conn, c, p); err != nil {
|
if err := handleEncryptionRequest(conn, c, p); err != nil {
|
||||||
return LoginErr{"encryption", err}
|
return LoginErr{"encryption", err}
|
||||||
}
|
}
|
||||||
receiving = "set compression"
|
receiving = "set compression"
|
||||||
|
|
||||||
case packetid.ClientboundLoginSuccess: // Login Success
|
case packetid.ClientboundLoginGameProfile: // Login Success
|
||||||
err := p.Scan(
|
err := p.Scan(
|
||||||
(*pk.UUID)(&c.UUID),
|
(*pk.UUID)(&c.UUID),
|
||||||
(*pk.String)(&c.Name),
|
(*pk.String)(&c.Name),
|
||||||
@ -85,13 +85,13 @@ func (c *Client) joinLogin(conn *net.Conn) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return LoginErr{"login success", err}
|
return LoginErr{"login success", err}
|
||||||
}
|
}
|
||||||
err = conn.WritePacket(pk.Marshal(packetid.ServerboundLoginAcknowledged))
|
err = conn.WritePacket(pk.Marshal(packetid.ServerboundLoginLoginAcknowledged))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LoginErr{"login success", err}
|
return LoginErr{"login success", err}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case packetid.ClientboundLoginCompression: // Set Compression
|
case packetid.ClientboundLoginLoginCompression: // Set Compression
|
||||||
var threshold pk.VarInt
|
var threshold pk.VarInt
|
||||||
if err := p.Scan(&threshold); err != nil {
|
if err := p.Scan(&threshold); err != nil {
|
||||||
return LoginErr{"compression", err}
|
return LoginErr{"compression", err}
|
||||||
@ -99,7 +99,7 @@ func (c *Client) joinLogin(conn *net.Conn) error {
|
|||||||
conn.SetThreshold(int(threshold))
|
conn.SetThreshold(int(threshold))
|
||||||
receiving = "login success"
|
receiving = "login success"
|
||||||
|
|
||||||
case packetid.ClientboundLoginPluginRequest: // Login Plugin Request
|
case packetid.ClientboundLoginCustomQuery: // Login Plugin Request
|
||||||
var (
|
var (
|
||||||
msgid pk.VarInt
|
msgid pk.VarInt
|
||||||
channel pk.Identifier
|
channel pk.Identifier
|
||||||
@ -119,7 +119,7 @@ func (c *Client) joinLogin(conn *net.Conn) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := conn.WritePacket(pk.Marshal(
|
if err := conn.WritePacket(pk.Marshal(
|
||||||
packetid.ServerboundLoginPluginResponse,
|
packetid.ServerboundLoginCustomQueryAnswer,
|
||||||
msgid, PluginMessageData,
|
msgid, PluginMessageData,
|
||||||
)); err != nil {
|
)); err != nil {
|
||||||
return LoginErr{"login Plugin", err}
|
return LoginErr{"login Plugin", err}
|
||||||
|
@ -94,7 +94,7 @@ func pingAndList(ctx context.Context, addr string, conn *mcnet.Conn) (data []byt
|
|||||||
// LIST
|
// LIST
|
||||||
// 请求服务器状态
|
// 请求服务器状态
|
||||||
err = conn.WritePacket(pk.Marshal(
|
err = conn.WritePacket(pk.Marshal(
|
||||||
packetid.ServerboundStatusRequest,
|
packetid.ServerboundStatusStatusRequest,
|
||||||
))
|
))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, fmt.Errorf("bot: send list packect fail: %v", err)
|
return nil, 0, fmt.Errorf("bot: send list packect fail: %v", err)
|
||||||
|
@ -79,7 +79,7 @@ func Encrypt(conn *net.Conn, name string, serverKey *rsa.PrivateKey) (*Resp, err
|
|||||||
|
|
||||||
func encryptionRequest(conn *net.Conn, publicKey, verifyToken []byte) error {
|
func encryptionRequest(conn *net.Conn, publicKey, verifyToken []byte) error {
|
||||||
return conn.WritePacket(pk.Marshal(
|
return conn.WritePacket(pk.Marshal(
|
||||||
packetid.ClientboundLoginEncryptionRequest,
|
packetid.ClientboundLoginHello,
|
||||||
pk.String(""),
|
pk.String(""),
|
||||||
pk.ByteArray(publicKey),
|
pk.ByteArray(publicKey),
|
||||||
pk.ByteArray(verifyToken),
|
pk.ByteArray(verifyToken),
|
||||||
@ -92,7 +92,7 @@ func encryptionResponse(conn *net.Conn, serverKey *rsa.PrivateKey, verifyToken [
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if packetid.ServerboundPacketID(p.ID) != packetid.ServerboundLoginEncryptionResponse {
|
if packetid.ServerboundPacketID(p.ID) != packetid.ServerboundLoginKey {
|
||||||
return nil, fmt.Errorf("0x%02X is not Encryption Response", p.ID)
|
return nil, fmt.Errorf("0x%02X is not Encryption Response", p.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,8 +96,8 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if packetid.ServerboundPacketID(p.ID) != packetid.ServerboundLoginStart {
|
if packetid.ServerboundPacketID(p.ID) != packetid.ServerboundLoginHello {
|
||||||
err = wrongPacketErr{expect: int32(packetid.ServerboundLoginStart), get: p.ID}
|
err = wrongPacketErr{expect: int32(packetid.ServerboundLoginHello), get: p.ID}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s
|
|||||||
// set compression
|
// set compression
|
||||||
if d.Threshold >= 0 {
|
if d.Threshold >= 0 {
|
||||||
err = conn.WritePacket(pk.Marshal(
|
err = conn.WritePacket(pk.Marshal(
|
||||||
packetid.ClientboundLoginCompression,
|
packetid.ClientboundLoginLoginCompression,
|
||||||
pk.VarInt(d.Threshold),
|
pk.VarInt(d.Threshold),
|
||||||
))
|
))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -152,7 +152,7 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s
|
|||||||
}
|
}
|
||||||
// send login success
|
// send login success
|
||||||
err = conn.WritePacket(pk.Marshal(
|
err = conn.WritePacket(pk.Marshal(
|
||||||
packetid.ClientboundLoginSuccess,
|
packetid.ClientboundLoginGameProfile,
|
||||||
pk.UUID(id),
|
pk.UUID(id),
|
||||||
pk.String(name),
|
pk.String(name),
|
||||||
pk.Array(properties),
|
pk.Array(properties),
|
||||||
@ -163,8 +163,8 @@ func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name s
|
|||||||
|
|
||||||
// receive login ack
|
// receive login ack
|
||||||
err = conn.ReadPacket(&p)
|
err = conn.ReadPacket(&p)
|
||||||
if err == nil && packetid.ServerboundPacketID(p.ID) != packetid.ServerboundLoginAcknowledged {
|
if err == nil && packetid.ServerboundPacketID(p.ID) != packetid.ServerboundLoginLoginAcknowledged {
|
||||||
err = wrongPacketErr{expect: int32(packetid.ServerboundLoginAcknowledged), get: p.ID}
|
err = wrongPacketErr{expect: int32(packetid.ServerboundLoginLoginAcknowledged), get: p.ID}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func (s *Server) acceptListPing(conn *net.Conn, clientProtocol int32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch packetid.ClientboundPacketID(p.ID) {
|
switch packetid.ClientboundPacketID(p.ID) {
|
||||||
case packetid.ClientboundStatusResponse: // List
|
case packetid.ClientboundStatusStatusResponse: // List
|
||||||
var resp []byte
|
var resp []byte
|
||||||
resp, err = s.listResp(clientProtocol)
|
resp, err = s.listResp(clientProtocol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -81,7 +81,7 @@ func (s *Server) AcceptConn(conn *net.Conn) {
|
|||||||
var loginErr LoginFailErr
|
var loginErr LoginFailErr
|
||||||
if errors.As(err, &loginErr) {
|
if errors.As(err, &loginErr) {
|
||||||
_ = conn.WritePacket(pk.Marshal(
|
_ = conn.WritePacket(pk.Marshal(
|
||||||
packetid.ClientboundLoginDisconnect,
|
packetid.ClientboundLoginLoginDisconnect,
|
||||||
loginErr.reason,
|
loginErr.reason,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user