Ill quickly explain the process of decoding captchas with the auth API. At the time of this post, it doesnt cost LG to decode a captcha (as it's currently only being used for testing purposes), however this will be updated in the future. It currently is only configured for recaptcha.

One final note: I'm not happy with how we keep having to send the user/pass combination to the server, and especially in plaintext. I'm going to rework all of this in the future, however I'll ensure that legacy calls are still properly processed, so it shouldn't be a concern.

--

So, basically the system works like this (I've been drawing diagrams all week for my IS class, thought I would do another :p)



So, like the diagram alludes to, you send the recaptcha key to the server, it sends back a system key, and then you use that system key to check with the server whether or not it has been solved. For instance, on the project I've been working on, I check every 5 seconds until it's solved.

Auth URLs

Send recaptcha key to server:
Code:
http://logicalgamers.com/auth/auth.php?user=&pass=&key=&gpc=&do=start&cid=
Breakdown:
  • User - logicalgamers username
  • Pass - logicalgamers password
  • key - your program key (will give you a % of LGG deducted from system)
  • gpc - random integer. Should be reasonably large
  • cid - recaptcha id. The value of the c variable in the following url:

Code:
http://api.recaptcha.net/image?c=03AHJ_VutAxHMf8TvDkgfn7to-Uj-JMlI3EkFAludzAL9LOA2QWyCu9jiA8xIJUmmuvXiGe5sr6k80a8QWj0ZjSWAo8RAoQn2Iz5sxSvAxoqZJviofoBqvZgjP2yNurak7XDZlCYy2n01Q3jkMrEt5BpSL6GfVQjq6tw
If you send the request properly it should give you a result similar to:
Code:
<return>
<sessionId>3dffff5e51205379d02d4ce88ec5ecca</sessionId>
</return>
The session id is important, so save that. It's a session unique to that individual captcha.

Checking on the captcha status
This is fairly simple once you have the captcha session id. Just send a call to:

Code:
http://logicalgamers.com/auth/auth.php?user=&pass=&key=&gpc=&do=status&csession=
All of the variables are same as the previous call, save csession, which is the captcha session id you retrieved in the previous step. If the captcha hasn't been found, it will output something similar to:

Code:
<return>
<error>Captcha not found</error>
</return>
The error message may change depending on the error. If the captcha has been found, it will output something similar to:
Code:
<return>
<captcha>captcha text</captcha>
</return>
Where the value of the captcha is found within the <captcha> tag.

Reporting an invalid captcha
If the captcha did not work (i.e. it was invalid), send an API call to:

Code:
http://logicalgamers.com/auth/auth.php?user=&pass=&key=&gpc=&do=invalid&csession=
Obviously filling out the variables. Our system will send a call back to deathbycaptcha and will ask for our money back.


Sample implementation code:

This is the code I've used in Python:

Class A:
Code:
    def initialiseCaptcha( self, captchaId ):
        # Captcha API url
        captchaApi = 'http://logicalgamers.com/auth/auth.php?user=' + self.lgDetails['username'] + '&pass=' + self.lgDetails['password'] + '&key=' + self.lgDetails['programKey'] + '&gpc=' + str( random.randint( 10000,1000000 ) ) + '&do=start&cid=' + captchaId

        # Retrieve the contents of the page
        pageHtml = self.openUrl( captchaApi )
        
        # Try to return
        try:
            captchaApiKey = re.findall( "\<sessionId\>([a-z0-9]{32})\<\/sessionId\>", pageHtml )
            
            # Return the server captcha API key
            return captchaApiKey[0]
            
        except:
            print "Unable to retrieve captcha session", captchaApiKey, pageHtml
            return ""
            
        
    def retrieveCaptcha( self, captchaSession ):
        # Captcha API url
        captchaApi = 'http://logicalgamers.com/auth/auth.php?user=' + self.lgDetails['username'] + '&pass=' + self.lgDetails['password'] + '&key=' + self.lgDetails['programKey'] + '&gpc=' + str( random.randint( 10000,1000000 ) ) + '&do=status&csession=' + captchaSession
        
        # Retrieve the contents of the page
        pageHtml = self.openUrl( captchaApi )
        
        if pageHtml.find( "<error>" ) >= 0:
            return ""
        else:
            captchaText = re.findall( "\<captcha\>(.*?)\<\/captcha\>", pageHtml )
            return captchaText[0]
            
    def reportInvalidCaptcha( self, captchaSession ):
        # Captcha API url
        captchaApi = 'http://logicalgamers.com/auth/auth.php?user=' + self.lgDetails['username'] + '&pass=' + self.lgDetails['password'] + '&key=' + self.lgDetails['programKey'] + '&gpc=' + str( random.randint( 10000,1000000 ) ) + '&do=invalid&csession=' + captchaSession
        
        # Retrieve the contents of the page
        pageHtml = self.openUrl( captchaApi )
        print "Invalid captcha", pageHtml
Initializing the captcha and retrieving the value:
Code:
   
    # Let's finish the game by sending our bucket to Gaia                
    def finishGame(self):

        print "finishGame function called"
        
        # Retrieve captcha function        
        def retrieveCaptcha():
            # For debugging purposes
            print "Fetching a new captcha"
            
            # Let's do some tests with the captcha
            captchaId = self.gaiaClass.getCaptcha()
                    
            # Let's connect to the logicalgamers API service
            captchaSession = self.gaiaClass.initialiseCaptcha( captchaId )
            
            # Let's try and get the value
            captchaText = ""
            curCount = 0
            
            # Loop through
            while captchaText == "":
                # For debugging purposes
                print "Waiting 5 seconds while we attempt to decode captcha"
                
                # If we've already tried (x) times, lets just break out and request a new captcha
                if curCount >= 6:
                    return ""
                
                # Increment the count
                curCount += 1
                
                # Sleep and then check on the status
                time.sleep( 5 )
                captchaText = self.gaiaClass.retrieveCaptcha( captchaSession )
            
            # Return the captcha    
            return captchaText
        
        # Let's loop through and fetch the captcha. If it's blank, we simply request another one
        captchaText = ""
        while captchaText == "":
            captchaText = retrieveCaptcha()
Detecting if the captcha was invalid:
Code:
                # Captcha was accepted
                if sushi[2] == "OK":
                    self.sendAttempts = 0
                    self.fishing = False
                    self.sendSushi([["19", self.seqID, "G_FISH_PLUGIN", "501", self.g_gameMD5, self.gaiaDetails["sessionId"]]])
                    
                # Captcha was not accepted
                else:
                    self.sendAttempts += 1
                    # It's failed. We've done it enough, let's just start a new game
                    if self.sendAttempts >= 4:
                        self.sendAttempts = 0
                        self.fishing = False
                        self.sendSushi([["19", self.seqID, "G_FISH_PLUGIN", "501", self.g_gameMD5, self.gaiaDetails["sessionId"]]])
                        
                    # Otherwise it's failed, let's just try it again
                    else:
                        # Try to send again
                        self.finishGame()
That's it. Questions? Just ask.