* Fix: Relogin with existing Cookie and prevent Full Login to Lobby if we have a valid Session Cookie for the lobby.
@@ -774,6 +774,8 @@ func (b *OGame) loginWithExistingCookies() (bool, error) {
for _, c := range cookies {
if c.Name == gfTokenCookieName {
token = c.Value
+ b.token = "Bearer " + c.Value
+ b.debug("found token " + b.token)
break
}
}
@@ -789,23 +791,41 @@ func (b *OGame) loginWithExistingCookies() (bool, error) {
return false, err
}
if err != nil {
+ b.debug("session not found")
err := b.login()
return false, err
}
-
if err := b.loginPart2(server, userAccount); err != nil {
return false, err
}
-
vals := url.Values{"page": {"ingame"}, "component": {OverviewPage}}
pageHTML, err := b.getPageContent(vals, SkipRetry)
if err != nil {
if err == ErrNotLogged {
- err := b.login()
+ b.debug("get login link")
+ loginLink, err := getLoginLink(b, userAccount, token)
+ if err != nil {
+ return true, err
+ }
+ pageHTML, err := execLoginLink(b, loginLink)
+ if err != nil {
+ return true, err
+ }
+ pageHTML, err = b.getPageContent(vals, SkipRetry)
+ b.debug("login using existing cookies")
+ if err := b.loginPart3(userAccount, pageHTML); err != nil {
return false, err
}
+ if err := b.Client.Jar.(*cookiejar.Jar).Save(); err != nil {
return false, err
}
+ b.debug("Cookies has been saved ")
+ for _, fn := range b.interceptorCallbacks {
+ fn("GET", loginLink, nil, nil, pageHTML)
+ }
+ return true, nil
+ }
+ }
b.debug("login using existing cookies")
if err := b.loginPart3(userAccount, pageHTML); err != nil {
return false, err
