continue dedimania
This commit is contained in:
parent
b71fced023
commit
6661197cb6
@ -1,16 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace Dedimania;
|
||||||
|
|
||||||
|
require_once "DedimaniaData.php";
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\TimerListener;
|
use ManiaControl\Callbacks\TimerListener;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Plugins\Plugin;
|
use ManiaControl\Plugins\Plugin;
|
||||||
|
|
||||||
class Dedimania implements CallbackListener, TimerListener, Plugin {
|
class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||||
|
/**
|
||||||
|
* 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';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/** @var ManiaControl $maniaControl */
|
/** @var ManiaControl $maniaControl */
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
/** @var DedimaniaData $dedimaniaData */
|
||||||
|
private $dedimaniaData = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the Plugin
|
* Prepares the Plugin
|
||||||
@ -30,13 +48,74 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
|||||||
*/
|
*/
|
||||||
public function load(ManiaControl $maniaControl) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->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
|
* Unload the plugin and its resources
|
||||||
*/
|
*/
|
||||||
public function unload() {
|
public function unload() {
|
||||||
// TODO: Implement unload() method.
|
unset($this->maniaControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,4 +161,5 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
|||||||
*/
|
*/
|
||||||
public static function getDescription() {
|
public static function getDescription() {
|
||||||
// TODO: Implement getDescription() method.
|
// TODO: Implement getDescription() method.
|
||||||
}}
|
}
|
||||||
|
}
|
@ -8,23 +8,41 @@
|
|||||||
|
|
||||||
namespace Dedimania;
|
namespace Dedimania;
|
||||||
|
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
|
use Maniaplanet\DedicatedServer\Structures\Version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dedimania Structure
|
* Dedimania Structure
|
||||||
*
|
*
|
||||||
* @author kremsy & steeffeen
|
* @author kremsy & steeffeen
|
||||||
*/
|
*/
|
||||||
class DedimaniaData {
|
class DedimaniaData {
|
||||||
/*public $streamBuffer;
|
public $game;
|
||||||
public $socket;
|
public $path;
|
||||||
public $function;
|
public $packmask;
|
||||||
public $url;
|
public $serverVersion;
|
||||||
public $creationTime;*/
|
public $serverBuild;
|
||||||
|
public $tool;
|
||||||
|
public $version;
|
||||||
|
public $login;
|
||||||
|
public $code;
|
||||||
|
|
||||||
public function __construct($url, $socket, $function) {
|
public function __construct($serverLogin, $dedimaniaCode, $path, $packmask, Version $serverVersion) {
|
||||||
/*$this->url = $url;
|
$this->game = "TM2";
|
||||||
$this->socket = $socket;
|
$this->login = $serverLogin;
|
||||||
$this->function = $function;
|
$this->code = $dedimaniaCode;
|
||||||
$this->creationTime = time();
|
$this->version = ManiaControl::VERSION;
|
||||||
$this->streamBuffer = '';*/
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user