From 222972808d386b77125273c1743d2943c964d96c Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 10 Nov 2013 17:04:57 +0100 Subject: [PATCH] map and maphandler class begin --- application/core/maniaControlClass.php | 1 + application/core/map.php | 70 +++++++++++++++++++++++++ application/core/mapHandler.php | 72 ++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 application/core/map.php create mode 100644 application/core/mapHandler.php diff --git a/application/core/maniaControlClass.php b/application/core/maniaControlClass.php index 4c32da03..661ed5ac 100644 --- a/application/core/maniaControlClass.php +++ b/application/core/maniaControlClass.php @@ -17,6 +17,7 @@ require_once __DIR__ . '/pluginHandler.php'; require_once __DIR__ . '/server.php'; require_once __DIR__ . '/settingManager.php'; require_once __DIR__ . '/settingConfigurator.php'; +require_once __DIR__ . '/mapHandler.php'; list($endiantest) = array_values(unpack('L1L', pack('V', 1))); if ($endiantest == 1) { require_once __DIR__ . '/PhpRemote/GbxRemote.inc.php'; diff --git a/application/core/map.php b/application/core/map.php new file mode 100644 index 00000000..b7769dbc --- /dev/null +++ b/application/core/map.php @@ -0,0 +1,70 @@ +id = 0; + if ($rpc_infos) { + $this->name = stripNewlines($rpc_infos['Name']); + $this->uid = $rpc_infos['UId']; + $this->filename = $rpc_infos['FileName']; + $this->author = $rpc_infos['Author']; + $this->environment = $rpc_infos['Environnement']; + $this->mood = $rpc_infos['Mood']; + $this->bronzetime = $rpc_infos['BronzeTime']; + $this->silvertime = $rpc_infos['SilverTime']; + $this->goldtime = $rpc_infos['GoldTime']; + $this->authortime = $rpc_infos['AuthorTime']; + $this->copperprice = $rpc_infos['CopperPrice']; + $this->laprace = $rpc_infos['LapRace']; + $this->forcedlaps = 0; + $this->nblaps = $rpc_infos['NbLaps']; + $this->nbchecks = $rpc_infos['NbCheckpoints']; + $this->maptype = $rpc_infos['MapType']; + $this->mapstyle = $rpc_infos['MapStyle']; + + $this->starttime = time(); + } else { + $this->name = 'undefined'; + } + + + } +} \ No newline at end of file diff --git a/application/core/mapHandler.php b/application/core/mapHandler.php new file mode 100644 index 00000000..c9692425 --- /dev/null +++ b/application/core/mapHandler.php @@ -0,0 +1,72 @@ +maniaControl = $maniaControl; + + $this->initTables(); + + $this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MC_ONINIT, $this, 'onInit'); + $this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_BEGINMAP, $this, 'beginMap'); + $this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_ENDMAP, $this, 'endMap'); + } + + /** + * Initialize all necessary tables + * + * @return bool + */ + private function initTables() { + + + } + + /** + * Handle OnInit callback + * + * @param array $callback + */ + public function onInit(){ + $this->maniaControl->client->query('GetMapList', 300, 0); + $mapList = $this->maniaControl->client->getResponse(); + foreach ($mapList as $map) { + $this->addMap($map); + } + } + + /** + * Add a map to the MapList + * + * @param Map $map + * @return bool + */ + private function addMap(Map $map) { + if (!$map) { + return false; + } + $this->mapList[$map->uid] = $map; + return true; + } + +} \ No newline at end of file