From 83795db39e0f09890842752e0d5383b76860fcad Mon Sep 17 00:00:00 2001 From: Mmx233 Date: Sun, 4 Jun 2023 20:49:28 +0800 Subject: [PATCH] =?UTF-8?q?improve:=20=E5=AE=9E=E8=A3=85=E5=97=85=E6=8E=A2?= =?UTF-8?q?=20acid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/bitsrun/main.go | 4 ---- internal/controllers/login.go | 20 +++++++++++++++++--- pkg/srun/api.go | 1 - pkg/srun/srun.go | 8 ++++++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/cmd/bitsrun/main.go b/cmd/bitsrun/main.go index 02e52f8..c885049 100644 --- a/cmd/bitsrun/main.go +++ b/cmd/bitsrun/main.go @@ -9,10 +9,6 @@ import ( ) func main() { - if global.Flags.AutoAcid { - //todo detect acid - } - if global.Config.Settings.Guardian.Enable { //进入守护模式 controllers.Guardian() diff --git a/internal/controllers/login.go b/internal/controllers/login.go index 1c81205..3e385bc 100644 --- a/internal/controllers/login.go +++ b/internal/controllers/login.go @@ -13,13 +13,27 @@ import ( func Login(eth *tools.Eth, debugOutput bool) error { // 登录配置初始化 httpClient := tools.HttpPackSelect(eth).Client - conf := &srun.Conf{ + srunClient := srun.New(&srun.Conf{ Https: global.Config.Settings.Basic.Https, LoginInfo: srun.LoginInfo{ Form: global.Config.Form, Meta: global.Config.Meta, }, Client: httpClient, + }) + + // 嗅探 acid + if global.Flags.AutoAcid { + log.Debugln("开始嗅探 acid") + acid, e := srunClient.DetectAcid() + if e != nil { + log.Errorf("嗅探 acid 失败,使用配置 acid: %v", e) + } else if acid == "" { + log.Errorln("找不到 acid,使用配置 acid") + } else { + log.Debugf("使用嗅探 acid: %s", acid) + srunClient.LoginInfo.Meta.Acid = acid + } } // 选择输出函数 @@ -32,7 +46,7 @@ func Login(eth *tools.Eth, debugOutput bool) error { output("正在获取登录状态") - online, ip, e := srun.LoginStatus(conf) + online, ip, e := srunClient.LoginStatus() if e != nil { return e } @@ -54,7 +68,7 @@ func Login(eth *tools.Eth, debugOutput bool) error { } else { log.Infoln("检测到用户未登录,开始尝试登录...") - if e = srun.DoLogin(ip, conf); e != nil { + if e = srunClient.DoLogin(ip); e != nil { return e } diff --git a/pkg/srun/api.go b/pkg/srun/api.go index bb91227..c8dd91e 100644 --- a/pkg/srun/api.go +++ b/pkg/srun/api.go @@ -81,7 +81,6 @@ func (a *Api) GetUserInfo() (map[string]interface{}, error) { // DetectAcid error 为 nil 的情况下 acid 可能为空 func (a *Api) DetectAcid() (string, error) { - fmt.Println("开始嗅探 Acid") addr := a.BaseUrl for { log.Debugln("HTTP GET ", addr) diff --git a/pkg/srun/srun.go b/pkg/srun/srun.go index a9c8b99..90d1051 100644 --- a/pkg/srun/srun.go +++ b/pkg/srun/srun.go @@ -30,7 +30,7 @@ type Srun struct { api Api } -func (c *Srun) LoginStatus() (online bool, ip string, e error) { +func (c Srun) LoginStatus() (online bool, ip string, e error) { res, e := c.api.GetUserInfo() if e != nil { return false, "", e @@ -59,7 +59,7 @@ func (c *Srun) LoginStatus() (online bool, ip string, e error) { return } -func (c *Srun) DoLogin(clientIP string) error { +func (c Srun) DoLogin(clientIP string) error { log.Debugln("正在获取 Token") if c.LoginInfo.Form.UserType != "" { @@ -125,3 +125,7 @@ func (c *Srun) DoLogin(clientIP string) error { return nil } + +func (c Srun) DetectAcid() (string, error) { + return c.api.DetectAcid() +}