reformat code in plugins

This commit is contained in:
kremsy
2014-08-13 11:14:29 +02:00
parent 22915bb934
commit 13924f7d8a
10 changed files with 850 additions and 1477 deletions

View File

@ -80,11 +80,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
$servers = $maniaControl->getServer()
->getAllServers();
$servers = $maniaControl->getServer()->getAllServers();
foreach ($servers as $server) {
$maniaControl->getSettingManager()
->initSetting(get_class(), self::SETTING_DEDIMANIA_CODE . $server->login . '$l', '');
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_DEDIMANIA_CODE . $server->login . '$l', '');
}
}
@ -134,61 +132,39 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
// Settings
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_TITLE, 'Dedimania');
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_POSX, -139);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_POSY, 7);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_LINE_HEIGHT, 4);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_LINE_COUNT, 12);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_TITLE, 'Dedimania');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, -139);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 7);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_HEIGHT, 4);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_COUNT, 12);
// Callbacks
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleMapEnd');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(RecordCallback::CHECKPOINT, $this, 'handleCheckpointCallback');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(RecordCallback::LAPFINISH, $this, 'handleLapFinishCallback');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(RecordCallback::FINISH, $this, 'handleFinishCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleMapEnd');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::CHECKPOINT, $this, 'handleCheckpointCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::LAPFINISH, $this, 'handleLapFinishCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::FINISH, $this, 'handleFinishCallback');
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'updateEverySecond', 1000);
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'handleEveryMinute', 1000 * 60);
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'updatePlayerList', 1000 * 60 * 3);
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'updateEverySecond', 1000);
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handleEveryMinute', 1000 * 60);
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'updatePlayerList', 1000 * 60 * 3);
$this->maniaControl->getCommandManager()
->registerCommandListener(array('dedirecs', 'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('dedirecs', 'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
// Open session
$serverInfo = $this->maniaControl->getServer()
->getInfo();
$serverInfo = $this->maniaControl->getServer()->getInfo();
$packMask = $this->maniaControl->getServer()->titleId;
$serverVersion = $this->maniaControl->getClient()
->getVersion();
$serverVersion = $this->maniaControl->getClient()->getVersion();
if ($packMask !== 'Trackmania_2@nadeolabs') {
$packMask = substr($this->maniaControl->getServer()->titleId, 2);
}
$dedimaniaCode = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DEDIMANIA_CODE . $serverInfo->login . '$l');
$dedimaniaCode = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEDIMANIA_CODE . $serverInfo->login . '$l');
if (!$dedimaniaCode) {
throw new \Exception("No Dedimania Code Specified, check the settings!");
}
@ -219,43 +195,42 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
//$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
Logger::log("Try to connect on Dedimania");
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
Logger::log("Try to connect on Dedimania");
if (!$data || $error) {
Logger::logError("Dedimania Error: '{$error}'");
}
if (!$data || $error) {
Logger::logError("Dedimania Error: '{$error}'");
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPEN_SESSION);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPEN_SESSION);
return;
}
$responseData = $methodResponse[0];
$this->dedimaniaData->sessionId = $responseData['SessionId'];
if ($this->dedimaniaData->sessionId) {
Logger::log("Dedimania connection successfully established.");
$this->fetchDedimaniaRecords();
$this->init = true;
} else {
Logger::logError("Error while opening Dedimania Connection");
}
$responseData = $methodResponse[0];
$this->dedimaniaData->sessionId = $responseData['SessionId'];
if ($this->dedimaniaData->sessionId) {
Logger::log("Dedimania connection successfully established.");
$this->fetchDedimaniaRecords();
$this->init = true;
} else {
Logger::logError("Error while opening Dedimania Connection");
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Connect Method Response");
var_dump($methodResponse);
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Connect Method Response");
var_dump($methodResponse);
var_dump("Dedi Debug: DedimaniaData after Startup");
var_dump($this->dedimaniaData);
}
}, $content, true);
var_dump("Dedi Debug: DedimaniaData after Startup");
var_dump($this->dedimaniaData);
}
}, $content, true);
}
/**
@ -319,48 +294,45 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$content = $this->encode_request(self::DEDIMANIA_GET_RECORDS, $data);
//var_dump("get recs");
//$this->maniaControl->fileReader->postDataTest($this->request,self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError('Dedimania Error: ' . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError('Dedimania Error: ' . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GET_RECORDS);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GET_RECORDS);
return;
}
$responseData = $methodResponse[0];
if (!isset($responseData['Players']) || !isset($responseData['Records'])) {
$this->maniaControl->getErrorHandler()
->triggerDebugNotice('Invalid Dedimania response!', $responseData);
return;
}
$responseData = $methodResponse[0];
if (!isset($responseData['Players']) || !isset($responseData['Records'])) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('Invalid Dedimania response!', $responseData);
return;
}
$this->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
$this->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
foreach ($responseData['Players'] as $player) {
$dediPlayer = new DedimaniaPlayer($player);
$this->dedimaniaData->addPlayer($dediPlayer);
}
foreach ($responseData['Records'] as $key => $record) {
$this->dedimaniaData->records[$key] = new RecordData($record);
}
foreach ($responseData['Players'] as $player) {
$dediPlayer = new DedimaniaPlayer($player);
$this->dedimaniaData->addPlayer($dediPlayer);
}
foreach ($responseData['Records'] as $key => $record) {
$this->dedimaniaData->records[$key] = new RecordData($record);
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Records Fetched");
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Records Fetched");
}
$this->updateManialink = true;
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
}, $content, true);
$this->updateManialink = true;
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
}, $content, true);
return true;
}
@ -369,22 +341,18 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* Build server info Structure for callbacks
*/
private function getServerInfo() {
$server = $this->maniaControl->getClient()
->getServerOptions();
$server = $this->maniaControl->getClient()->getServerOptions();
if (!$server) {
return null;
}
if ($this->maniaControl->getPlayerManager()
->getPlayerCount(false) <= 0
if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) <= 0
) {
return null;
}
$playerCount = $this->maniaControl->getPlayerManager()
->getPlayerCount();
$spectatorCount = $this->maniaControl->getPlayerManager()
->getSpectatorCount();
$playerCount = $this->maniaControl->getPlayerManager()->getPlayerCount();
$spectatorCount = $this->maniaControl->getPlayerManager()->getSpectatorCount();
return array('SrvName' => $server->name, 'Comment' => $server->comment, 'Private' => (strlen($server->password) > 0), 'NumPlayers' => $playerCount, 'MaxPlayers' => $server->currentMaxPlayers, 'NumSpecs' => $spectatorCount, 'MaxSpecs' => $server->currentMaxSpectators);
}
@ -393,8 +361,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* Build simple player list for callbacks
*/
private function getPlayerList() {
$players = $this->maniaControl->getPlayerManager()
->getPlayers();
$players = $this->maniaControl->getPlayerManager()->getPlayers();
if (empty($players)) {
return null;
@ -412,8 +379,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @return array
*/
private function getMapInfo() {
$map = $this->maniaControl->getMapManager()
->getCurrentMap();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
return null;
}
@ -433,8 +399,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @return String
*/
private function getGameModeString() {
$gameMode = $this->maniaControl->getServer()
->getGameMode();
$gameMode = $this->maniaControl->getServer()->getGameMode();
if ($gameMode === null) {
Logger::logError("Couldn't retrieve game mode.");
return null;
@ -442,8 +407,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
switch ($gameMode) {
case 0:
{
$scriptNameResponse = $this->maniaControl->getClient()
->getScriptName();
$scriptNameResponse = $this->maniaControl->getClient()->getScriptName();
$scriptName = str_replace('.Script.txt', '', $scriptNameResponse['CurrentValue']);
switch ($scriptName) {
case 'Rounds':
@ -487,12 +451,10 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
var_dump("Dedimania Debug: Update Manialink");
}
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
) {
$manialink = $this->buildManialink();
$this->maniaControl->getManialinkManager()
->sendManialink($manialink);
$this->maniaControl->getManialinkManager()->sendManialink($manialink);
}
}
@ -504,27 +466,15 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
private function buildManialink() {
$records = $this->dedimaniaData->records;
$title = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_TITLE);
$posX = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_WIDTH);
$lines = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_LINE_COUNT);
$lineHeight = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_LINE_HEIGHT);
$labelStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultLabelStyle();
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadSubstyle();
$title = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_TITLE);
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_WIDTH);
$lines = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINE_COUNT);
$lineHeight = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINE_HEIGHT);
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$manialink = new ManiaLink(self::MLID_DEDIMANIA);
@ -622,35 +572,34 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$content = $this->encode_request(self::DEDIMANIA_CHECK_SESSION, array($this->dedimaniaData->sessionId));
//var_dump("check session"); //TODO remove
//$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECK_SESSION);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECK_SESSION);
return;
}
$responseData = $methodResponse[0];
if (is_bool($responseData)) {
if (!$responseData) {
$this->openDedimaniaSession();
}
}
$responseData = $methodResponse[0];
if (is_bool($responseData)) {
if (!$responseData) {
$this->openDedimaniaSession();
}
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Session Check ResponseData ");
var_dump($responseData);
}
}, $content, true);
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Session Check ResponseData ");
var_dump($responseData);
}
}, $content, true);
}
/**
@ -667,42 +616,38 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $player->login, $player->rawNickname, $player->path, $player->isSpectator);
$content = $this->encode_request(self::DEDIMANIA_PLAYERCONNECT, $data);
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$player) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$player) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
return;
}
$responseData = $methodResponse[0];
$dediPlayer = new DedimaniaPlayer($responseData);
$this->dedimaniaData->addPlayer($dediPlayer);
$responseData = $methodResponse[0];
$dediPlayer = new DedimaniaPlayer($responseData);
$this->dedimaniaData->addPlayer($dediPlayer);
// Fetch records if he is the first who joined the server
if ($this->maniaControl->getPlayerManager()
->getPlayerCount(false) === 1
) {
$this->fetchDedimaniaRecords(true);
}
// Fetch records if he is the first who joined the server
if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) === 1
) {
$this->fetchDedimaniaRecords(true);
}
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
) {
$manialink = $this->buildManialink();
$this->maniaControl->getManialinkManager()
->sendManialink($manialink, $player->login);
}
}, $content, true);
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
) {
$manialink = $this->buildManialink();
$this->maniaControl->getManialinkManager()->sendManialink($manialink, $player->login);
}
}, $content, true);
}
/**
@ -720,22 +665,21 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $player->login, '');
$content = $this->encode_request(self::DEDIMANIA_PLAYERDISCONNECT, $data);
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT);
}
}, $content, true);
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT);
}
}, $content, true);
}
/**
@ -791,40 +735,39 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
var_dump("Dedimania Debug: Submitting Times at End-Map", $content);
}
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: Submit Data Response");
var_dump($data);
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: Submit Data Response");
var_dump($data);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SET_CHALLENGE_TIMES);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SET_CHALLENGE_TIMES);
return;
}
// Called method response
if (!$methodResponse[0]) {
Logger::logError("Records Plugin: Submitting dedimania records failed.");
}
// Called method response
if (!$methodResponse[0]) {
Logger::logError("Records Plugin: Submitting dedimania records failed.");
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: endMap response");
var_dump($methodResponse);
var_dump("Dedimania Data");
var_dump($this->dedimaniaData);
}
}, $content, false);
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: endMap response");
var_dump($methodResponse);
var_dump("Dedimania Data");
var_dump($this->dedimaniaData);
}
}, $content, false);
}
/**
@ -842,30 +785,28 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $serverInfo, $votesInfo, $playerList);
$content = $this->encode_request(self::DEDIMANIA_UPDATE_SERVER_PLAYERS, $data);
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATE_SERVER_PLAYERS);
}
}, $content, true);
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATE_SERVER_PLAYERS);
}
}, $content, true);
}
/**
* Build Votes Info Array for Callbacks
*/
private function getVotesInfo() {
$map = $this->maniaControl->getMapManager()
->getCurrentMap();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
return null;
}
@ -919,8 +860,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
return;
}
$map = $this->maniaControl->getMapManager()
->getCurrentMap();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
return;
}
@ -940,8 +880,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
break;
}
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_DEDIMANIA_CHANGED, $newRecord);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_CHANGED, $newRecord);
// Announce record
if ($oldRecord->nullRecord || $newRecord->rank < $oldRecord->rank) {
@ -955,8 +894,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
if (!$oldRecord->nullRecord) {
$message .= ' ($<$ff0' . $oldRecord->rank . '.$> $<$fff-' . Formatter::formatTime(($oldRecord->best - $callback->lapTime)) . '$>)';
}
$this->maniaControl->getChat()
->sendInformation($message . '!');
$this->maniaControl->getChat()->sendInformation($message . '!');
$this->updateManialink = true;
}
@ -1092,8 +1030,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
*/
private function updateDedimaniaRecordRanks() {
if ($this->dedimaniaData->getRecordCount() === 0) {
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
return;
}
@ -1105,8 +1042,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$record->rank = $rank;
$rank++;
}
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
}
/**
@ -1116,28 +1052,23 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
*/
private function setRecordReplays(RecordData &$record) {
// Set validation replay
$validationReplay = $this->maniaControl->getServer()
->getValidationReplay($record->login);
$validationReplay = $this->maniaControl->getServer()->getValidationReplay($record->login);
if ($validationReplay) {
$record->vReplay = $validationReplay;
}
// Set ghost replay
if ($record->rank <= 1) {
$dataDirectory = $this->maniaControl->getServer()
->getDirectory()
->getGameDataFolder();
$dataDirectory = $this->maniaControl->getServer()->getDirectory()->getGameDataFolder();
if (!isset($this->dedimaniaData->directoryAccessChecked)) {
$access = $this->maniaControl->getServer()
->checkAccess($dataDirectory);
$access = $this->maniaControl->getServer()->checkAccess($dataDirectory);
if (!$access) {
trigger_error("No access to the servers data directory. Can't retrieve ghost replays.");
}
$this->dedimaniaData->directoryAccessChecked = $access;
}
if ($this->dedimaniaData->directoryAccessChecked) {
$ghostReplay = $this->maniaControl->getServer()
->getGhostReplay($record->login);
$ghostReplay = $this->maniaControl->getServer()->getGhostReplay($record->login);
if ($ghostReplay) {
$record->top1GReplay = $ghostReplay;
}
@ -1154,8 +1085,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$actionId = $callback[1][2];
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()
->getPlayer($login);
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if ($actionId === self::ACTION_SHOW_DEDIRECORDSLIST) {
$this->showDediRecordsList(array(), $player);
@ -1169,18 +1099,13 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @param Player $player
*/
public function showDediRecordsList(array $chat, Player $player) {
$width = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
// get PlayerList
$records = $this->dedimaniaData->records;
if (!$records) {
$this->maniaControl->getChat()
->sendInformation('There are no Dedimania records on this map!');
$this->maniaControl->getChat()->sendInformation('There are no Dedimania records on this map!');
return;
}
@ -1191,9 +1116,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultListFrame($script, $paging);
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Start offsets
@ -1201,9 +1124,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$posY = $height / 2;
// Predefine Description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultDescriptionLabel();
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
// Headline
@ -1211,8 +1132,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$frame->add($headFrame);
$headFrame->setY($posY - 5);
$array = array('Rank' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Time' => $posX + 101);
$this->maniaControl->getManialinkManager()
->labelLine($headFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
$index = 0;
$posY = $height / 2 - 10;
@ -1241,8 +1161,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$listRecord->nickName = $listRecord->login;
}
$array = array($listRecord->rank => $posX + 5, '$fff' . $listRecord->nickName => $posX + 18, $listRecord->login => $posX + 70, Formatter::formatTime($listRecord->best) => $posX + 101);
$this->maniaControl->getManialinkManager()
->labelLine($recordFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($recordFrame, $array);
$recordFrame->setY($posY);
@ -1251,8 +1170,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
// Render and display xml
$this->maniaControl->getManialinkManager()
->displayWidget($maniaLink, $player, 'DediRecordsList');
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'DediRecordsList');
}
/**