From 28c2a358e6cf80edeb7ca894e9b26b98e08e833d Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Sat, 6 Aug 2022 20:17:08 -0700 Subject: [PATCH] simplify code --- ogame.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/ogame.go b/ogame.go index aa685072..6b476770 100644 --- a/ogame.go +++ b/ogame.go @@ -1113,27 +1113,23 @@ func postSessions(b *OGame, gameEnvironmentID, platformGameID, username, passwor parts := strings.Split(gfChallengeIDValue, ";") challengeID = parts[0] - if tried { + if tried || b.captchaCallback == nil { return out, errors.New("captcha required, " + challengeID) } tried = true - if b.captchaCallback != nil { - questionRaw, iconsRaw, err := startCaptchaChallenge(b.Client, challengeID) - if err != nil { - return out, errors.New("failed to start captcha challenge: " + err.Error()) - } - answer, err := b.captchaCallback(questionRaw, iconsRaw) - if err != nil { - return out, errors.New("failed to get answer for captcha challenge: " + err.Error()) - } - if err := solveChallenge(b.Client, challengeID, answer); err != nil { - return out, errors.New("failed to solve captcha challenge: " + err.Error()) - } - continue + questionRaw, iconsRaw, err := startCaptchaChallenge(b.Client, challengeID) + if err != nil { + return out, errors.New("failed to start captcha challenge: " + err.Error()) } - - return out, errors.New("captcha required, " + challengeID) + answer, err := b.captchaCallback(questionRaw, iconsRaw) + if err != nil { + return out, errors.New("failed to get answer for captcha challenge: " + err.Error()) + } + if err := solveChallenge(b.Client, challengeID, answer); err != nil { + return out, errors.New("failed to solve captcha challenge: " + err.Error()) + } + continue } }