From df0b3260c94ede37a33a521e3d74a08cf59d863c Mon Sep 17 00:00:00 2001 From: MscBaiMeow Date: Fri, 6 Mar 2020 10:39:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoFish.go | 4 ++-- conf.json | 31 +++++-------------------------- go.mod | 2 +- go.sum | 4 ++-- mclogin/login.go | 41 ++++++++++++++++++++++------------------- 5 files changed, 32 insertions(+), 50 deletions(-) diff --git a/AutoFish.go b/AutoFish.go index 4b52239..e6283dc 100644 --- a/AutoFish.go +++ b/AutoFish.go @@ -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") @@ -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" { diff --git a/conf.json b/conf.json index 2d0855d..960f7da 100644 --- a/conf.json +++ b/conf.json @@ -1,36 +1,15 @@ { "players": [ - { - "name": "bs1", - "UUID": "", - "AsTk": "", - "account": "", - "authserver": "", - "authmode": "Offline" - }, { "name": "Msc__BaiMeow", "UUID": "1ef88718148741cb8f5770e01fd55ef7", - "AsTk": "ffffffffffffffffffffffffffffffff", - "account": "100000@qq.com", + "Tokens": { + "accessToken": "eyJhbpciOiJIUzI1NiJ9.eyJzdWmiOiIxNTBiY2d0N2Q4MGUxZmNkOWUwZDM5YmY1Yzk0NzhhMiIsInlnZ3QiOiI5NzViNDgwNTdhMDg0ZDcyYjk0N2I1NzQxOTBhYWRhYyIsInNwciI6IjFlZjg4NzE4MTQ4NzQxY2I4ZjU3NzBlMDFmZDU1ZWY3IiwiaXNzIjoiWWdnZHJhc2lsLUF1dGgiLCJleHAiOjE1ODM2MzIzNTYsImlhdCI6MTU4MzQ1OTU1Nn0.WMtYlGEhIv3Ex4roPEmbEL5zdI-i1IfypQ1nr5r1Vo4", + "clientToken": "1ca41fra-6f49-4b67-8bb5-4c432be98633" + }, + "account": "10000@qq.com", "authserver": "https://authserver.mojang.com", "authmode": "MojangAuth" - }, - { - "name": "bs2", - "UUID": "", - "AsTk": "", - "account": "", - "authserver": "", - "authmode": "Offline" - }, - { - "name": "bs3", - "UUID": "", - "AsTk": "", - "account": "", - "authserver": "", - "authmode": "Offline" } ] } \ No newline at end of file diff --git a/go.mod b/go.mod index 4d5096f..75462ba 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b29c9e7..8751557 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/mclogin/login.go b/mclogin/login.go index 9bb136d..06f59d6 100644 --- a/mclogin/login.go +++ b/mclogin/login.go @@ -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 @@ -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 @@ -49,13 +49,13 @@ 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 @@ -63,7 +63,7 @@ func Authlogin(account, authserver *string, auth *Player) { selected string ) //把安排survey包的单选中的选项所需要的切片搞出来 - for _, v := range resp.AvailableProfiles() { + for _, v := range access.AvailableProfiles() { preSelected = append(preSelected, fmt.Sprintf("[%d]", no)+v.Name) no++ } @@ -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 } @@ -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) @@ -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) @@ -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 @@ -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) @@ -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)