improved response handling

- btw: returning stuff in a closure doesn't make sense
This commit is contained in:
Steffen Schröder 2014-06-15 00:34:52 +02:00
parent fa14d96111
commit ddc42c854f

View File

@ -181,11 +181,16 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
$data = $this->decode($data);
if (is_array($data)) {
foreach ($data as $index => $methodResponse) {
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPENSESSION);
} else if ($index <= 0) {
return;
}
$responseData = $methodResponse[0];
$this->dedimaniaData->sessionId = $responseData['SessionId'];
if ($this->dedimaniaData->sessionId) {
@ -195,9 +200,6 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
} else {
$this->maniaControl->log("Error while opening Dedimania Connection");
}
}
}
}
}, $content, true);
}
@ -268,13 +270,16 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
$data = $self->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
if (is_array($data)) {
foreach ($data as $index => $methodResponse) {
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GETRECORDS);
return false;
} else if ($index <= 0) {
return;
}
$responseData = $methodResponse[0];
$self->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
@ -285,12 +290,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
foreach ($responseData['Records'] as $key => $record) {
$self->dedimaniaData->records[$key] = new RecordData($record);
}
}
}
}
$self->updateManialink = true;
$self->maniaControl->callbackManager->triggerCallback(self::CB_DEDIMANIA_UPDATED, $self->dedimaniaData->records);
return true;
}, $content, true);
return true;
@ -533,20 +535,22 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
$data = $self->decode($data);
if (is_array($data)) {
foreach ($data as $methodResponse) {
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECKSESSION);
} else {
return;
}
$responseData = $methodResponse[0];
if (is_bool($responseData)) {
if (!$responseData) {
$self->openDedimaniaSession();
}
}
}
}
}
}, $content, true);
return;
}
@ -568,11 +572,16 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
$data = $self->decode($data);
if (is_array($data)) {
foreach ($data as $index => $methodResponse) {
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
} else if ($index <= 0) {
return;
}
$responseData = $methodResponse[0];
$dediPlayer = new DedimaniaPlayer($responseData);
$self->dedimaniaData->addPlayer($dediPlayer);
@ -581,19 +590,11 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
if ($self->maniaControl->playerManager->getPlayerCount(false) === 1) {
$self->fetchDedimaniaRecords(true);
}
}
if ($self->maniaControl->settingManager->getSettingValue($self, self::SETTING_WIDGET_ENABLE)) {
$manialink = $self->buildManialink();
$self->maniaControl->manialinkManager->sendManialink($manialink, $player->login);
}
}
} else {
if (!$data) {
trigger_error('XmlRpc Error.');
var_dump($data);
}
}
return true;
}, $content, true);
}
@ -619,19 +620,14 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
$data = $self->decode($data);
if (is_array($data)) {
foreach ($data as $methodResponse) {
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT);
}
}
} else {
if (!$data) {
trigger_error('XmlRpc Error.');
var_dump($data);
}
}
return true;
}, $content, true);
}
@ -693,22 +689,20 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
$data = $self->decode($data);
if (is_array($data)) {
foreach ($data as $index => $methodResponse) {
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SETCHALLENGETIMES);
} else {
if ($index <= 0) {
return;
}
// Called method response
$responseData = $methodResponse[0];
if (!$responseData) {
if (!$methodResponse[0]) {
trigger_error("Records Plugin: Submitting dedimania records failed.");
}
continue;
}
}
}
}
}, $content, false);
}
@ -734,19 +728,14 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
$data = $self->decode($data);
if (is_array($data)) {
foreach ($data as $methodResponse) {
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATESERVERPLAYERS);
}
}
} else {
if (!$data) {
trigger_error('XmlRpc Error.');
var_dump($data);
}
}
return true;
}, $content, true);
}