Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
修复自动登录失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
BaiMeow committed Mar 6, 2020
1 parent e21b6a3 commit df0b326
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 50 deletions.
4 changes: 2 additions & 2 deletions AutoFish.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
flag.BoolVar(&removemode, "remove", false, "删除配置模式")
flag.Parse()
log.Println("自动钓鱼机器人启动!")
log.Println("机器人版本:1.4.3.1")
log.Println("机器人版本:1.4.4")
log.Printf("游戏版本:%s", version)
log.Println("基于github.com/Tnze/go-mc")
log.Println("作者: Tnze&BaiMeow")
Expand Down Expand Up @@ -84,7 +84,7 @@ func main() {
}

c = bot.NewClient()
c.Name, c.Auth.UUID, c.AsTk = auth.Name, auth.UUID, auth.AsTk
c.Name, c.Auth.UUID, c.AsTk = auth.Name, auth.UUID, auth.Tokens.AccessToken
l.AddtoConfig(&auth)
//判断是否领域服登陆,整一个领域ip
if realm && auth.Authmode != "Offline" {
Expand Down
31 changes: 5 additions & 26 deletions conf.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
{
"players": [
{
"name": "bs1",
"UUID": "",
"AsTk": "",
"account": "",
"authserver": "",
"authmode": "Offline"
},
{
"name": "Msc__BaiMeow",
"UUID": "1ef88718148741cb8f5770e01fd55ef7",
"AsTk": "ffffffffffffffffffffffffffffffff",
"account": "[email protected]",
"Tokens": {
"accessToken": "eyJhbpciOiJIUzI1NiJ9.eyJzdWmiOiIxNTBiY2d0N2Q4MGUxZmNkOWUwZDM5YmY1Yzk0NzhhMiIsInlnZ3QiOiI5NzViNDgwNTdhMDg0ZDcyYjk0N2I1NzQxOTBhYWRhYyIsInNwciI6IjFlZjg4NzE4MTQ4NzQxY2I4ZjU3NzBlMDFmZDU1ZWY3IiwiaXNzIjoiWWdnZHJhc2lsLUF1dGgiLCJleHAiOjE1ODM2MzIzNTYsImlhdCI6MTU4MzQ1OTU1Nn0.WMtYlGEhIv3Ex4roPEmbEL5zdI-i1IfypQ1nr5r1Vo4",
"clientToken": "1ca41fra-6f49-4b67-8bb5-4c432be98633"
},
"account": "[email protected]",
"authserver": "https://authserver.mojang.com",
"authmode": "MojangAuth"
},
{
"name": "bs2",
"UUID": "",
"AsTk": "",
"account": "",
"authserver": "",
"authmode": "Offline"
},
{
"name": "bs3",
"UUID": "",
"AsTk": "",
"account": "",
"authserver": "",
"authmode": "Offline"
}
]
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ require (
gopkg.in/yaml.v2 v2.2.3 // indirect
)

replace github.com/Tnze/go-mc => github.com/MscBaiMeow/go-mc v1.15.2
replace github.com/Tnze/go-mc => github.com/MscBaiMeow/go-mc v1.14.5-0.20200306020755-789ec6ee2af3
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/AlecAivazis/survey/v2 v2.0.4 h1:qzXnJSzXEvmUllWqMBWpZndvT2YfoAUzAMvZUax3L2M=
github.com/AlecAivazis/survey/v2 v2.0.4/go.mod h1:WYBhg6f0y/fNYUuesWQc0PKbJcEliGcYHB9sNT3Bg74=
github.com/MscBaiMeow/go-mc v1.15.2 h1:ya1h5v4aqUf8AyMcmOXjiDjjdw5qS4K/JR6SsURwnmY=
github.com/MscBaiMeow/go-mc v1.15.2/go.mod h1:1m/EKIN1b/8WC0NwzbJXS9FYHG2I0hEH12ewt29kqcI=
github.com/MscBaiMeow/go-mc v1.14.5-0.20200306020755-789ec6ee2af3 h1:oH/yN4+YjoJSqXSubuamJK3usgMaKIJ/c3klmR6L0EE=
github.com/MscBaiMeow/go-mc v1.14.5-0.20200306020755-789ec6ee2af3/go.mod h1:ZQpDcppzIn7X37rsk39CAL4C7nkmu4sxWvDpcy9pncc=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/Netflix/go-expect v0.0.0-20190729225929-0e00d9168667 h1:l2RCK7mjLhjfZRIcCXTVHI34l67IRtKASBjusViLzQ0=
github.com/Netflix/go-expect v0.0.0-20190729225929-0e00d9168667/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
Expand Down
41 changes: 22 additions & 19 deletions mclogin/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (

//Player is a profile of aplayer.
type Player struct {
Name string `json:"name"`
UUID string `json:"UUID"`
AsTk string `json:"AsTk"`
Account string `json:"account"`
Authserver string `json:"authserver"`
Authmode string `json:"authmode"`
Name string `json:"name"`
UUID string `json:"UUID"`
Tokens ygg.Tokens `json:"Tokens"`
Account string `json:"account"`
Authserver string `json:"authserver"`
Authmode string `json:"authmode"`
}

//Config used to restore config in the program
Expand All @@ -28,8 +28,8 @@ type Config struct {
}

var (
conf Config
resp *ygg.Access
conf Config
access ygg.Access
)

//Authlogin is used when you need to login with passwd
Expand All @@ -49,21 +49,21 @@ func Authlogin(account, authserver *string, auth *Player) {
Message: "Please type your password",
}
survey.AskOne(prompt, &password)
resp, err := ygg.Authenticate(*account, string(password))
access, err := ygg.Authenticate(*account, string(password))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
log.Println("Auth success")
if len(resp.AvailableProfiles()) != 1 {
if len(access.AvailableProfiles()) != 1 {
//多用户选择、登陆
var (
no int
preSelected []string
selected string
)
//把安排survey包的单选中的选项所需要的切片搞出来
for _, v := range resp.AvailableProfiles() {
for _, v := range access.AvailableProfiles() {
preSelected = append(preSelected, fmt.Sprintf("[%d]", no)+v.Name)
no++
}
Expand All @@ -76,15 +76,15 @@ func Authlogin(account, authserver *string, auth *Player) {
//获得选中的用户的序号
fmt.Sscanf(selected, "[%d]", &no)
//refresh刷新获得该用户AsTk
if err = resp.Refresh(&resp.AvailableProfiles()[no]); err != nil {
if err = access.Refresh(&access.AvailableProfiles()[no]); err != nil {
log.Fatal(err)
os.Exit(1)

}
}
//安排登陆账户
auth.UUID, auth.Name = resp.SelectedProfile()
auth.AsTk = resp.AccessToken()
auth.UUID, auth.Name = access.SelectedProfile()
auth.Tokens = access.GetTokens()
return
}

Expand Down Expand Up @@ -134,7 +134,8 @@ func LoadConfiglogin(auth *Player) {
return
case "MojangAuth":
//检测asTk是否有效
ok, err := resp.Validate(auth.AsTk)
access.SetTokens(auth.Tokens)
ok, err := access.Validate()
if err != nil {
log.Fatal(err)
os.Exit(1)
Expand All @@ -146,7 +147,8 @@ func LoadConfiglogin(auth *Player) {
case "ThreeAuth":
ygg.AuthURL = fmt.Sprintf("%s/authserver", auth.Authserver)
bot.SessionURL = fmt.Sprintf("%s/sessionserver/session/minecraft/join", auth.Authserver)
ok, err := resp.Validate(auth.AsTk)
access.SetTokens(auth.Tokens)
ok, err := access.Validate()
if err != nil {
log.Fatal(err)
os.Exit(1)
Expand Down Expand Up @@ -191,7 +193,7 @@ func AddtoConfig(auth *Player) {
//判断是否同一个账号
if auth.UUID == v.UUID {
//判断是否需要更新AsTk
if auth.AsTk != v.AsTk {
if auth.Tokens != v.Tokens {
break
}
return
Expand All @@ -202,7 +204,7 @@ func AddtoConfig(auth *Player) {
if i == len(conf.Players) {
conf.Players = append(conf.Players, *auth)
} else {
conf.Players[i].AsTk = auth.AsTk
conf.Players[i].Tokens = auth.Tokens
}
//替换配置文件
data, _ := json.Marshal(conf)
Expand Down Expand Up @@ -230,7 +232,8 @@ func Directlogin(uuid string, auth *Player) {
ygg.AuthURL = fmt.Sprintf("%s/authserver", auth.Authserver)
bot.SessionURL = fmt.Sprintf("%s/sessionserver/session/minecraft/join", auth.Authserver)
}
ok, err := resp.Validate(auth.AsTk)
access.SetTokens(auth.Tokens)
ok, err := access.Validate()
if err != nil {
log.Fatal(err)
os.Exit(1)
Expand Down

0 comments on commit df0b326

Please sign in to comment.