dedimania small improvements

This commit is contained in:
kremsy 2017-05-22 15:52:59 +02:00
parent 6663d8baa6
commit 955621ff9b
2 changed files with 25 additions and 25 deletions

View File

@ -110,8 +110,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'updateEverySecond', 1000); $this->maniaControl->getTimerManager()->registerTimerListening($this, 'updateEverySecond', 1000);
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handleEveryHalfMinute', 1000 * 30); $this->maniaControl->getTimerManager()->registerTimerListening($this, 'handleEveryMinute', 1000 * 60);
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'updatePlayerList', 1000 * 60 * 3);
$this->maniaControl->getCommandManager()->registerCommandListener(array('dedirecs', $this->maniaControl->getCommandManager()->registerCommandListener(array('dedirecs',
'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.'); 'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
@ -131,7 +130,10 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
throw new \Exception("This Plugin is only for Trackmania!"); throw new \Exception("This Plugin is only for Trackmania!");
} }
$dedimaniaData = new DedimaniaData($serverInfo->login, $dedimaniaCode, $serverInfo->path, $packMask, $serverVersion); $login = ".escstadium";
$dedimaniaCode = "6372eec4d0";
$dedimaniaData = new DedimaniaData($login, $dedimaniaCode, $serverInfo->path, $packMask, $serverVersion);
//New Version //New Version
$this->webHandler = new DedimaniaWebHandler($this->maniaControl); $this->webHandler = new DedimaniaWebHandler($this->maniaControl);
@ -204,7 +206,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
/** /**
* Handle 1 Minute Callback * Handle 1 Minute Callback
*/ */
public function handleEveryHalfMinute() { public function handleEveryMinute() {
if ($this->webHandler->getDedimaniaData()->sessionId == "") { if ($this->webHandler->getDedimaniaData()->sessionId == "") {
return; return;
} }
@ -245,14 +247,6 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$this->webHandler->submitChallengeTimes(); $this->webHandler->submitChallengeTimes();
} }
/**
* Update the PlayerList every 3 Minutes
*/
public function updatePlayerList() {
$this->webHandler->updatePlayerList();
}
/** /**
* Handle Checkpoint Callback * Handle Checkpoint Callback
* *

View File

@ -3,6 +3,7 @@
namespace MCTeam\Dedimania; namespace MCTeam\Dedimania;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Files\AsyncHttpRequest; use ManiaControl\Files\AsyncHttpRequest;
use ManiaControl\Logger; use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -16,7 +17,7 @@ use ManiaControl\Players\Player;
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class DedimaniaWebHandler { class DedimaniaWebHandler implements TimerListener {
const XMLRPC_MULTICALL = 'system.multicall'; const XMLRPC_MULTICALL = 'system.multicall';
const DEDIMANIA_URL = 'http://dedimania.net:8082/Dedimania'; const DEDIMANIA_URL = 'http://dedimania.net:8082/Dedimania';
const DEDIMANIA_OPEN_SESSION = 'dedimania.OpenSession'; const DEDIMANIA_OPEN_SESSION = 'dedimania.OpenSession';
@ -47,10 +48,9 @@ class DedimaniaWebHandler {
public function openDedimaniaSession($updateRecords = false) { public function openDedimaniaSession($updateRecords = false) {
$content = $this->encodeRequest(self::DEDIMANIA_OPEN_SESSION, array($this->dedimaniaData->toArray())); $content = $this->encodeRequest(self::DEDIMANIA_OPEN_SESSION, array($this->dedimaniaData->toArray()));
Logger::logInfo("Try to connect on Dedimania");
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, self::DEDIMANIA_URL); $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, self::DEDIMANIA_URL);
$asyncHttpRequest->setCallable(function ($data, $error) use ($updateRecords) { $asyncHttpRequest->setCallable(function ($data, $error) use ($updateRecords) {
Logger::logInfo("Try to connect on Dedimania");
if (!$data || $error) { if (!$data || $error) {
Logger::logError("Dedimania Error while opening session: '{$error}' Line 42"); Logger::logError("Dedimania Error while opening session: '{$error}' Line 42");
} }
@ -99,7 +99,7 @@ class DedimaniaWebHandler {
// Reset records // Reset records
if ($reset) { if ($reset) {
$this->dedimaniaData->records = array(); $this->dedimaniaData->unsetRecords();
} }
$serverInfo = $this->getServerInfo(); $serverInfo = $this->getServerInfo();
@ -150,6 +150,11 @@ class DedimaniaWebHandler {
$this->maniaLinkNeedsUpdate = true; $this->maniaLinkNeedsUpdate = true;
$this->maniaControl->getCallbackManager()->triggerCallback(DedimaniaPlugin::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records); //TODO $this->maniaControl->getCallbackManager()->triggerCallback(DedimaniaPlugin::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records); //TODO
//3 Minutes
$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () {
$this->updatePlayerList();
}, 1000 * 60 * 3);
}); });
$asyncHttpRequest->setContent($content); $asyncHttpRequest->setContent($content);
@ -187,6 +192,7 @@ class DedimaniaWebHandler {
$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);
Logger::logError("Dedimania Check Session failed, opening a new Session!");
$this->openDedimaniaSession(); $this->openDedimaniaSession();
return; return;
} }
@ -194,6 +200,7 @@ class DedimaniaWebHandler {
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
if (is_bool($responseData)) { if (is_bool($responseData)) {
if (!$responseData) { if (!$responseData) {
Logger::logError("Dedimania Check Session failed, opening a new Session!");
$this->openDedimaniaSession(); $this->openDedimaniaSession();
} }
} }
@ -265,6 +272,7 @@ class DedimaniaWebHandler {
$asyncHttpRequest->setCallable(function ($data, $error) { $asyncHttpRequest->setCallable(function ($data, $error) {
if ($error) { if ($error) {
Logger::logError("Dedimania Error while submitting times: " . $error); Logger::logError("Dedimania Error while submitting times: " . $error);
return;
} }
$data = $this->decode($data); $data = $this->decode($data);
@ -310,9 +318,8 @@ class DedimaniaWebHandler {
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, self::DEDIMANIA_URL); $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, self::DEDIMANIA_URL);
$asyncHttpRequest->setCallable(function ($data, $error) use (&$player) { $asyncHttpRequest->setCallable(function ($data, $error) use (&$player) {
if ($error) { if ($error) {
$this->openDedimaniaSession(); //TODO Verify why? $this->checkDedimaniaSession(); //TODO Verify why?
var_dump($data); return;
var_dump("Dedimania test3");
} }
$data = $this->decode($data); $data = $this->decode($data);
@ -364,9 +371,8 @@ class DedimaniaWebHandler {
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, self::DEDIMANIA_URL); $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, self::DEDIMANIA_URL);
$asyncHttpRequest->setCallable(function ($data, $error) { $asyncHttpRequest->setCallable(function ($data, $error) {
if ($error) { if ($error) {
$this->openDedimaniaSession(); $this->checkDedimaniaSession();
var_dump($data); return;
var_dump("Dedimania test4");
} }
$data = $this->decode($data); $data = $this->decode($data);
@ -408,9 +414,8 @@ class DedimaniaWebHandler {
$asyncHttpRequest->setCallable(function ($data, $error) { $asyncHttpRequest->setCallable(function ($data, $error) {
if ($error) { if ($error) {
Logger::logError("Dedimania Error while update playerlist: " . $error); Logger::logError("Dedimania Error while update playerlist: " . $error);
var_dump($data); $this->checkDedimaniaSession();
var_dump("test4"); return;
} }
$data = $this->decode($data); $data = $this->decode($data);
@ -423,6 +428,7 @@ class DedimaniaWebHandler {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATE_SERVER_PLAYERS); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATE_SERVER_PLAYERS);
} }
Logger::logInfo("Dedimania Playerlist Updated"); Logger::logInfo("Dedimania Playerlist Updated");
}); });