X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fthird_party%2Fapi%2Fwernisportal%2Fclass_WernisApi.php;h=5147f6aafe73adfe38fec1d92b99847ef49d221a;hb=fdc6a02b5e6c2155cda61fcc345c7583b734ab85;hp=42936f106b99d01d7753e698f59ceb3554c05d59;hpb=49f84a522f0ccac3b70728cd41011a0be0eed8cf;p=core.git diff --git a/inc/classes/third_party/api/wernisportal/class_WernisApi.php b/inc/classes/third_party/api/wernisportal/class_WernisApi.php index 42936f10..5147f6aa 100644 --- a/inc/classes/third_party/api/wernisportal/class_WernisApi.php +++ b/inc/classes/third_party/api/wernisportal/class_WernisApi.php @@ -2,11 +2,12 @@ /** * Class for connecting to the Wernis-Portal at http://www.wds66.com * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007 - 2009 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.shipsimu.org + * @todo Out-dated since 0.6-BETA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -70,10 +71,6 @@ class WernisApi extends BaseFrameworkSystem { protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); } /** @@ -82,7 +79,7 @@ class WernisApi extends BaseFrameworkSystem { * @param $cfg Configuration array * @return $apiInstance An instance of this API class */ - public final static function createWernisApi (array $cfg) { + public static final function createWernisApi (array $cfg) { // Create a new instance $apiInstance = new WernisApi(); @@ -120,7 +117,7 @@ class WernisApi extends BaseFrameworkSystem { $amount = isset($amount) ? $amount+0 : 0; if ($amount < $this->config['mineinsatz']) { - $this->setStatusMessage('low_stakes', sprintf("Dein Einsatz muss mindestens %d Wernis betragen.", $this->config['mineinsatz'])); + $this->setStatusMessage('low_stakes', sprintf('Dein Einsatz muss mindestens %d Wernis betragen.', $this->config['mineinsatz'])); return false; } @@ -133,7 +130,7 @@ class WernisApi extends BaseFrameworkSystem { $amount = isset($amount) ? $amount+0 : 0; if ($amount < $this->config['mineinsatz']) { - $this->setStatusMessage('low_stakes', sprintf("Dein Einsatz muss mindestens %d Wernis betragen.", $this->config['mineinsatz'])); + $this->setStatusMessage('low_stakes', sprintf('Dein Einsatz muss mindestens %d Wernis betragen.', $this->config['mineinsatz'])); return false; } @@ -144,9 +141,9 @@ class WernisApi extends BaseFrameworkSystem { // Script abbrechen mit Zurueck-Buttom public function ende () { global $_CONFIG; - include "templates/zurueck.html"; - include "templates/fuss.html"; - die(); + include 'templates/zurueck.html'; + include 'templates/fuss.html'; + exit(); } // Fehlermeldung ausgeben und beenden @@ -168,7 +165,7 @@ class WernisApi extends BaseFrameworkSystem { return $this->statusArray['message']; } else { // Fall-back to status - return sprintf("Fehler-Code %s ist keiner Nachricht zugewiesen.", $this->getErrorCode()); + return sprintf('Fehler-Code %s ist keiner Nachricht zugewiesen.', $this->getErrorCode()); } } @@ -189,8 +186,8 @@ class WernisApi extends BaseFrameworkSystem { if (!is_array($requestData)) { // Then abort here! return array( - 'status' => "failed_general", - 'message' => "API-Daten in config sind ungültig!" + 'status' => 'failed_general', + 'message' => 'API-Daten in config sind ungültig!' ); } @@ -198,13 +195,13 @@ class WernisApi extends BaseFrameworkSystem { if ((empty($this->config['wernis_api_id'])) || (empty($this->config['wernis_api_key']))) { // Abort here... return array( - 'status' => "failed_general", - 'message' => "API-Daten in config.php sind leer!" + 'status' => 'failed_general', + 'message' => 'API-Daten in config.php sind leer!' ); } // Construct the request string - $requestString = $this->config['api_url'] . $scriptName."?api_id=".$this->config['wernis_api_id']."&api_key=".$this->config['wernis_api_key']; + $requestString = $this->config['api_url'] . $scriptName . '?api_id=' . $this->config['wernis_api_id'] . '&api_key='.$this->config['wernis_api_key']; foreach ($requestData as $key => $value) { $requestString .= '&' . $key . '=' . $value; } @@ -213,16 +210,22 @@ class WernisApi extends BaseFrameworkSystem { $response = $this->sendRawRequest($requestString); // Check the response header if all is fine - if (strpos($response[0], '200') === false) { + if (strpos($response[0], '200') === FALSE) { // Something bad happend... :( return array( - 'status' => "request_error", - 'message' => sprintf("Servermeldung %s von WDS66-API erhalten.", $response[0]) + 'status' => 'request_error', + 'message' => sprintf('Servermeldung %s von WDS66-API erhalten.', $response[0]) ); } // All (maybe) fine so remove the response header from server - $response = $response[(count($response) - 1)]; + for ($idx = (count($response) - 1); $idx > 1; $idx--) { + $line = trim($response[$idx]); + if (!empty($line)) { + $response = $line; + break; + } + } // Prepare the returning result for higher functions if (substr($response, 0, 1) == '&') { @@ -237,51 +240,51 @@ class WernisApi extends BaseFrameworkSystem { $return = array(); // We use only the first two entries (which shall be fine) - if ($data[0] === "error") { + if ($data[0] === 'error') { // The request has failed... :( switch ($data[1]) { - case "404": // Invalid API ID - case "AUTH": // Authorization has failed + case '404': // Invalid API ID + case 'AUTH': // Authorization has failed $return = array( - 'status' => "auth_failed", - 'message' => "API-Daten scheinen nicht zu stimmen! (Access Denied)" + 'status' => 'auth_failed', + 'message' => 'API-Daten scheinen nicht zu stimmen! (Access Denied)' ); break; - case "LOCKED": // User account is locked! - case "PASS": // Bad passphrase entered - case "USER": // Missing account or invalid password + case 'LOCKED': // User account is locked! + case 'PASS': // Bad passphrase entered + case 'USER': // Missing account or invalid password $return = array( - 'status' => "user_failed", - 'message' => "Dein eingegebener WDS66-Username stimmt nicht, ist gesperrt oder du hast ein falsches Passwort eingegeben." + 'status' => 'user_failed', + 'message' => 'Dein eingegebener WDS66-Username stimmt nicht, ist gesperrt oder du hast ein falsches Passwort eingegeben.' ); break; - case "OWN": // Transfer to own account + case 'OWN': // Transfer to own account $return = array( - 'status' => "own_failed", - 'message' => "Du darfst dein eigenes Spiel leider nicht spielen." + 'status' => 'own_failed', + 'message' => 'Du darfst dein eigenes Spiel leider nicht spielen.' ); break; - case "AMOUNT": // Amount is depleted + case 'AMOUNT': // Amount is depleted $return = array( - 'status' => "amount_failed", - 'message' => "Dein Guthaben reicht nicht aus, um das Spiel zu spielen." + 'status' => 'amount_failed', + 'message' => 'Dein Guthaben reicht nicht aus, um das Spiel zu spielen.' ); break; - case "AMOUNT-SEND": // API amount is depleted + case 'AMOUNT-SEND': // API amount is depleted $return = array( - 'status' => "api_amount_failed", - 'message' => "Nicht genügend Guthaben auf dem API-Account." + 'status' => 'api_amount_failed', + 'message' => 'Nicht genügend Guthaben auf dem API-Account.' ); break; default: // Unknown error (maybe new?) $return = array( - 'status' => "request_failed", - 'message' => sprintf("Unbekannter Fehler %s von API erhalten.", $data[1]) + 'status' => 'request_failed', + 'message' => sprintf('Unbekannter Fehler %s von API erhalten.', $data[1]) ); break; } @@ -300,7 +303,7 @@ class WernisApi extends BaseFrameworkSystem { // Widthdraw this amount private function executeWithdraw ($amount) { // First all fails... - $result = false; + $result = FALSE; // Prepare the purpose $purpose = "\"Bube oder Dame\"-Einsatz gesetzt."; @@ -310,17 +313,17 @@ class WernisApi extends BaseFrameworkSystem { 'sub_request' => 'receive', 't_uid' => $this->w_id, 't_md5' => $this->w_md5, - 'r_uid' => (int)$this->config['wernis_refid'], - 'amount' => (int)$amount, + 'r_uid' => (int) $this->config['wernis_refid'], + 'amount' => (int) $amount, 'purpose' => urlencode(base64_encode($purpose)) ); // Return the result from the lower functions - $return = $this->sendRequest("book.php", $requestData); + $return = $this->sendRequest('book.php', $requestData); if ($return['status'] == $this->statusOkay) { // All fine! - $result = true; + $result = TRUE; } else { // Status failture text $this->setStatusMessage($return['message'], $return['status']); @@ -333,7 +336,7 @@ class WernisApi extends BaseFrameworkSystem { // Payout this amount private function executePayout ($amount) { // First all fails... - $result = false; + $result = FALSE; // Prepare the purpose $purpose = "\"Bube oder Dame\"-Gewinn erhalten."; @@ -343,8 +346,8 @@ class WernisApi extends BaseFrameworkSystem { 'sub_request' => 'send', 't_uid' => $this->w_id, 't_md5' => $this->w_md5, - 'r_uid' => (int)$this->config['wernis_refid'], - 'amount' => (int)$amount, + 'r_uid' => (int) $this->config['wernis_refid'], + 'amount' => (int) $amount, 'purpose' => urlencode(base64_encode($purpose)) ); @@ -353,7 +356,7 @@ class WernisApi extends BaseFrameworkSystem { if ($return['status'] == $this->statusOkay) { // All fine! - $result = true; + $result = TRUE; } else { // Status failture text $this->setStatusMessage($return['message'], $return['status']); @@ -373,7 +376,7 @@ class WernisApi extends BaseFrameworkSystem { $url = $extract[0]; // Extract host name - $host = str_replace("http://", '', $url); + $host = str_replace('http://', '', $url); if (ereg('/', $host)) $host = substr($host, 0, strpos($host, '/')); // Generate relative URL @@ -388,9 +391,9 @@ class WernisApi extends BaseFrameworkSystem { } // Generate request header - $request = "GET /".trim($script)." HTTP/1.0\r\n"; - $request .= "Host: ".$host."\r\n"; - $request .= sprintf("User-Agent: Bube oder Dame / 1.0 by Quix0r [Spieler: %d]\r\n\r\n", $this->w_id); + $request = "GET /" . trim($script) . " HTTP/1.0\r\n"; + $request .= "Host: " . $host . "\r\n"; + $request .= sprintf("User-Agent: WernisApi/1.0 by Quix0r [Spieler: %d]\r\n\r\n", $this->w_id); // Initialize array $response = array(); @@ -400,17 +403,17 @@ class WernisApi extends BaseFrameworkSystem { // Read response while(!feof($fp)) { - $response[] = trim(fgets($fp, 1024)); - } + array_push($response, trim(fgets($fp, 1024))); + } // END - while // Close socket fclose($fp); // Was the request successfull? - if ((!ereg("200 OK", $response[0])) && (empty($response[0]))) { + if ((!ereg('200 OK', $response[0])) && (empty($response[0]))) { // Not found / access forbidden $response = array('', '', ''); - } + } // END - if // Return response return $response;