2013-11-12 15:48:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Maps;
|
|
|
|
|
2013-12-30 23:53:42 +01:00
|
|
|
use ManiaControl\Formatter;
|
2013-11-12 15:48:25 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
|
|
|
|
/**
|
2014-01-06 15:54:22 +01:00
|
|
|
* Map Class
|
2013-11-12 15:48:25 +01:00
|
|
|
*
|
|
|
|
* @author kremsy & steeffeen
|
|
|
|
*/
|
|
|
|
class Map {
|
|
|
|
/**
|
2014-01-06 15:54:22 +01:00
|
|
|
* Public Properties
|
2013-11-12 15:48:25 +01:00
|
|
|
*/
|
2013-11-25 02:01:15 +01:00
|
|
|
public $index = -1;
|
2013-11-12 15:48:25 +01:00
|
|
|
public $name = 'undefined';
|
|
|
|
public $uid = '';
|
|
|
|
public $fileName = '';
|
|
|
|
public $environment = '';
|
2014-01-05 13:56:05 +01:00
|
|
|
public $goldTime = -1;
|
|
|
|
public $copperPrice = -1;
|
2013-11-12 15:48:25 +01:00
|
|
|
public $mapType = '';
|
|
|
|
public $mapStyle = '';
|
2013-11-25 19:46:29 +01:00
|
|
|
public $nbCheckpoints = -1;
|
2013-11-12 15:48:25 +01:00
|
|
|
public $mx = null;
|
|
|
|
public $authorLogin = '';
|
|
|
|
public $authorNick = '';
|
|
|
|
public $authorZone = '';
|
|
|
|
public $authorEInfo = '';
|
|
|
|
public $comment = '';
|
|
|
|
public $titleUid = '';
|
2014-01-05 13:56:05 +01:00
|
|
|
public $startTime = -1;
|
2014-01-08 21:52:42 +01:00
|
|
|
|
2013-11-12 15:48:25 +01:00
|
|
|
/**
|
2014-01-06 15:54:22 +01:00
|
|
|
* Private Properties
|
2013-11-12 15:48:25 +01:00
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
2014-01-06 15:54:22 +01:00
|
|
|
* Create a new Map Object from Rpc Data
|
2013-11-12 15:48:25 +01:00
|
|
|
*
|
2014-01-05 13:56:05 +01:00
|
|
|
* @param \ManiaControl\ManiaControl $maniaControl
|
2014-01-08 21:52:42 +01:00
|
|
|
* @param array $rpc_infos
|
2013-11-12 15:48:25 +01:00
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl, $rpc_infos = null) {
|
2013-12-28 23:24:54 +01:00
|
|
|
$this->maniaControl = $maniaControl;
|
2014-01-08 21:52:42 +01:00
|
|
|
$this->startTime = time();
|
|
|
|
|
|
|
|
if(!$rpc_infos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->name = $rpc_infos['Name'];
|
|
|
|
$this->uid = $rpc_infos['UId'];
|
|
|
|
$this->fileName = $rpc_infos['FileName'];
|
2013-11-12 15:48:25 +01:00
|
|
|
$this->authorLogin = $rpc_infos['Author'];
|
|
|
|
$this->environment = $rpc_infos['Environnement'];
|
2014-01-08 21:52:42 +01:00
|
|
|
$this->goldTime = $rpc_infos['GoldTime'];
|
2013-11-12 15:48:25 +01:00
|
|
|
$this->copperPrice = $rpc_infos['CopperPrice'];
|
2014-01-08 21:52:42 +01:00
|
|
|
$this->mapType = $rpc_infos['MapType'];
|
|
|
|
$this->mapStyle = $rpc_infos['MapStyle'];
|
|
|
|
if(isset($rpc_infos['NbCheckpoints'])) {
|
2013-12-16 08:38:35 +01:00
|
|
|
$this->nbCheckpoints = $rpc_infos['NbCheckpoints'];
|
|
|
|
}
|
2014-01-08 21:52:42 +01:00
|
|
|
|
2013-12-16 08:38:35 +01:00
|
|
|
$this->authorNick = $this->authorLogin;
|
2014-01-08 21:52:42 +01:00
|
|
|
|
2013-12-28 23:24:54 +01:00
|
|
|
$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
|
2014-01-08 21:52:42 +01:00
|
|
|
if($this->maniaControl->server->checkAccess($mapsDirectory)) {
|
2014-01-06 15:54:22 +01:00
|
|
|
$mapFetcher = new \GBXChallMapFetcher(true);
|
2013-11-12 15:48:25 +01:00
|
|
|
try {
|
2014-01-06 15:54:22 +01:00
|
|
|
$mapFetcher->processFile($mapsDirectory . $this->fileName);
|
2014-01-08 21:52:42 +01:00
|
|
|
$this->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
|
2014-01-06 15:54:22 +01:00
|
|
|
$this->authorEInfo = $mapFetcher->authorEInfo;
|
2014-01-08 21:52:42 +01:00
|
|
|
$this->authorZone = $mapFetcher->authorZone;
|
|
|
|
$this->comment = $mapFetcher->comment;
|
|
|
|
} catch(\Exception $e) {
|
2014-01-06 15:54:22 +01:00
|
|
|
trigger_error($e->getMessage());
|
2013-11-12 15:48:25 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-08 21:52:42 +01:00
|
|
|
|
2013-12-27 21:10:53 +01:00
|
|
|
// TODO: define timeout if mx is down,todo fetch all map infos at once (maybe way faster)
|
2014-01-08 21:52:42 +01:00
|
|
|
$serverInfo = $this->maniaControl->server->titleId;
|
|
|
|
$title = strtoupper(substr($serverInfo, 0, 2));
|
|
|
|
$this->mx = new \MXInfoFetcher($title, $this->uid, false);
|
2013-11-12 15:48:25 +01:00
|
|
|
}
|
|
|
|
}
|