Add playerinfo recorder for chat message

This commit is contained in:
Tnze
2022-12-30 01:09:08 +08:00
parent 6fba193255
commit 77857a1a85
6 changed files with 206 additions and 39 deletions

View File

@ -15,11 +15,13 @@ import (
"net/http"
"strings"
"github.com/google/uuid"
"github.com/Tnze/go-mc/data/packetid"
"github.com/Tnze/go-mc/net"
"github.com/Tnze/go-mc/net/CFB8"
pk "github.com/Tnze/go-mc/net/packet"
"github.com/google/uuid"
"github.com/Tnze/go-mc/yggdrasil/user"
)
const verifyTokenLen = 16
@ -171,42 +173,20 @@ func twosComplement(p []byte) []byte {
return p
}
type (
Texture = user.Texture
Property = user.Property
)
// Resp is the response of authentication
type Resp struct {
Name string
ID uuid.UUID
Properties []Property
}
type Property struct {
Name, Value, Signature string
}
func (p Property) WriteTo(w io.Writer) (n int64, err error) {
return pk.Tuple{
pk.String(p.Name),
pk.String(p.Value),
pk.Option[pk.String, *pk.String]{
Has: p.Signature != "",
Val: pk.String(p.Signature),
},
}.WriteTo(w)
}
// Texture includes player's skin and cape
type Texture struct {
TimeStamp int64 `json:"timestamp"`
ID uuid.UUID `json:"profileId"`
Name string `json:"profileName"`
Textures struct {
SKIN, CAPE struct {
URL string `json:"url"`
}
} `json:"textures"`
Properties []user.Property
}
// Texture unmarshal the base64 encoded texture of Resp
func (r *Resp) Texture() (t Texture, err error) {
func (r *Resp) Texture() (t user.Texture, err error) {
var texture []byte
texture, err = base64.StdEncoding.DecodeString(r.Properties[0].Value)
if err != nil {