├── .gitattributes ├── LICENSE ├── README.md └── dofuswebapi.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Foohx (Robin G.) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DofusWeb API 2 | 3 | DofusWeb API est une petite librairie HTTP non officiel vous permettant d'intéragir avec les services web de la société Ankama. 4 | 5 | * Connexion/Déconnexion sur [dofus.com](http://dofus.com/fr) 6 | * Récupération du Pseudo 7 | * Récupération de l'abonnement et de la date d'expiration 8 | * Récupération des Ogrines 9 | * Récupération des Kroz 10 | * Récupération nombre d'Ankabox 11 | * Listing des personnages (Nom, Race, Niveau et Serveur) 12 | * Connexion/Déconnexion sur [account.ankama.com](https://account.ankama.com) (Gestion de compte) 13 | * Indication SHIELD activé ou non 14 | * Indication compte certifié ou non 15 | * Obtention de l'identifiant 16 | * Obtention de l'identité (Nom, Prénom ainsi que Date de naissance) 17 | * Obtention de l'email 18 | * Obtention des numéros de téléphone 19 | * Obtention du mot de passe (caché) 20 | * Obtention de l'adresse postal principale 21 | * Conservation de la connexion (refresh possible) 22 | * Sauvegarde des cookies (fichier) 23 | 24 | --- 25 | 26 | **Important**: Merci de respecter vos utilisateurs et de ne pas récupérer d'informations sans leur accord préalable !!! 27 | 28 | --- 29 | 30 | # Installation 31 | DofusWeb API requiert au minimum PHP `v5.4+` ainsi que l'extension `CURL`. 32 | 33 | ### Github 34 | 35 | Récupérer les sources de la librairie : 36 | 37 | ```bash 38 | $ git clone https://github.com/Foohx/DofusWeb-API.git 39 | ``` 40 | 41 | Puis l'inclure dans vos scripts : 42 | 43 | ```bash 44 | require_once '/path/to/lib/dofuswebapi.php'; 45 | ``` 46 | 47 | # Utilisation 48 | 49 | ### Initialiser la class 50 | 51 | Pour s'initialiser DofusWeb API à besoin de deux chaines de caractère. La première étant le nom de compte et la seconde étant le mot de passe. 52 | 53 | ```php 54 | $hDofus = new DofusWeb_API('username', 'password'); 55 | ``` 56 | 57 | Il faut ensuite définir un fichier qui va permettre de conserver la connexion au site : 58 | 59 | ```php 60 | $hDofus->setCookie('/path/to/file/for/cookie.txt') 61 | ``` 62 | 63 | Voilà ! Vous êtes maintenant prêt pour partir à la chasse aux informations. 64 | 65 | ### Collecter des informations sur Dofus.com 66 | 67 | Connexion au compte avec les identifiants précédents : 68 | 69 | ```php 70 | $hDofus->reqDofusLogin(); 71 | ``` 72 | 73 | Récupération des informations du compte : 74 | 75 | ```php 76 | $hDofus->collectDofusData(); 77 | ``` 78 | 79 | Vous pouvez accéder aux informations collecté via l'attribut `$dataDofus`. Cet attribut est un tableau multi-dimensionnel ayant pour structure : 80 | 81 | ```php 82 | array( 83 | 'account' => array( 84 | 'nickname' => 'Pseudo-Forum', 85 | 'subscription' => true/false, 86 | 'subs_expiration' => 'JJ/MM/AAAA', 87 | 'ogrines' => 1337, 88 | 'kroz' => 137, 89 | 'ankabox' => 0, 90 | ), 91 | 'characters' => array( 92 | array( 93 | 'class' => 'Zobal', 94 | 'level' => 10, 95 | 'name' => 'NomPerso 1', 96 | 'server' => 'NomDuServeur' 97 | ), 98 | array( 99 | 'class' => 'Cra', 100 | 'level' => 94, 101 | 'name' => 'NomPerso 2', 102 | 'server' => 'NomDuServeur' 103 | ), 104 | array( 105 | 'class' => 'NomRace', 106 | 'level' => 200, 107 | 'name' => 'NomPerso 3', 108 | 'server' => 'NomDuServeur' 109 | ) 110 | // etc.. 111 | ) 112 | ); 113 | ``` 114 | 115 | Il est désormais possible de récupérer les Kamas (montant disponible par serveur) en bourse à l'aide de la fonction : 116 | 117 | ```php 118 | $hDofus->collectDofusData_Bourse(); 119 | ``` 120 | 121 | L'appel précédent doit être fait uniquement après un `$hDofus->collectDofusData();` ! 122 | Ainsi l'attribut `$dataDofus` se verra modifier de la sorte : 123 | 124 | ```php 125 | array( 126 | 'account' => array( 127 | 'nickname' => 'Pseudo-Forum', 128 | 'subscription' => true/false, 129 | 'subs_expiration' => 'JJ/MM/AAAA', 130 | 'ogrines' => 1337, 131 | 'kroz' => 137, 132 | 'ankabox' => 0, 133 | ), 134 | 'characters' => array( 135 | array( 136 | 'class' => 'Zobal', 137 | 'level' => 10, 138 | 'name' => 'NomPerso 1', 139 | 'server' => 'NomDuServeur' 140 | ) 141 | // etc.. 142 | ), 143 | 'bourse' => array( 144 | array( 145 | 'server' => 'Helsephine' 146 | 'kamas' => 851638 147 | ), 148 | array( 149 | 'server' => 'Hyrkul' 150 | 'kamas' => 0 151 | ) 152 | // etc.. 153 | ) 154 | ); 155 | ``` 156 | 157 | 158 | Pour les néophytes le tableau s'utilise ainsi : 159 | 160 | ```php 161 | echo "Ogrines : " . $hDofus->dataDofus['account']['ogrines'] . "
"; 162 | echo "Kroz : " . $hDofus->dataDofus['account']['kroz'] . "
"; 163 | // ... 164 | echo "Perso 1 : " . $hDofus->dataDofus['characters'][0]['name'] . "
"; 165 | echo "Niveau : " . $hDofus->dataDofus['characters'][0]['level'] . "
"; 166 | echo "Perso 2 : " . $hDofus->dataDofus['characters'][1]['name'] . "
"; 167 | echo "Niveau : " . $hDofus->dataDofus['characters'][1]['level'] . "
"; 168 | // etc... 169 | ``` 170 | 171 | Si vous voulez lister tous les personnages ou compter combien le compte en possède : 172 | 173 | ```php 174 | $nombrePersonnages = count($hDofus->dataDofus['characters']); 175 | for ($i=0; $i < $nombrePersonnages; $i++) 176 | { 177 | echo "Race : " . $hDofus->dataDofus['characters'][$i]['class'] . "
"; 178 | echo "Nom : " . $hDofus->dataDofus['characters'][$i]['name'] . "
"; 179 | echo "Niveau : " . $hDofus->dataDofus['characters'][$i]['level'] . "
"; 180 | echo "Serveur : " . $hDofus->dataDofus['characters'][$i]['server'] . "

"; 181 | } 182 | ``` 183 | 184 | Une fois que vous en avez terminé avec les requêtes vous pouvez clore votre session en vous déconnectant : 185 | 186 | ```php 187 | $hDofus->reqAnkamaLogout(); 188 | ``` 189 | 190 | ### Collecter des informations sur Ankama.com 191 | 192 | ```php 193 | $hDofus->reqAnkamaLogin(); 194 | $hDofus->reqAnkamaHome(); 195 | $hDofus->collectAnkamaData(); 196 | $hDofus->reqAnkamaLogout(); 197 | ``` 198 | 199 | Structure de l'attribut `$dataAccount` : 200 | 201 | ```php 202 | array( 203 | 'security' => 0, 204 | 'account' => array( 205 | 'nickname' => 'Pseudo-Forum', 206 | 'firstname' => 'Prénom', 207 | 'lastname' => 'Nom', 208 | 'birth' => 'JJ Mois AAAA', 209 | 'email' => 'email@exemple.com', 210 | 'portable' => '06******00', 211 | 'fixe' => '05******00', 212 | 'password' => '**********', 213 | 'address' => 'ADRESSE | POSTALE | CP | VILLE', 214 | 'certified' => true / false 215 | ) 216 | ); 217 | ``` 218 | 219 | Exemple : 220 | 221 | ```php 222 | echo "Bonjour Mr. " . $hDofus->dataAccount['account']['lastname'] . "
"; 223 | echo "Votre email de contact : " . $hDofus->dataAccount['account']['email'] . "
"; 224 | 225 | if ($hDofus->dataAccount['security'] == 3) 226 | echo "Votre compte est protégé par le SHIELD !"; 227 | ``` 228 | 229 | ### Bourse aux Kamas / Ankama SHIELD 230 | 231 | Si vous souhaitez accéder à la bourse aux Kamas et que votre compte possède le SHIELD d'activé, il est possible de passer outre ! 232 | 233 | Dans un premier temps, on essaye d'accéder normalement à la bourse. 234 | Si la fonction `collectDofusData_Bourse()` nous informe dans les `errors` qu'une protection SHIELD est présente, alors on demande un code par email : 235 | 236 | ```php 237 | $hDofus = new DofusWeb_API('username', 'password'); 238 | 239 | $hDofus->setCookie('cookie.txt'); 240 | 241 | $r = $hDofus->reqDofusLogin(); 242 | $hDofus->collectDofusData(); 243 | $r = $hDofus->collectDofusData_Bourse(); 244 | if ($r == False && in_array('Protected by shield !', $hDofus->errors)){ 245 | print("SHIELD detected !\n"); 246 | $hDofus->ShieldCode(); // Demande du code par mail pour dévérouiller le SHIELD 247 | } 248 | ``` 249 | 250 | Une fois le code reçu dans votre boite, il ne faut pas vous reconnecter comme habituellement. Le fichier de cookie permet de conserver votre SESSION et donc de rester connecté. De plus aucune requête ne doit être effectuée avant la validation du code. 251 | 252 | Dans le code suivant, on ajoute donc l'option `false` en second paramètres à setCookie(), ceci aura pour effet de ne pas générer une nouvelle connexion ! 253 | 254 | ```php 255 | $hDofus = new DofusWeb_API('username', 'password'); 256 | 257 | $hDofus->setCookie('cookie.txt', false); // On souhaite conserver notre cookie précédent, d'ou le false ici ! 258 | 259 | $hDofus->ShieldValidate("V8TUST"); // V8TUST est le code reçu précédemment par mail 260 | $hDofus->collectDofusData(); 261 | $r = $hDofus->collectDofusData_Bourse(); 262 | if ($r == False && in_array('Protected by shield !', $hDofus->errors)){ 263 | print("SHIELD detected !\n"); 264 | $hDofus->ShieldCode(); 265 | } else { 266 | print("No SHIELD detected !\n"); 267 | } 268 | ``` 269 | 270 | Ajouté suite à une demande de [@Reptiluka](https://twitter.com/Reptiluka) 271 | 272 | # Class 273 | 274 | ### Attributs 275 | 276 | * `body` - Contient le code source de la dernière requête effectué 277 | * `code` - Code HTTP de la dernière requête 278 | * `dataAccount` - Informations extraites du site account.ankama.com 279 | * `dataDofus` - Informations extraite du site dofus.com 280 | * `errors` - Contient une liste d'erreurs (array) 281 | 282 | ### Fonctions 283 | 284 | Toutes ces fonctions retournent `true` en cas de succès ou `false` en cas d'échec. Les fonctions débutant par `req` effectuent des requêtes HTTP et retourne des informations dans `body` et `code`. En cas de problèmes / d'erreurs des détails sont disponible dans l'attribut `errors` 285 | 286 | * `askIsConnected($reload=false)` - Vérifie que l'utilisateur est connecté 287 | * `collectAnkamaData()` - Récupère des informations et le stock dans `dataAccount` 288 | * `collectDofusData()` - Récupère des informations et le stock dans `dataDofus` 289 | * `collectDofusData_Bourse()` - Récupère des informations de la bourse aux Kamas (un appel à `collectDofusData()` est necéssaire avant !) 290 | * `setCookie($path_to_file)` - Indique dans quel fichier stocker les cookies 291 | * `setLogin($username, $password)` - Permet de changer les identifiants de connexion 292 | * `getCookie()` - Récupère le nom du fichier de cookie courant 293 | * `getLogin()` - Récupère les identifiants de connexion de la class 294 | * `reqAnkamaHome()` - Execute une requête `GET` sur la page d'accueil d'Ankama 295 | * `reqAnkamaLogin()` - Execute une requête `POST` afin de s'identifier sur Ankama 296 | * `reqAnkamaLogout()` - Execute une requête `GET` afin de se déconnecter d'Ankama 297 | * `reqDofusHome()` - Execute une requête `GET` sur la page d'accueil de Dofus 298 | * `reqDofusLogin()` - Execute une requête `POST` afin de s'identifier sur Dofus 299 | * `reqDofusLogout()` - Execute une requête `GET` afin de se déconnecter de Dofus 300 | * `ShieldCode()` - Envoi un `mail` contenant un `code` pour dévérouiller le SHIELD 301 | * `ShieldValidate($code)` - Valide le `code` reçu par `mail` grâce à la fonction `ShieldCode()` 302 | -------------------------------------------------------------------------------- /dofuswebapi.php: -------------------------------------------------------------------------------- 1 | setLogin($username, $password); 22 | } 23 | public function __destruct() 24 | { 25 | if (@file_exists($rhis->cookie)) 26 | { 27 | @unlink($this->_cookie); 28 | } 29 | } 30 | 31 | public function askIsConnected($reload=false) 32 | { 33 | if ($reload) 34 | { 35 | // Reload Ankama or Dofus Homepage ! 36 | } 37 | if (preg_match('#Gestion de compte.*?#', $this->body)) 38 | return true; 39 | return false; 40 | } 41 | 42 | public function collectAnkamaData() 43 | { 44 | $this->errors = array(); 45 | if (!$this->askIsConnected()) 46 | { 47 | $this->errors[] = "Not connected !"; 48 | return false; 49 | } 50 | $r = NULL; 51 | if (($r = $this->_askAnkamaAccess()) == self::ACCESS_FAIL) 52 | { 53 | $this->errors[] = "Not connected !"; 54 | return false; 55 | } 56 | $this->dataAccount['security'] = $r; 57 | if ($r != self::ACCESS_DONE) 58 | return false; 59 | $this->dataAccount['account'] = $this->_parseAnkamaAccount(); 60 | return true; 61 | } 62 | 63 | public function collectDofusData() 64 | { 65 | $this->errors = array(); 66 | if (!$this->askIsConnected()) 67 | { 68 | $this->errors[] = "Not connected !"; 69 | return false; 70 | } 71 | $this->dataDofus['account'] = $this->_parseDofusAccount(); 72 | $this->dataDofus['characters'] = $this->_parseDofusCharacters(); 73 | //$this->dataDofus['notifications'] = $this->_parseDofusNotifications(); 74 | return true; 75 | } 76 | 77 | public function ShieldCode() 78 | { 79 | $r = $this->reqOther('https://account.ankama.com/fr/securite/mode-restreint?f=https://secure.dofus.com/fr/achat-bourses-kamas-ogrines/selection-serveur'); 80 | $r = $this->_doRequest(array( 81 | 'url' => 'https://account.ankama.com/fr/securite/mode-restreint?f=https://secure.dofus.com/fr/achat-bourses-kamas-ogrines/selection-serveur', 82 | 'type' => 'POST', 83 | 'fields' => array( 84 | 'step' => 2 85 | ), 86 | 'cookie' => $this->_cookie 87 | )); 88 | } 89 | 90 | public function ShieldValidate($code, $name="API") 91 | { 92 | $r = $this->_doRequest(array( 93 | 'url' => 'https://account.ankama.com/fr/securite/mode-restreint?f=https://secure.dofus.com/fr/achat-bourses-kamas-ogrines/selection-serveur', 94 | 'type' => 'POST', 95 | 'fields' => array( 96 | 'step' => 3, 97 | 'security_code' => $code, 98 | 'security_browser' => $name 99 | ), 100 | 'cookie' => $this->_cookie 101 | )); 102 | $r = $this->reqOther('https://secure.dofus.com/fr/achat-bourses-kamas-ogrines/selection-serveur'); 103 | } 104 | 105 | public function collectDofusData_Bourse() 106 | { 107 | if (!is_array($this->dataDofus)) return false; 108 | $this->errors = array(); 109 | // Request 110 | $r = $this->reqOther('https://secure.dofus.com/fr/achat-bourses-kamas-ogrines/selection-serveur'); 111 | // Connected ? 112 | if (!$r && !$this->askIsConnected()) 113 | { 114 | $this->errors[] = "Not connected !"; 115 | return false; 116 | } 117 | $this->body = str_replace("\n", "", $this->body); 118 | // Shield ? 119 | if (preg_match_all('#shield#m', $this->body, $m)){ 120 | $this->errors = array(); 121 | $this->errors[] = "Protected by shield !"; 122 | return false; 123 | } 124 | // I Parse 125 | if (preg_match_all('#([A-Za-z- ]+)?<\/span>.*?ak-nb-kamas">([0-9 ]+)body, $m)) 126 | { 127 | if (!isset($m[1]) && !isset($m[2])) return false; 128 | $this->dataDofus['bourse'] = array(); 129 | for ($i=0; $i < count($m[1]); $i++) { 130 | $this->dataDofus['bourse'][] = array( 131 | 'server' => $m[1][$i], 132 | 'kamas' => intval(str_replace(" ", "", $m[2][$i])) 133 | ); 134 | } 135 | return true; 136 | } 137 | // O Parse 138 | return false; 139 | } 140 | 141 | public function setCookie($path_to_file, $new=True) 142 | { 143 | $this->errors = array(); 144 | $this->_cookie = $path_to_file; 145 | if ($new) { 146 | if (@file_put_contents($this->_cookie, "") === false) 147 | { 148 | $this->errors[] = "Can't create a cookie file."; 149 | $this->_cookie = NULL; 150 | return false; 151 | } 152 | } 153 | return true; 154 | } 155 | 156 | public function setLogin($username, $password) 157 | { 158 | $this->errors = array(); 159 | if (!is_string($username) || !is_string($password)) 160 | { 161 | $this->errors[] = "Parameters are not of type string."; 162 | return false; 163 | } 164 | $this->_login = array( 165 | 'user' => $username, 166 | 'pass' => $password 167 | ); 168 | return true; 169 | } 170 | 171 | public function getCookie() 172 | { 173 | return $this->_cookie; 174 | } 175 | 176 | public function getLogin() 177 | { 178 | return $this->_login; 179 | } 180 | 181 | public function reqOther($url) 182 | { 183 | $ret = $this->_doRequest(array( 184 | 'url' => $url, 185 | 'type' => 'GET', 186 | 'cookie' => $this->_cookie 187 | )); 188 | if (!$ret || $this->code != 200) 189 | return false; 190 | return true; 191 | } 192 | 193 | public function reqAnkamaHome() 194 | { 195 | $ret = $this->_doRequest(array( 196 | 'url' => 'https://account.ankama.com/fr/votre-compte/profil', 197 | 'type' => 'GET', 198 | 'cookie' => $this->_cookie 199 | )); 200 | if (!$ret || $this->code != 200) 201 | return false; 202 | return true; 203 | } 204 | 205 | public function reqAnkamaLogin() 206 | { 207 | $ret = $this->_doRequest(array( 208 | 'url' => 'https://account.ankama.com/sso', 209 | 'type' => 'POST', 210 | 'fields' => array( 211 | 'action' => "login", 212 | 'from' => "https://account.ankama.com/fr/profil/informations", 213 | 'postback' => 1, 214 | 'login' => $this->_login['user'], 215 | 'password' => $this->_login['pass'] 216 | ), 217 | 'cookie' => $this->_cookie 218 | )); 219 | if (!$ret || $this->code != 200) 220 | return false; 221 | return $this->askIsConnected(); 222 | } 223 | 224 | public function reqAnkamaLogout() 225 | { 226 | if (!$this->askIsConnected()) 227 | return true; 228 | $ret = $this->_doRequest(array( 229 | 'url' => 'https://account.ankama.com/sso?action=logout&from=https://account.ankama.com/fr/votre-compte/profil', 230 | 'type' => 'GET', 231 | 'cookie' => $this->_cookie 232 | )); 233 | if (!$ret || $this->code != 200) 234 | return false; 235 | return ($this->askIsConnected() ? false : true); 236 | } 237 | 238 | public function reqDofusHome() 239 | { 240 | $ret = $this->_doRequest(array( 241 | 'url' => 'http://www.dofus.com/fr', 242 | 'type' => 'GET', 243 | 'cookie' => $this->_cookie 244 | )); 245 | if (!$ret || $this->code != 200) 246 | return false; 247 | return true; 248 | } 249 | 250 | public function reqDofusLogin() 251 | { 252 | $ret = $this->_doRequest(array( 253 | 'url' => 'https://account.ankama.com/sso', 254 | 'type' => 'POST', 255 | 'fields' => array( 256 | 'action' => "login", 257 | 'from' => "http://www.dofus.com/fr", 258 | 'login' => $this->_login['user'], 259 | 'password' => $this->_login['pass'] 260 | ), 261 | 'cookie' => $this->_cookie 262 | )); 263 | if (!$ret || $this->code != 200) 264 | return false; 265 | if ($this->askIsConnected()) 266 | return true; 267 | // get error message 268 | $this->errors = array(); 269 | $matches = array(); 270 | if (preg_match('##', $this->body, $matches)) 271 | { 272 | $this->errors[] = $matches[1]; 273 | $this->errors[] = $matches[2]; 274 | } 275 | else 276 | $this->errors[] = "unknown"; 277 | return false; 278 | } 279 | 280 | public function reqDofusLogout() 281 | { 282 | if (!$this->askIsConnected()) 283 | return true; 284 | $ret = $this->_doRequest(array( 285 | 'url' => 'https://account.ankama.com/sso?action=logout&from=http://www.dofus.com/fr', 286 | 'type' => 'GET', 287 | 'cookie' => $this->_cookie 288 | )); 289 | if (!$ret || $this->code != 200) 290 | return false; 291 | return ($this->askIsConnected() ? false : true); 292 | } 293 | 294 | private function _askAnkamaAccess($reload=false) 295 | { 296 | $this->errors = array(); 297 | if ($reload) 298 | { 299 | if (!$this->reqAnkamaHome() || !$this->askIsConnected()) 300 | { 301 | $this->errors[] = "Reload failed or not connected."; 302 | return self::ACCESS_FAIL; 303 | } 304 | } 305 | else if (!$this->askIsConnected()) 306 | { 307 | $this->errors[] = "You need to be connected."; 308 | return self::ACCESS_FAIL; 309 | } 310 | if (preg_match('#PRESENTATION DES CGU#', $this->body)) 311 | { 312 | $this->errors[] = "!Access -> CGU"; 313 | return self::ACCESS_CGU; 314 | } 315 | if (preg_match('#Le mode restreint est activ#', $this->body)) 316 | { 317 | $this->errors[] = "!Access -> SHIELD"; 318 | return self::ACCESS_SHIELD; 319 | } 320 | return self::ACCESS_DONE; 321 | } 322 | 323 | private function _doRequest($options) 324 | { 325 | $this->code = NULL; 326 | $this->body = NULL; 327 | $this->errors = array(); 328 | 329 | if (empty($options['url'])) 330 | return false; 331 | if (!isset($options['useragent'])) 332 | $options['useragent'] = "Mozilla 5.0"; 333 | $hc = curl_init($options['url']); 334 | curl_setopt($hc, CURLOPT_FRESH_CONNECT, true); 335 | curl_setopt($hc, CURLOPT_SSL_VERIFYPEER, false); 336 | curl_setopt($hc, CURLOPT_SSL_VERIFYHOST, 0); 337 | curl_setopt($hc, CURLOPT_FOLLOWLOCATION, true); 338 | curl_setopt($hc, CURLOPT_RETURNTRANSFER, true); 339 | curl_setopt($hc, CURLOPT_COOKIEJAR, realpath($options['cookie'])); 340 | curl_setopt($hc, CURLOPT_COOKIEFILE, realpath($options['cookie'])); 341 | curl_setopt($hc, CURLOPT_USERAGENT, $options['useragent']); 342 | if (isset($options['type']) && $options['type'] == 'POST') 343 | { 344 | curl_setopt($hc, CURLOPT_POST, true); 345 | curl_setopt($hc, CURLOPT_POSTFIELDS, $options['fields']); 346 | } 347 | if (($this->body = utf8_decode(curl_exec($hc))) === false) 348 | $this->errors[] = curl_error($hc); 349 | $this->code = curl_getinfo($hc, CURLINFO_HTTP_CODE); 350 | curl_close($hc); 351 | return true; 352 | } 353 | 354 | private function _parseAnkamaAccount() 355 | { 356 | $r_array = array(); 357 | $matches = array(); 358 | 359 | preg_match_all('#
(.*?)
#s', $this->body, $matches); 360 | $sub_matches = array(); 361 | if (preg_match('#(.*?)#', $matches[1][0], $sub_matches)) 362 | $r_array['nickname'] = $sub_matches[1]; 363 | else 364 | $r_array['nickname'] = NULL; 365 | if (preg_match('#(.*?) (.*?).*?le(.*?)
#s', $matches[1][1], $sub_matches)) 366 | { 367 | $r_array['firstname'] = $sub_matches[1]; 368 | $r_array['lastname'] = $sub_matches[2]; 369 | $r_array['birth'] = trim($sub_matches[3]); 370 | } 371 | else 372 | { 373 | $r_array['firstname'] = NULL; 374 | $r_array['lastname'] = NULL; 375 | $r_array['birth'] = NULL; 376 | } 377 | if (preg_match('#(.*?)#', $matches[1][2], $sub_matches)) 378 | $r_array['email'] = $sub_matches[1]; 379 | else 380 | $r_array['email'] = NULL; 381 | if (preg_match('#portable.*?(.*?).*?fixe.*?(.*?)#s', $matches[1][3], $sub_matches)) 382 | { 383 | $r_array['portable'] = $sub_matches[1]; 384 | $r_array['fixe'] = $sub_matches[2]; 385 | } 386 | else 387 | { 388 | $r_array['portable'] = NULL; 389 | $r_array['fixe'] = NULL; 390 | } 391 | $r_array['password'] = trim($matches[1][4]); 392 | $r_array['address'] = explode('
', trim($matches[1][5])); 393 | $r_array['address'][count($r_array['address'])-1] = explode("Compte certifi.{1}
#s', $matches[1][7])) 403 | $r_array['certified'] = false; 404 | else 405 | $r_array['certified'] = true; 406 | return $r_array; 407 | } 408 | 409 | private function _parseDofusAccount() 410 | { 411 | $r_array = array(); 412 | $matches = array(); 413 | // Read Nickname 414 | if (preg_match('#class="ak-infos-nickname">(.*?)#', $this->body, $matches)) 415 | $r_array['nickname'] = $matches[1]; 416 | else 417 | $r_array['nickname'] = NULL; 418 | // Read Subscription 419 | if (preg_match('#subscribe">(.*?)DOFUS#s', $this->body, $matches)) 420 | { 421 | $r_array['subscription'] = trim(html_entity_decode($matches[1])); 422 | if (preg_match('#^Non Abo#', $r_array['subscription'])) 423 | $r_array['subscription'] = false; 424 | else 425 | $r_array['subscription'] = true; 426 | } 427 | else 428 | $r_array['subscription'] = NULL; 429 | if (preg_match('#jusqu\'au (.*?)#', $this->body, $matches)) 430 | $r_array['subs_expiration'] = trim($matches[1]); 431 | else 432 | $r_array['subs_expiration'] = NULL; 433 | // Read Ogrines, Kroz and Ankabox 434 | if (preg_match_all ('#
(.*?)
#s', $this->body, $matches)) 435 | { 436 | foreach ($matches[1] as $string){ 437 | $rmatches = array(); 438 | if (preg_match('#class="ak-infos-title">([a-zA-Z]*).*?: .*?class="ak-infos-nb">(.*?)#s', $string, $rmatches)) 439 | $r_array[strtolower(trim( htmlentities(preg_replace("/\s/",'',html_entity_decode($rmatches[1]))) ))] = $rmatches[2]; 440 | } 441 | } 442 | return $r_array; 443 | } 444 | 445 | private function _parseDofusCharacters() 446 | { 447 | $r_array = array(); 448 | $matches = array(); 449 | // Read Class and Level 450 | if (!preg_match_all ('#
(.*?)
#s', $this->body, $matches)) 451 | return $r_array; 452 | foreach ($matches[1] as $v) { 453 | $index = count($r_array); 454 | $parse = explode(' -', $v); 455 | $r_array[$index]['class'] = $parse[0]; 456 | $parse = explode(' : ', $v); 457 | $r_array[$index]['level'] = intval($parse[1]); 458 | } 459 | // Read Name 460 | if (!preg_match_all('#
.*?(.*?)#s', $this->body, $matches)) 461 | return $r_array; 462 | $index = 0; 463 | foreach ($matches[1] as $v) { 464 | $r_array[$index]['name'] = $v; 465 | $index += 1; 466 | } 467 | // Read Server 468 | if (!preg_match_all('#
(.*?)
#s', $this->body, $matches)) 469 | return $r_array; 470 | $index = 0; 471 | foreach ($matches[1] as $v) { 472 | $r_array[$index]['server'] = $v; 473 | $index += 1; 474 | } 475 | $temp = array(); 476 | foreach ($r_array as $key => $row) 477 | $temp[$key] = $row['level']; 478 | array_multisort($temp, SORT_DESC, $r_array); 479 | return $r_array; 480 | } 481 | 482 | /* 483 | private function _parseDofusNotifications() 484 | { 485 | $this->notifications = array(); 486 | 487 | $matches = array(); 488 | if (!preg_match_all ('#
(.*?)
#s', $this->body, $matches)) 489 | return false; 490 | foreach ($matches[1] as $v) { 491 | $index = count($this->notifications); 492 | $this->notifications[$index]['note'] = $v; 493 | } 494 | return true; 495 | } 496 | */ 497 | } 498 | --------------------------------------------------------------------------------