improve: 实装嗅探 acid

This commit is contained in:
Mmx233
2023-06-04 20:49:28 +08:00
parent af3b4d6439
commit 83795db39e
4 changed files with 23 additions and 10 deletions

View File

@@ -9,10 +9,6 @@ import (
)
func main() {
if global.Flags.AutoAcid {
//todo detect acid
}
if global.Config.Settings.Guardian.Enable {
//进入守护模式
controllers.Guardian()

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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()
}