TrackManiaControl/application/plugins/Dedimania/Dedimania.php

165 lines
4.2 KiB
PHP
Raw Normal View History

2014-02-14 19:22:11 +01:00
<?php
2014-02-15 01:03:25 +01:00
namespace Dedimania;
2014-02-14 19:22:11 +01:00
2014-02-15 01:03:25 +01:00
require_once "DedimaniaData.php";
2014-02-14 19:22:11 +01:00
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\ManiaControl;
use ManiaControl\Plugins\Plugin;
class Dedimania implements CallbackListener, TimerListener, Plugin {
2014-02-15 01:03:25 +01:00
/**
* Constants
*/
const XMLRPC_MULTICALL = 'system.multicall';
const DEDIMANIA_URL = 'http://dedimania.net:8081/Dedimania';
const DEDIMANIA_OPENSESSION = 'dedimania.OpenSession';
const DEDIMANIA_CHECKSESSION = 'dedimania.CheckSession';
const DEDIMANIA_GETRECORDS = 'dedimania.GetChallengeRecords';
const DEDIMANIA_PLAYERCONNECT = 'dedimania.PlayerConnect';
const DEDIMANIA_PLAYERDISCONNECT = 'dedimania.PlayerDisconnect';
const DEDIMANIA_UPDATESERVERPLAYERS = 'dedimania.UpdateServerPlayers';
const DEDIMANIA_SETCHALLENGETIMES = 'dedimania.SetChallengeTimes';
const DEDIMANIA_WARNINGSANDTTR2 = 'dedimania.WarningsAndTTR2';
2014-02-14 19:22:11 +01:00
/**
* Private Properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
2014-02-15 01:03:25 +01:00
/** @var DedimaniaData $dedimaniaData */
private $dedimaniaData = null;
2014-02-14 19:22:11 +01:00
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* Load the plugin
*
* @param \ManiaControl\ManiaControl $maniaControl
* @return bool
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
2014-02-15 01:03:25 +01:00
2014-02-15 12:41:29 +01:00
return;
2014-02-15 01:03:25 +01:00
$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');
2014-02-14 19:22:11 +01:00
}
/**
* Unload the plugin and its resources
*/
public function unload() {
2014-02-15 01:03:25 +01:00
unset($this->maniaControl);
2014-02-14 19:22:11 +01:00
}
/**
* Get plugin id
*
* @return int
*/
public static function getId() {
// TODO: Implement getId() method.
}
/**
* Get Plugin Name
*
* @return string
*/
public static function getName() {
// TODO: Implement getName() method.
}
/**
* Get Plugin Version
*
* @return float
*/
public static function getVersion() {
// TODO: Implement getVersion() method.
}
/**
* Get Plugin Author
*
* @return string
*/
public static function getAuthor() {
// TODO: Implement getAuthor() method.
}
/**
* Get Plugin Description
*
* @return string
*/
public static function getDescription() {
// TODO: Implement getDescription() method.
2014-02-15 01:03:25 +01:00
}
}