提高对第三方启动器的兼容性

This commit is contained in:
xmdhs 2023-09-13 23:37:23 +08:00
parent 5c590ac78f
commit 7624268b93
No known key found for this signature in database
GPG Key ID: E809D6D43DEFCC95
4 changed files with 33 additions and 28 deletions

View File

@ -7,10 +7,6 @@ type Pass struct {
} }
type Authenticate struct { type Authenticate struct {
Agent struct {
Name string `json:"name" validate:"required,eq=Minecraft"`
Version int `json:"version" validate:"required,eq=1"`
} `json:"agent"`
ClientToken string `json:"clientToken"` ClientToken string `json:"clientToken"`
RequestUser bool `json:"requestUser"` RequestUser bool `json:"requestUser"`
Pass Pass
@ -23,7 +19,8 @@ type Error struct {
} }
type TokenUserID struct { type TokenUserID struct {
ID string `json:"id"` ID string `json:"id"`
Properties []any `json:"properties,omitempty"`
} }
type Token struct { type Token struct {

View File

@ -11,7 +11,7 @@ type UserTextures struct {
ProfileName string `json:"profileName"` ProfileName string `json:"profileName"`
Textures map[string]Textures `json:"textures"` Textures map[string]Textures `json:"textures"`
// 时间戳 毫秒 // 时间戳 毫秒
Timestamp string `json:"timestamp"` Timestamp int64 `json:"timestamp"`
} }
type Textures struct { type Textures struct {

View File

@ -40,6 +40,7 @@ func newYggdrasil(r *httprouter.Router, handelY yggdrasil.Yggdrasil) error {
r.POST("/api/yggdrasil/minecraftservices/player/certificates", warpHJSON(handelY.PlayerCertificates())) r.POST("/api/yggdrasil/minecraftservices/player/certificates", warpHJSON(handelY.PlayerCertificates()))
r.GET("/api/yggdrasil", warpHJSON(handelY.YggdrasilRoot())) r.GET("/api/yggdrasil", warpHJSON(handelY.YggdrasilRoot()))
r.GET("/api/yggdrasil/", warpHJSON(handelY.YggdrasilRoot()))
r.GET("/texture/*filepath", handelY.TextureAssets()) r.GET("/texture/*filepath", handelY.TextureAssets())
return nil return nil

View File

@ -104,7 +104,8 @@ func (y *Yggdrasil) Authenticate(cxt context.Context, auth yggdrasil.Authenticat
ClientToken: clientToken, ClientToken: clientToken,
SelectedProfile: p, SelectedProfile: p,
User: yggdrasil.TokenUserID{ User: yggdrasil.TokenUserID{
ID: utils.UUIDGen(strconv.Itoa(u.ID)), ID: utils.UUIDGen(strconv.Itoa(u.ID)),
Properties: []any{},
}, },
}, nil }, nil
} }
@ -171,16 +172,16 @@ func (y *Yggdrasil) Refresh(ctx context.Context, token yggdrasil.RefreshToken) (
if err != nil { if err != nil {
return yggdrasil.Token{}, fmt.Errorf("Authenticate: %w", err) return yggdrasil.Token{}, fmt.Errorf("Authenticate: %w", err)
} }
u := yggdrasil.UserInfo{ID: up.UUID, Name: up.Name}
return yggdrasil.Token{ return yggdrasil.Token{
AccessToken: jwts, AccessToken: jwts,
ClientToken: t.CID, AvailableProfiles: []yggdrasil.UserInfo{u},
SelectedProfile: yggdrasil.UserInfo{ ClientToken: t.CID,
ID: up.UUID, SelectedProfile: u,
Name: up.Name,
},
User: yggdrasil.TokenUserID{ User: yggdrasil.TokenUserID{
ID: utils.UUIDGen(strconv.Itoa(t.UID)), ID: utils.UUIDGen(strconv.Itoa(t.UID)),
Properties: []any{},
}, },
}, nil }, nil
} }
@ -209,7 +210,7 @@ func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool,
ProfileID: up.UUID, ProfileID: up.UUID,
ProfileName: up.Name, ProfileName: up.Name,
Textures: map[string]yggdrasil.Textures{}, Textures: map[string]yggdrasil.Textures{},
Timestamp: strconv.FormatInt(time.Now().UnixMilli(), 10), Timestamp: time.Now().UnixMilli(),
} }
for _, v := range up.Edges.Usertexture { for _, v := range up.Edges.Usertexture {
@ -230,25 +231,31 @@ func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool,
texturesBase64 := ut.Base64() texturesBase64 := ut.Base64()
var signStr string pl := []yggdrasil.UserProperties{}
pl = append(pl, yggdrasil.UserProperties{
Name: "textures",
Value: texturesBase64,
})
pl = append(pl, yggdrasil.UserProperties{
Name: "uploadableTextures",
Value: "skin,cape",
})
if !unsigned { if !unsigned {
s := sign.NewAuthlibSignWithKey(y.prikey) s := sign.NewAuthlibSignWithKey(y.prikey)
signStr, err = s.Sign([]byte(texturesBase64)) for i, v := range pl {
if err != nil { sign, err := s.Sign([]byte(v.Signature))
return yggdrasil.UserInfo{}, fmt.Errorf("GetProfile: %w", err) if err != nil {
return yggdrasil.UserInfo{}, fmt.Errorf("GetProfile: %w", ErrNotUser)
}
pl[i].Signature = sign
} }
} }
uinfo := yggdrasil.UserInfo{ uinfo := yggdrasil.UserInfo{
ID: up.UUID, ID: up.UUID,
Name: up.Name, Name: up.Name,
Properties: []yggdrasil.UserProperties{ Properties: pl,
{
Name: "textures",
Value: texturesBase64,
Signature: signStr,
},
},
} }
return uinfo, nil return uinfo, nil