improved response handling
- btw: returning stuff in a closure doesn't make sense
This commit is contained in:
parent
fa14d96111
commit
ddc42c854f
@ -181,22 +181,24 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->decode($data);
|
$data = $this->decode($data);
|
||||||
if (is_array($data)) {
|
if (!is_array($data) || empty($data)) {
|
||||||
foreach ($data as $index => $methodResponse) {
|
return;
|
||||||
if (xmlrpc_is_fault($methodResponse)) {
|
}
|
||||||
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPENSESSION);
|
|
||||||
} else if ($index <= 0) {
|
$methodResponse = $data[0];
|
||||||
$responseData = $methodResponse[0];
|
if (xmlrpc_is_fault($methodResponse)) {
|
||||||
$this->dedimaniaData->sessionId = $responseData['SessionId'];
|
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPENSESSION);
|
||||||
if ($this->dedimaniaData->sessionId) {
|
return;
|
||||||
$this->maniaControl->log("Dedimania connection successfully established.");
|
}
|
||||||
$this->fetchDedimaniaRecords();
|
|
||||||
$this->init = true;
|
$responseData = $methodResponse[0];
|
||||||
} else {
|
$this->dedimaniaData->sessionId = $responseData['SessionId'];
|
||||||
$this->maniaControl->log("Error while opening Dedimania Connection");
|
if ($this->dedimaniaData->sessionId) {
|
||||||
}
|
$this->maniaControl->log("Dedimania connection successfully established.");
|
||||||
}
|
$this->fetchDedimaniaRecords();
|
||||||
}
|
$this->init = true;
|
||||||
|
} else {
|
||||||
|
$this->maniaControl->log("Error while opening Dedimania Connection");
|
||||||
}
|
}
|
||||||
}, $content, true);
|
}, $content, true);
|
||||||
}
|
}
|
||||||
@ -268,29 +270,29 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = $self->decode($data);
|
$data = $self->decode($data);
|
||||||
|
if (!is_array($data) || empty($data)) {
|
||||||
if (is_array($data)) {
|
return;
|
||||||
foreach ($data as $index => $methodResponse) {
|
|
||||||
if (xmlrpc_is_fault($methodResponse)) {
|
|
||||||
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GETRECORDS);
|
|
||||||
return false;
|
|
||||||
} else if ($index <= 0) {
|
|
||||||
$responseData = $methodResponse[0];
|
|
||||||
$self->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
|
|
||||||
|
|
||||||
foreach ($responseData['Players'] as $player) {
|
|
||||||
$dediPlayer = new DedimaniaPlayer($player);
|
|
||||||
$self->dedimaniaData->addPlayer($dediPlayer);
|
|
||||||
}
|
|
||||||
foreach ($responseData['Records'] as $key => $record) {
|
|
||||||
$self->dedimaniaData->records[$key] = new RecordData($record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$methodResponse = $data[0];
|
||||||
|
if (xmlrpc_is_fault($methodResponse)) {
|
||||||
|
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GETRECORDS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$responseData = $methodResponse[0];
|
||||||
|
$self->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
|
||||||
|
|
||||||
|
foreach ($responseData['Players'] as $player) {
|
||||||
|
$dediPlayer = new DedimaniaPlayer($player);
|
||||||
|
$self->dedimaniaData->addPlayer($dediPlayer);
|
||||||
|
}
|
||||||
|
foreach ($responseData['Records'] as $key => $record) {
|
||||||
|
$self->dedimaniaData->records[$key] = new RecordData($record);
|
||||||
|
}
|
||||||
|
|
||||||
$self->updateManialink = true;
|
$self->updateManialink = true;
|
||||||
$self->maniaControl->callbackManager->triggerCallback(self::CB_DEDIMANIA_UPDATED, $self->dedimaniaData->records);
|
$self->maniaControl->callbackManager->triggerCallback(self::CB_DEDIMANIA_UPDATED, $self->dedimaniaData->records);
|
||||||
return true;
|
|
||||||
}, $content, true);
|
}, $content, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -533,18 +535,20 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = $self->decode($data);
|
$data = $self->decode($data);
|
||||||
if (is_array($data)) {
|
if (!is_array($data) || empty($data)) {
|
||||||
foreach ($data as $methodResponse) {
|
return;
|
||||||
if (xmlrpc_is_fault($methodResponse)) {
|
}
|
||||||
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECKSESSION);
|
|
||||||
} else {
|
$methodResponse = $data[0];
|
||||||
$responseData = $methodResponse[0];
|
if (xmlrpc_is_fault($methodResponse)) {
|
||||||
if (is_bool($responseData)) {
|
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECKSESSION);
|
||||||
if (!$responseData) {
|
return;
|
||||||
$self->openDedimaniaSession();
|
}
|
||||||
}
|
|
||||||
}
|
$responseData = $methodResponse[0];
|
||||||
}
|
if (is_bool($responseData)) {
|
||||||
|
if (!$responseData) {
|
||||||
|
$self->openDedimaniaSession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, $content, true);
|
}, $content, true);
|
||||||
@ -568,32 +572,29 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = $self->decode($data);
|
$data = $self->decode($data);
|
||||||
if (is_array($data)) {
|
if (!is_array($data) || empty($data)) {
|
||||||
foreach ($data as $index => $methodResponse) {
|
return;
|
||||||
if (xmlrpc_is_fault($methodResponse)) {
|
}
|
||||||
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
|
|
||||||
} else if ($index <= 0) {
|
$methodResponse = $data[0];
|
||||||
$responseData = $methodResponse[0];
|
if (xmlrpc_is_fault($methodResponse)) {
|
||||||
$dediPlayer = new DedimaniaPlayer($responseData);
|
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
|
||||||
$self->dedimaniaData->addPlayer($dediPlayer);
|
return;
|
||||||
|
}
|
||||||
// Fetch records if he is the first who joined the server
|
|
||||||
if ($self->maniaControl->playerManager->getPlayerCount(false) === 1) {
|
$responseData = $methodResponse[0];
|
||||||
$self->fetchDedimaniaRecords(true);
|
$dediPlayer = new DedimaniaPlayer($responseData);
|
||||||
}
|
$self->dedimaniaData->addPlayer($dediPlayer);
|
||||||
}
|
|
||||||
if ($self->maniaControl->settingManager->getSettingValue($self, self::SETTING_WIDGET_ENABLE)) {
|
// Fetch records if he is the first who joined the server
|
||||||
$manialink = $self->buildManialink();
|
if ($self->maniaControl->playerManager->getPlayerCount(false) === 1) {
|
||||||
$self->maniaControl->manialinkManager->sendManialink($manialink, $player->login);
|
$self->fetchDedimaniaRecords(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
if ($self->maniaControl->settingManager->getSettingValue($self, self::SETTING_WIDGET_ENABLE)) {
|
||||||
if (!$data) {
|
$manialink = $self->buildManialink();
|
||||||
trigger_error('XmlRpc Error.');
|
$self->maniaControl->manialinkManager->sendManialink($manialink, $player->login);
|
||||||
var_dump($data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}, $content, true);
|
}, $content, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,19 +620,14 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = $self->decode($data);
|
$data = $self->decode($data);
|
||||||
if (is_array($data)) {
|
if (!is_array($data) || empty($data)) {
|
||||||
foreach ($data as $methodResponse) {
|
return;
|
||||||
if (xmlrpc_is_fault($methodResponse)) {
|
}
|
||||||
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT);
|
|
||||||
}
|
$methodResponse = $data[0];
|
||||||
}
|
if (xmlrpc_is_fault($methodResponse)) {
|
||||||
} else {
|
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT);
|
||||||
if (!$data) {
|
|
||||||
trigger_error('XmlRpc Error.');
|
|
||||||
var_dump($data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}, $content, true);
|
}, $content, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,21 +689,19 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = $self->decode($data);
|
$data = $self->decode($data);
|
||||||
if (is_array($data)) {
|
if (!is_array($data) || empty($data)) {
|
||||||
foreach ($data as $index => $methodResponse) {
|
return;
|
||||||
if (xmlrpc_is_fault($methodResponse)) {
|
}
|
||||||
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SETCHALLENGETIMES);
|
|
||||||
} else {
|
$methodResponse = $data[0];
|
||||||
if ($index <= 0) {
|
if (xmlrpc_is_fault($methodResponse)) {
|
||||||
// Called method response
|
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SETCHALLENGETIMES);
|
||||||
$responseData = $methodResponse[0];
|
return;
|
||||||
if (!$responseData) {
|
}
|
||||||
trigger_error("Records Plugin: Submitting dedimania records failed.");
|
|
||||||
}
|
// Called method response
|
||||||
continue;
|
if (!$methodResponse[0]) {
|
||||||
}
|
trigger_error("Records Plugin: Submitting dedimania records failed.");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, $content, false);
|
}, $content, false);
|
||||||
}
|
}
|
||||||
@ -734,19 +728,14 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = $self->decode($data);
|
$data = $self->decode($data);
|
||||||
if (is_array($data)) {
|
if (!is_array($data) || empty($data)) {
|
||||||
foreach ($data as $methodResponse) {
|
return;
|
||||||
if (xmlrpc_is_fault($methodResponse)) {
|
}
|
||||||
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATESERVERPLAYERS);
|
|
||||||
}
|
$methodResponse = $data[0];
|
||||||
}
|
if (xmlrpc_is_fault($methodResponse)) {
|
||||||
} else {
|
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATESERVERPLAYERS);
|
||||||
if (!$data) {
|
|
||||||
trigger_error('XmlRpc Error.');
|
|
||||||
var_dump($data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}, $content, true);
|
}, $content, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user