TrackManiaControl/application/core/Callbacks/LibXmlRpcCallbackManager.php

93 lines
3.0 KiB
PHP
Raw Normal View History

2014-04-24 17:41:05 +02:00
<?php
namespace ManiaControl\Callbacks;
use ManiaControl\ManiaControl;
/**
* Class managing & converting LibXmlRpc Callbacks
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
2014-04-24 21:55:47 +02:00
class LibXmlRpcCallbackManager implements CallbackListener {
2014-04-24 17:41:05 +02:00
/*
* Private Properties
*/
private $maniaControl = null;
/**
2014-04-24 21:55:47 +02:00
* Create a new LibXmlRpc Callbacks Instance
2014-04-24 17:41:05 +02:00
*
2014-05-02 17:50:30 +02:00
* @param ManiaControl $maniaControl
* @param CallbackManager $callbackManager
2014-04-24 17:41:05 +02:00
*/
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
$this->maniaControl = $maniaControl;
2014-04-24 21:55:47 +02:00
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
2014-04-24 17:41:05 +02:00
}
2014-04-24 23:11:09 +02:00
/**
* Handle Script Callbacks
*
* @param string $name
2014-05-02 17:50:30 +02:00
* @param array $data
2014-04-24 23:11:09 +02:00
*/
public function handleScriptCallbacks($name, array $data) {
2014-05-02 17:50:30 +02:00
switch ($name) {
2014-04-24 17:41:05 +02:00
case 'LibXmlRpc_BeginMatch':
2014-04-24 21:55:47 +02:00
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMATCH, $data[0]);
2014-04-24 17:41:05 +02:00
break;
case 'LibXmlRpc_LoadingMap':
2014-04-24 21:55:47 +02:00
$this->maniaControl->callbackManager->triggerCallback(Callbacks::LOADINGMAP, $data[0]);
2014-04-24 17:41:05 +02:00
break;
2014-04-24 21:55:47 +02:00
case 'BeginMap':
2014-04-24 17:41:05 +02:00
case 'LibXmlRpc_BeginMap':
2014-04-24 17:54:13 +02:00
$this->maniaControl->mapManager->handleScriptBeginMap($data[0]);
2014-04-24 17:41:05 +02:00
break;
2014-04-24 21:55:47 +02:00
case 'LibXmlRpc_BeginSubmatch':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINSUBMATCH, $data[0]);
break;
case 'LibXmlRpc_BeginTurn':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINTURN, $data[0]);
break;
case 'LibXmlRpc_EndTurn':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDTURN, $data[0]);
break;
case 'LibXmlRpc_EndRound':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDROUND, $data[0]);
break;
case 'LibXmlRpc_EndSubmatch':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDSUBMATCH, $data[0]);
break;
case 'EndMap':
case 'LibXmlRpc_EndMap':
$this->maniaControl->mapManager->handleScriptEndMap($data[0]);
break;
case 'LibXmlRpc_EndMatch':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDMATCH, $data[0]);
break;
case 'LibXmlRpc_BeginWarmUp':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINWARMUP);
break;
case 'LibXmlRpc_EndWarmUp':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDWARMUP);
break;
2014-04-24 23:11:09 +02:00
case 'LibXmlRpc_PlayerRanking': //TODO really useful? what does it have what RankingsManager not have?
$this->triggerPlayerRanking($data[0]);
break;
2014-04-24 17:41:05 +02:00
}
}
2014-04-24 23:11:09 +02:00
/**
* Triggers the Ranking of a Player
*
* @param array $data
2014-04-24 23:11:09 +02:00
*/
private function triggerPlayerRanking(array $data) {
2014-04-24 23:11:09 +02:00
$player = $this->maniaControl->playerManager->getPlayer($data[1]);
$this->maniaControl->callbackManager->triggerCallback(Callbacks::PLAYERRANKING, $player, $data[0], $data[6], $data[5]);
}
2014-04-24 21:55:47 +02:00
}