- subfolders for different classes
- Improved file and class naming - "handler"-> "listener" (callbacks, commands)
This commit is contained in:
84
application/core/Maps/Map.php
Normal file
84
application/core/Maps/Map.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Maps;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Map class
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
class Map {
|
||||
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $mapFetcher = null;
|
||||
public $id = 0;
|
||||
public $name = 'undefined';
|
||||
public $uid = '';
|
||||
public $fileName = '';
|
||||
public $environment = '';
|
||||
public $goldTime; // TODO: format?
|
||||
public $copperPrice = 0;
|
||||
public $mapType = '';
|
||||
public $mapStyle = '';
|
||||
public $mx = null;
|
||||
public $authorLogin = '';
|
||||
public $authorNick = '';
|
||||
public $authorZone = '';
|
||||
public $authorEInfo = '';
|
||||
public $comment = '';
|
||||
public $titleUid = '';
|
||||
public $startTime = 0;
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Create a new map object from rpc data
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
* @param array $rpc_infos
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl, $rpc_infos = null) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->startTime = time();
|
||||
|
||||
if (!$rpc_infos) {
|
||||
return;
|
||||
}
|
||||
$this->name = $rpc_infos['Name']; // in aseco stripped new lines on name
|
||||
$this->uid = $rpc_infos['UId'];
|
||||
$this->fileName = $rpc_infos['FileName'];
|
||||
$this->authorLogin = $rpc_infos['Author'];
|
||||
$this->environment = $rpc_infos['Environnement'];
|
||||
$this->goldTime = $rpc_infos['GoldTime'];
|
||||
$this->copperPrice = $rpc_infos['CopperPrice'];
|
||||
$this->mapType = $rpc_infos['MapType'];
|
||||
$this->mapStyle = $rpc_infos['MapStyle'];
|
||||
|
||||
$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
|
||||
if ($this->maniaControl->server->checkAccess($mapsDirectory)) {
|
||||
$this->mapFetcher = new \GBXChallMapFetcher(true);
|
||||
try {
|
||||
$this->mapFetcher->processFile($mapsDirectory . $this->fileName);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
trigger_error($e->getMessage(), E_USER_WARNING);
|
||||
}
|
||||
$this->authorNick = $this->mapFetcher->authorNick;
|
||||
$this->authorEInfo = $this->mapFetcher->authorEInfo;
|
||||
$this->authorZone = $this->mapFetcher->authorZone;
|
||||
$this->comment = $this->mapFetcher->comment;
|
||||
}
|
||||
|
||||
// TODO: define timeout if mx is down
|
||||
$serverInfo = $this->maniaControl->server->getSystemInfo();
|
||||
$title = strtoupper(substr($serverInfo['TitleId'], 0, 2));
|
||||
$this->mx = new \MXInfoFetcher($title, $this->uid, false);
|
||||
}
|
||||
}
|
77
application/core/Maps/MapManager.php
Normal file
77
application/core/Maps/MapManager.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Maps;
|
||||
|
||||
require_once __DIR__ . '/Map.php';
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
|
||||
/**
|
||||
* Manager for maps
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
class MapManager implements CallbackListener {
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $mapList = array();
|
||||
|
||||
/**
|
||||
* Construct map manager
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
|
||||
// TODO: database init
|
||||
// TODO: erasemap from server
|
||||
// TODO: implement of a method which are called by xlist command and results maplists from maniaexcahnge (or extra class for it)
|
||||
// TODO: admin add from maniaexchange, would handle it here
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->initTables();
|
||||
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleBeginMap');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize necessary database tables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function initTables() {
|
||||
// TODO: Initialize database table
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a map to the MapList
|
||||
*
|
||||
* @param \ManiaControl\Maps\Map $map
|
||||
* @return bool
|
||||
*/
|
||||
private function addMap(Map $map) {
|
||||
if (!$map) {
|
||||
return false;
|
||||
}
|
||||
// TODO: Save map in database
|
||||
$this->mapList[$map->uid] = $map;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle BeginMap callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleBeginMap(array $callback) {
|
||||
$rpcMap = $this->maniaControl->server->getCurrentMap();
|
||||
$map = new Map($this->maniaControl, $rpcMap);
|
||||
$this->addMap($map);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user