ManiaLib 1.0b1 API Reference

Source for file AuthenticationToken.class.php

Documentation is available at AuthenticationToken.class.php

  1. <?php
  2. /**
  3.  * @author Philippe Melot
  4.  * @copyright 2009-2010 NADEO
  5.  * @package ManiaLib
  6.  */
  7.  
  8. /**
  9.  * Manialink Authentication
  10.  * Helps using the Manialink Authentication System developped by NADEO.
  11.  * Note that it only works with United Forever accounts.
  12.  * @package ManiaLib
  13.  * @subpackage Authentication
  14.  */
  15. final class AuthenticationToken
  16. {
  17.     /**
  18.      * @ignore
  19.      */
  20.     const scriptUrl 'http://scripts.trackmaniaforever.com/checkAuthenticationToken.php?login=%s&token=%s';
  21.  
  22.     /**
  23.      * 
  24.      * Check if the login and the token are correct for the
  25.      * authentication
  26.      * 
  27.      * @param string $playerlogin 
  28.      * @param string $token 
  29.      * @throws AuthenticationTokenNoLoginException
  30.      * @throws AuthenticationTokenInvalidTokenException
  31.      * @throws AuthenticationTokenInvalidLoginException
  32.      * @throws AuthenticationNationsTokenUnknownPlayerException
  33.      * @throws AuthenticationTokenBadTokenException
  34.      * @throws AuthenticationTokenFailedException
  35.      * @return bool 
  36.      */
  37.     static function checkAuthenticationToken($playerlogin$token)
  38.     {
  39.         if(!$playerlogin)
  40.         throw new AuthenticationTokenNoLoginException();
  41.         if(!$token)
  42.         throw new AuthenticationTokenInvalidTokenException();
  43.         
  44.         $scriptUrl sprintf(self::scriptUrl,$playerlogin,$token);
  45.         
  46.         $response file_get_contents($scriptUrl);
  47.         
  48.         $error strstr('<errors>',$response);
  49.         
  50.         if(!$error)
  51.             return true;
  52.         
  53.         $error str_split($errorstrlenstrstr('</response>',$error) ) );
  54.         
  55.         switch($error)
  56.         {
  57.             case 7:     throw new AuthenticationTokenInvalidLoginException();
  58.                 break;
  59.             case 14:     throw new AuthenticationNationsTokenUnknownPlayerException();
  60.                 break;
  61.             case 166:    throw new AuthenticationTokenInvalidTokenException();
  62.                 break;
  63.             case 167:     throw new AuthenticationTokenBadTokenException();
  64.                 break;
  65.             default:    throw new AuthenticationTokenFailedException();
  66.         }
  67.     }
  68. }
  69.  
  70. /**
  71.  * @package ManiaLib
  72.  * @subpackage Authentication
  73.  * @ignore
  74.  */
  75. class AuthenticationTokenFailedException extends Exception {}
  76. /**
  77.  * @package ManiaLib
  78.  * @subpackage Authentication
  79.  * @ignore
  80.  */
  81. class AuthenticationTokenInvalidLoginException extends AuthenticationTokenFailedException {}
  82. /**
  83.  * @package ManiaLib
  84.  * @subpackage Authentication
  85.  * @ignore
  86.  */
  87. class AuthenticationTokenNoLoginException extends AuthenticationTokenFailedException {}
  88. /**
  89.  * @package ManiaLib
  90.  * @subpackage Authentication
  91.  * @ignore
  92.  */
  93. class AuthenticationTokenBadTokenException extends AuthenticationTokenFailedException {}
  94. /**
  95.  * @package ManiaLib
  96.  * @subpackage Authentication
  97.  * @ignore
  98.  */
  99. class AuthenticationTokenInvalidTokenException extends AuthenticationTokenFailedException {}
  100. /**
  101.  * @package ManiaLib
  102.  * @subpackage Authentication
  103.  * @ignore
  104.  */
  105. class AuthenticationNationsTokenUnknownPlayerException extends AuthenticationTokenFailedException {}
  106.  
  107. ?>