add player package with key client-side player functionality, update protocol codecs, and refactor metadata definitions and slot usage
This commit is contained in:
74
pkg/client/connect.go
Normal file
74
pkg/client/connect.go
Normal file
@ -0,0 +1,74 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.konjactw.dev/patyhank/minego/pkg/auth"
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
"github.com/Tnze/go-mc/data/packetid"
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
)
|
||||
|
||||
func (b *botClient) login() error {
|
||||
a := &auth.Auth{
|
||||
Conn: b.conn,
|
||||
Provider: b.authProvider,
|
||||
}
|
||||
|
||||
ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancelFunc()
|
||||
|
||||
return a.HandleLogin(ctx)
|
||||
}
|
||||
|
||||
func (b *botClient) configuration() (err error) {
|
||||
var p pk.Packet
|
||||
for {
|
||||
err = b.conn.ReadPacket(&p)
|
||||
|
||||
switch packetid.ClientboundPacketID(p.ID) {
|
||||
case packetid.ClientboundConfigDisconnect:
|
||||
var reason chat.Message
|
||||
err = p.Scan(&reason)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return errors.New("kicked: " + reason.String())
|
||||
case packetid.ClientboundConfigFinishConfiguration:
|
||||
err = b.conn.WritePacket(pk.Marshal(
|
||||
packetid.ServerboundConfigFinishConfiguration,
|
||||
))
|
||||
return err
|
||||
case packetid.ClientboundConfigKeepAlive:
|
||||
var keepAliveID pk.Long
|
||||
err = p.Scan(&keepAliveID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = b.conn.WritePacket(pk.Marshal(packetid.ServerboundConfigKeepAlive, keepAliveID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case packetid.ClientboundConfigPing:
|
||||
var pingID pk.Int
|
||||
err = p.Scan(&pingID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = b.conn.WritePacket(pk.Marshal(packetid.ServerboundConfigPong, pingID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case packetid.ClientboundConfigSelectKnownPacks:
|
||||
err = b.conn.WritePacket(pk.Marshal(packetid.ServerboundConfigSelectKnownPacks, pk.VarInt(0)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user