try to fix dedimania php notice

This commit is contained in:
kremsy 2015-01-12 13:33:40 +01:00
parent 2d942c58fe
commit f2948c1a0c

View File

@ -69,10 +69,10 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
private $maniaControl = null; private $maniaControl = null;
// TODO: there are several spots where $dedimaniaData is null - fix those (look for !$this->dedimaniaData) // TODO: there are several spots where $dedimaniaData is null - fix those (look for !$this->dedimaniaData)
/** @var DedimaniaData $dedimaniaData */ /** @var DedimaniaData $dedimaniaData */
private $dedimaniaData = null; private $dedimaniaData = null;
private $updateManialink = false; private $updateManialink = false;
private $checkpoints = array(); private $checkpoints = array();
private $init = false; private $init = false;
private $request = null; private $request = null;
@ -196,41 +196,41 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
//$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) { //$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) { $this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
Logger::log("Try to connect on Dedimania"); Logger::log("Try to connect on Dedimania");
if (!$data || $error) { if (!$data || $error) {
Logger::logError("Dedimania Error: '{$error}'"); Logger::logError("Dedimania Error: '{$error}'");
} }
$data = $this->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPEN_SESSION); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPEN_SESSION);
return; return;
} }
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
$this->dedimaniaData->sessionId = $responseData['SessionId']; $this->dedimaniaData->sessionId = $responseData['SessionId'];
if ($this->dedimaniaData->sessionId) { if ($this->dedimaniaData->sessionId) {
Logger::log("Dedimania connection successfully established."); Logger::log("Dedimania connection successfully established.");
$this->fetchDedimaniaRecords(); $this->fetchDedimaniaRecords();
$this->init = true; $this->init = true;
} else { } else {
Logger::logError("Error while opening Dedimania Connection"); Logger::logError("Error while opening Dedimania Connection");
} }
if (self::DEDIMANIA_DEBUG) { if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Connect Method Response"); var_dump("Dedi Debug: Connect Method Response");
var_dump($methodResponse); var_dump($methodResponse);
var_dump("Dedi Debug: DedimaniaData after Startup"); var_dump("Dedi Debug: DedimaniaData after Startup");
var_dump($this->dedimaniaData); var_dump($this->dedimaniaData);
} }
}, $content, true); }, $content, true);
} }
/** /**
@ -295,44 +295,44 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
//var_dump("get recs"); //var_dump("get recs");
//$this->maniaControl->fileReader->postDataTest($this->request,self::DEDIMANIA_URL, function ($data, $error) { //$this->maniaControl->fileReader->postDataTest($this->request,self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) { $this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) { if ($error) {
Logger::logError('Dedimania Error: ' . $error); Logger::logError('Dedimania Error: ' . $error);
} }
$data = $this->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GET_RECORDS); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GET_RECORDS);
return; return;
} }
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
if (!isset($responseData['Players']) || !isset($responseData['Records'])) { if (!isset($responseData['Players']) || !isset($responseData['Records'])) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('Invalid Dedimania response!', $responseData); $this->maniaControl->getErrorHandler()->triggerDebugNotice('Invalid Dedimania response!', $responseData);
return; return;
} }
$this->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank']; $this->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
foreach ($responseData['Players'] as $player) { foreach ($responseData['Players'] as $player) {
$dediPlayer = new DedimaniaPlayer($player); $dediPlayer = new DedimaniaPlayer($player);
$this->dedimaniaData->addPlayer($dediPlayer); $this->dedimaniaData->addPlayer($dediPlayer);
} }
foreach ($responseData['Records'] as $key => $record) { foreach ($responseData['Records'] as $key => $record) {
$this->dedimaniaData->records[$key] = new RecordData($record); $this->dedimaniaData->records[$key] = new RecordData($record);
} }
if (self::DEDIMANIA_DEBUG) { if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Records Fetched"); var_dump("Dedimania Records Fetched");
} }
$this->updateManialink = true; $this->updateManialink = true;
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records); $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
}, $content, true); }, $content, true);
return true; return true;
} }
@ -405,8 +405,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
return null; return null;
} }
switch ($gameMode) { switch ($gameMode) {
case 0: case 0: {
{
$scriptNameResponse = $this->maniaControl->getClient()->getScriptName(); $scriptNameResponse = $this->maniaControl->getClient()->getScriptName();
$scriptName = str_replace('.Script.txt', '', $scriptNameResponse['CurrentValue']); $scriptName = str_replace('.Script.txt', '', $scriptNameResponse['CurrentValue']);
switch ($scriptName) { switch ($scriptName) {
@ -424,13 +423,11 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
} }
case 1: case 1:
case 3: case 3:
case 5: case 5: {
{
return 'Rounds'; return 'Rounds';
} }
case 2: case 2:
case 4: case 4: {
{
return 'TA'; return 'TA';
} }
} }
@ -573,33 +570,33 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
//var_dump("check session"); //TODO remove //var_dump("check session"); //TODO remove
//$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) { //$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) { $this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) { if ($error) {
Logger::logError("Dedimania Error: " . $error); Logger::logError("Dedimania Error: " . $error);
} }
$data = $this->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECK_SESSION); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECK_SESSION);
return; return;
} }
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
if (is_bool($responseData)) { if (is_bool($responseData)) {
if (!$responseData) { if (!$responseData) {
$this->openDedimaniaSession(); $this->openDedimaniaSession();
} }
} }
if (self::DEDIMANIA_DEBUG) { if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Session Check ResponseData "); var_dump("Dedi Debug: Session Check ResponseData ");
var_dump($responseData); var_dump($responseData);
} }
}, $content, true); }, $content, true);
} }
/** /**
@ -617,37 +614,37 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$content = $this->encode_request(self::DEDIMANIA_PLAYERCONNECT, $data); $content = $this->encode_request(self::DEDIMANIA_PLAYERCONNECT, $data);
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$player) { $this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$player) {
if ($error) { if ($error) {
Logger::logError("Dedimania Error: " . $error); Logger::logError("Dedimania Error: " . $error);
} }
$data = $this->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
return; return;
} }
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
$dediPlayer = new DedimaniaPlayer($responseData); $dediPlayer = new DedimaniaPlayer($responseData);
$this->dedimaniaData->addPlayer($dediPlayer); $this->dedimaniaData->addPlayer($dediPlayer);
// Fetch records if he is the first who joined the server // Fetch records if he is the first who joined the server
if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) === 1 if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) === 1
) { ) {
$this->fetchDedimaniaRecords(true); $this->fetchDedimaniaRecords(true);
} }
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE) if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
) { ) {
$manialink = $this->buildManialink(); $manialink = $this->buildManialink();
$this->maniaControl->getManialinkManager()->sendManialink($manialink, $player->login); $this->maniaControl->getManialinkManager()->sendManialink($manialink, $player->login);
} }
}, $content, true); }, $content, true);
} }
/** /**
@ -666,20 +663,20 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$content = $this->encode_request(self::DEDIMANIA_PLAYERDISCONNECT, $data); $content = $this->encode_request(self::DEDIMANIA_PLAYERDISCONNECT, $data);
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) { $this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) { if ($error) {
Logger::logError("Dedimania Error: " . $error); Logger::logError("Dedimania Error: " . $error);
} }
$data = $this->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT);
} }
}, $content, true); }, $content, true);
} }
/** /**
@ -735,38 +732,38 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
} }
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) { $this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) { if ($error) {
Logger::logError("Dedimania Error: " . $error); Logger::logError("Dedimania Error: " . $error);
} }
if (self::DEDIMANIA_DEBUG) { if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: Submit Data Response"); var_dump("Dedimania Debug: Submit Data Response");
var_dump($data); var_dump($data);
} }
$data = $this->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SET_CHALLENGE_TIMES); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SET_CHALLENGE_TIMES);
return; return;
} }
// Called method response // Called method response
if (!$methodResponse[0]) { if (!$methodResponse[0]) {
Logger::logError("Records Plugin: Submitting dedimania records failed."); Logger::logError("Records Plugin: Submitting dedimania records failed.");
} }
if (self::DEDIMANIA_DEBUG) { if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: endMap response"); var_dump("Dedimania Debug: endMap response");
var_dump($methodResponse); var_dump($methodResponse);
var_dump("Dedimania Data"); var_dump("Dedimania Data");
var_dump($this->dedimaniaData); var_dump($this->dedimaniaData);
} }
}, $content, false); }, $content, false);
} }
/** /**
@ -785,20 +782,20 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$content = $this->encode_request(self::DEDIMANIA_UPDATE_SERVER_PLAYERS, $data); $content = $this->encode_request(self::DEDIMANIA_UPDATE_SERVER_PLAYERS, $data);
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) { $this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) { if ($error) {
Logger::logError("Dedimania Error: " . $error); Logger::logError("Dedimania Error: " . $error);
} }
$data = $this->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATE_SERVER_PLAYERS); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATE_SERVER_PLAYERS);
} }
}, $content, true); }, $content, true);
} }
/** /**
@ -848,7 +845,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @param RecordCallback $callback * @param RecordCallback $callback
*/ */
public function handleFinishCallback(RecordCallback $callback) { public function handleFinishCallback(RecordCallback $callback) {
if (!$this->dedimaniaData || !$this->dedimaniaData->records) { if ($this->dedimaniaData != null || !$this->dedimaniaData->records) {
return; return;
} }
if ($callback->isLegacyCallback) { if ($callback->isLegacyCallback) {
@ -907,7 +904,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @return RecordData $record * @return RecordData $record
*/ */
private function getDedimaniaRecord($login) { private function getDedimaniaRecord($login) {
if (!$this->dedimaniaData || !$this->dedimaniaData->records) { if ($this->dedimaniaData != null || !$this->dedimaniaData->records) {
return new RecordData(null); return new RecordData(null);
} }
$records = $this->dedimaniaData->records; $records = $this->dedimaniaData->records;
@ -948,7 +945,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @return bool * @return bool
*/ */
private function insertDedimaniaRecord(RecordData &$newRecord, RecordData $oldRecord) { private function insertDedimaniaRecord(RecordData &$newRecord, RecordData $oldRecord) {
if (!$this->dedimaniaData || !$this->dedimaniaData->records || $newRecord->nullRecord) { if ($this->dedimaniaData != null || !$this->dedimaniaData->records || $newRecord->nullRecord) {
return false; return false;
} }