Skip to content

Commit

Permalink
Merge branch 'release/42.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Jun 15, 2020
2 parents 9d6a9d2 + 6c99cf0 commit 9c811b8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func Register(email, password, proxyAddr, proxyUsername, proxyPassword, proxyTyp
return nil
}

func AddAccount(username, password, universe, lang string, proxyAddr, proxyUsername, proxyPassword, proxyType string) (NewAccount, error) {
func AddAccount(username, password, otpSecret, universe, lang, proxyAddr, proxyUsername, proxyPassword, proxyType string) (NewAccount, error) {
var newAccount NewAccount
var err error
client := &http.Client{}
Expand All @@ -249,7 +249,7 @@ func AddAccount(username, password, universe, lang string, proxyAddr, proxyUsern
if err != nil {
return newAccount, err
}
postSessionsRes, err := postSessions2(client, gameEnvironmentID, platformGameID, username, password)
postSessionsRes, err := postSessions2(client, gameEnvironmentID, platformGameID, username, password, otpSecret)
if err != nil {
return newAccount, err
}
Expand Down Expand Up @@ -885,7 +885,7 @@ func postSessions(b *OGame, gameEnvironmentID, platformGameID, username, passwor
return out, nil
}

func postSessions2(client *http.Client, gameEnvironmentID, platformGameID, username, password string) (postSessionsResponse, error) {
func postSessions2(client *http.Client, gameEnvironmentID, platformGameID, username, password, otpSecret string) (postSessionsResponse, error) {
var out postSessionsResponse
payload := url.Values{
"autoGameAccountCreation": {"false"},
Expand All @@ -901,6 +901,20 @@ func postSessions2(client *http.Client, gameEnvironmentID, platformGameID, usern
return out, err
}

if otpSecret != "" {
passcode, err := totp.GenerateCodeCustom(otpSecret, time.Now(), totp.ValidateOpts{
Period: 30,
Skew: 1,
Digits: otp.DigitsSix,
Algorithm: otp.AlgorithmSHA1,
})
if err != nil {
return out, err
}
req.Header.Add("tnt-2fa-code", passcode)
req.Header.Add("tnt-installation-id", "")
}

req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Accept-Encoding", "gzip, deflate, br")

Expand Down

0 comments on commit 9c811b8

Please sign in to comment.