waylaidwanderer/PHP-SteamCommunity

Setting the CaptchaGID

Opened this issue · 1 comments

Hello! This is not an issue as such more of a improvement.

I was using this library to create a new steam account in one of my projects and ended up with the following:

    public function postCreate(Request $request) {

        $username = $request->username;
        $password = $request->password;
        $email    = $request->email;
        $captcha  = $request->captcha;
        $captchaid= $request->captchagid;

        if(!$username || !$password || !$email) {
            return array('error' => 'You\'re missing a required field');
        }

        $settings = [];
        $settings["username"] = $username;
        $settings["password"] = $password;

        $steam = new SteamCommunity($settings, dirname(__FILE__));

        if($captcha) {
            $steam->setCaptchaText($captcha, $captchaid);
        }

        $response = $steam->createAccount($email);

        if ($response == "NeedCaptcha") {
            return array(
                'error' => 'Need captcha',
                'CaptchaID' => $steam->getCaptchaGID(),
                'CaptchaLink' => $steam->getCaptchaLink()
            );
        }

        return $response;
    }

Note the line
$steam->setCaptchaText($captcha, $captchaid);

I had to modify your library so I could set the captcha GID as when you just use setCaptchaText it seems to fail without having the ID set. I understand you probably intended it to be used with ask() however I'm building it as an API so I can go to a single url with the required info and voilla.

I didn't want to create a pull request because I didn't know if you wanted to make a setter method as you have done with other things or wanted to add it in with the setCaptchaText I've included it with the function becuase if you're needing to set the captcha GID you're going to be entering some text presumably. But anyway here's my temp fix for now:

    /**
     * Set this after a captcha is encountered when logging in or creating an account.
     * @param string $captchaText
     * @param string $captchaGID
     */
    public function setCaptchaText($captchaText, $captchaGID = false)
    {
        if($captchaGID) {
            $this->captchaGID = $captchaGID;
        }

        $this->captchaText = $captchaText;
    }

I'll make a little PR if you want but I figured it was a small addition so why bother :p

That's odd, because the captcha GID should be automatically set, as per this line: https://github.com/waylaidwanderer/PHP-SteamCommunity/blob/master/SteamCommunity.php#L185

Can you try to reproduce this and then log the $captchaUrlResponse?