improve: 完成对主程序登录函数的改造

This commit is contained in:
Mmx233
2022-10-21 14:40:31 +08:00
parent 16e207b8e2
commit 7a7323691a
3 changed files with 36 additions and 9 deletions

View File

@@ -29,7 +29,7 @@ func Guardian() {
_ = recover()
}()
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
e := Login(nil)
e := Login(nil, true)
if e != nil {
log.Errorln("登录出错: ", e)
}
@@ -38,7 +38,7 @@ func Guardian() {
if e == nil {
for _, eth := range interfaces {
log.Debugf("使用 %s 网口登录 ", eth.Name)
e = Login(eth.Addr)
e = Login(eth.Addr, true)
if e != nil {
log.Errorln("网口 ", eth.Name+" 登录出错: ", e)
}

View File

@@ -4,17 +4,44 @@ import (
"github.com/Mmx233/BitSrunLoginGo/global"
"github.com/Mmx233/BitSrunLoginGo/util"
BitSrun "github.com/Mmx233/BitSrunLoginGo/v1"
log "github.com/sirupsen/logrus"
"net"
)
// Login 登录逻辑
func Login(localAddr net.Addr) error {
return BitSrun.Login(&BitSrun.Conf{
func Login(localAddr net.Addr, debugOutput bool) error {
conf := &BitSrun.Conf{
Https: global.Config.Settings.Basic.Https,
LoginInfo: BitSrun.LoginInfo{
Form: &global.Config.Form,
Meta: &global.Config.Meta,
},
Client: util.HttpTools(localAddr).Client,
})
}
var output func(args ...interface{})
if debugOutput {
output = log.Debugln
} else {
output = log.Infoln
}
output("正在获取登录状态")
online, ip, e := BitSrun.LoginStatus(conf)
if e != nil {
return e
}
log.Debugln("认证客户端 ip: ", ip)
if online {
output("已登录~")
return nil
} else {
output("检测到用户未登录,开始尝试登录...")
return BitSrun.DoLogin(ip, conf)
}
}

View File

@@ -19,7 +19,7 @@ func main() {
//登录流程
var err error
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
if err = controllers.Login(nil); err != nil {
if err = controllers.Login(nil, false); err != nil {
log.Errorln("登录出错: ", err)
if !global.Config.Settings.Log.DebugLevel {
fmt.Printf("开启调试日志debug_level获取详细信息")
@@ -27,11 +27,11 @@ func main() {
return
}
} else { //多网卡
log.Debugln("多网卡模式")
log.Infoln("多网卡模式")
interfaces, _ := util.GetInterfaceAddr()
for _, eth := range interfaces {
log.Debugln("使用网卡: ", eth.Name)
if err = controllers.Login(eth.Addr); err != nil {
log.Infoln("使用网卡: ", eth.Name)
if err = controllers.Login(eth.Addr, false); err != nil {
log.Errorln("登录出错: ", err)
}
}