From 6661197cb6fc6e11bd5a35836476fec9c1cf5141 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 15 Feb 2014 01:03:25 +0100 Subject: [PATCH] continue dedimania --- application/plugins/Dedimania/Dedimania.php | 84 ++++++++++++++++++- .../plugins/Dedimania/DedimaniaData.php | 40 ++++++--- 2 files changed, 111 insertions(+), 13 deletions(-) diff --git a/application/plugins/Dedimania/Dedimania.php b/application/plugins/Dedimania/Dedimania.php index 8cabbfa6..0065c556 100644 --- a/application/plugins/Dedimania/Dedimania.php +++ b/application/plugins/Dedimania/Dedimania.php @@ -1,16 +1,34 @@ maniaControl = $maniaControl; + + return; + + $this->openDedimaniaSession(true); + } + + private function openDedimaniaSession($init = false) { + // Open session + + $path = "GRA"; + $serverVersion = $this->maniaControl->client->getVersion(); + $packMask = substr($this->maniaControl->server->titleId, 2); + $this->dedimaniaData = new DedimaniaData("abc", "cde", $path, $packMask, $serverVersion); + + + $url = self::DEDIMANIA_URL; + + //TODO make postFile method in FileReader + $urlData = parse_url($url); + + $content = gzcompress($this->encode_request(self::DEDIMANIA_OPENSESSION, array($this->dedimaniaData->toArray()))); + + $query = 'POST ' . $urlData['path'] . ' HTTP/1.1' . PHP_EOL; + $query .= 'Host: ' . $urlData['host'] . PHP_EOL; + $query .= 'Accept-Charset: utf-8;' . PHP_EOL; + $query .= 'Accept-Encoding: gzip;' . PHP_EOL; + $query .= 'Content-Type: text/xml; charset=utf-8;' . PHP_EOL; + $query .= 'Keep-Alive: 300;' . PHP_EOL; + $query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL; + $query .= 'Content-Length: ' . strlen($content) . PHP_EOL . PHP_EOL; + $query .= $content . PHP_EOL; + + + $this->maniaControl->fileReader->loadFile($url, function ($data, $error) { + var_dump($data); + var_dump($error); + + }, 'UTF-8', $query); + + } + + /** + * Encodes the given xml rpc method and params + * + * @param string $method + * @param array $params + * @return string + */ + private function encode_request($method, $params) { + $paramArray = array(array('methodName' => $method, 'params' => $params), array('methodName' => self::DEDIMANIA_WARNINGSANDTTR2, 'params' => array())); + return xmlrpc_encode_request(self::XMLRPC_MULTICALL, array($paramArray), array('encoding' => 'UTF-8', 'escaping' => 'markup')); + } + + /** + * Decodes xml rpc response + * + * @param string $response + * @return mixed + */ + private function decode($response) { + return xmlrpc_decode($response, 'utf-8'); } /** * Unload the plugin and its resources */ public function unload() { - // TODO: Implement unload() method. + unset($this->maniaControl); } /** @@ -82,4 +161,5 @@ class Dedimania implements CallbackListener, TimerListener, Plugin { */ public static function getDescription() { // TODO: Implement getDescription() method. -}} \ No newline at end of file + } +} \ No newline at end of file diff --git a/application/plugins/Dedimania/DedimaniaData.php b/application/plugins/Dedimania/DedimaniaData.php index b624c37f..7de85805 100644 --- a/application/plugins/Dedimania/DedimaniaData.php +++ b/application/plugins/Dedimania/DedimaniaData.php @@ -8,23 +8,41 @@ namespace Dedimania; +use ManiaControl\ManiaControl; +use Maniaplanet\DedicatedServer\Structures\Version; + /** * Dedimania Structure * * @author kremsy & steeffeen */ class DedimaniaData { - /*public $streamBuffer; - public $socket; - public $function; - public $url; - public $creationTime;*/ + public $game; + public $path; + public $packmask; + public $serverVersion; + public $serverBuild; + public $tool; + public $version; + public $login; + public $code; - public function __construct($url, $socket, $function) { - /*$this->url = $url; - $this->socket = $socket; - $this->function = $function; - $this->creationTime = time(); - $this->streamBuffer = '';*/ + public function __construct($serverLogin, $dedimaniaCode, $path, $packmask, Version $serverVersion) { + $this->game = "TM2"; + $this->login = $serverLogin; + $this->code = $dedimaniaCode; + $this->version = ManiaControl::VERSION; + $this->tool = "ManiaControl"; + $this->path = $path; + $this->packmask = $packmask; + $this->serverVersion = $serverVersion->version; + $this->serverBuild = $serverVersion->build; + } + + public function toArray() { + $array = array(); + foreach(get_object_vars($this) as $key => $value) + $array[ucfirst($key)] = $value; + return $array; } } \ No newline at end of file