From 7408ffb4ac59d71806cf351ea321f78af5896a0d Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 20 Apr 2014 14:52:26 +0200 Subject: [PATCH] php 5.3 compatiblity --- .../core/ManiaExchange/ManiaExchangeList.php | 14 +- .../core/Manialinks/CustomUIManager.php | 5 +- application/core/Maps/MapList.php | 13 +- application/core/Maps/MapManager.php | 13 +- application/core/Players/PlayerList.php | 16 ++- application/core/Server/UsageReporter.php | 5 +- application/core/Update/UpdateManager.php | 120 +++++++++--------- application/plugins/CustomVotes.php | 1 - application/plugins/Dedimania/Dedimania.php | 25 ++-- application/plugins/Donations.php | 24 ++-- application/plugins/Karma.php | 77 +++++------ 11 files changed, 165 insertions(+), 148 deletions(-) diff --git a/application/core/ManiaExchange/ManiaExchangeList.php b/application/core/ManiaExchange/ManiaExchangeList.php index 417fc05c..252f91c3 100644 --- a/application/core/ManiaExchange/ManiaExchangeList.php +++ b/application/core/ManiaExchange/ManiaExchangeList.php @@ -103,17 +103,15 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener } } - $function = function ($maps) use (&$player) { + // search for matching maps + $self = $this; + $this->maniaControl->mapManager->mxManager->getMapsAsync(function ($maps) use (&$self, &$player) { if (!$maps) { - $this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login); + $self->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login); return; } - $this->showManiaExchangeList($maps, $player); - }; - - - // search for matching maps - $this->maniaControl->mapManager->mxManager->getMapsAsync($function, $searchString, $author, $environment); + $self->showManiaExchangeList($maps, $player); + }, $searchString, $author, $environment); } /** diff --git a/application/core/Manialinks/CustomUIManager.php b/application/core/Manialinks/CustomUIManager.php index 84af3f7d..7cc53476 100644 --- a/application/core/Manialinks/CustomUIManager.php +++ b/application/core/Manialinks/CustomUIManager.php @@ -86,8 +86,9 @@ class CustomUIManager implements CallbackListener, TimerListener { $this->updateManialink($player); //send it again after 500ms - $this->maniaControl->timerManager->registerOneTimeListening($this, function($time) use (&$player){ - $this->updateManialink($player); + $self = $this; + $this->maniaControl->timerManager->registerOneTimeListening($this, function($time) use (&$self, &$player){ + $self->updateManialink($player); },500); } diff --git a/application/core/Maps/MapList.php b/application/core/Maps/MapList.php index 1a01fd5e..474c196d 100644 --- a/application/core/Maps/MapList.php +++ b/application/core/Maps/MapList.php @@ -545,18 +545,19 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { /** @var Map $map */ $votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message); - $votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) { - $this->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!'); + $self = $this; + $votesPlugin->startVote($player, 'switchmap', function ($result) use (&$self, &$votesPlugin, &$map) { + $self->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!'); $votesPlugin->undefineVote('switchmap'); try { - $index = $this->maniaControl->mapManager->getMapIndex($map); - $this->maniaControl->client->jumpToMapIndex($index); + $index = $self->maniaControl->mapManager->getMapIndex($map); + $self->maniaControl->client->jumpToMapIndex($index); } catch(Exception $e) { //TODO temp added 19.04.2014 - $this->maniaControl->errorHandler->triggerDebugNotice("Exception line 557 MapList.php" . $e->getMessage()); + $self->maniaControl->errorHandler->triggerDebugNotice("Exception line 557 MapList.php" . $e->getMessage()); - $this->maniaControl->chat->sendError("Error while Switching Map"); + $self->maniaControl->chat->sendError("Error while Switching Map"); } }); break; diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index b90a00b7..72e701c4 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -586,27 +586,28 @@ class MapManager implements CallbackListener { public function addMapFromMx($mapId, $login, $update = false) { if (is_numeric($mapId)) { // Check if map exists - $this->maniaControl->mapManager->mxManager->getMapInfo($mapId, function (MXMapInfo $mapInfo) use (&$login, &$update) { + $self = $this; + $this->maniaControl->mapManager->mxManager->getMapInfo($mapId, function (MXMapInfo $mapInfo) use (&$self, &$login, &$update) { if (!$mapInfo || !isset($mapInfo->uploaded)) { // Invalid id - $this->maniaControl->chat->sendError('Invalid MX-Id!', $login); + $self->maniaControl->chat->sendError('Invalid MX-Id!', $login); return; } // TODO hardcoded during closed beta, later take just $mapInfo->url again $url = 'http://' . $mapInfo->prefix . '.mania-exchange.com/' . $mapInfo->dir . '/download/' . $mapInfo->id; - if ($this->maniaControl->settingManager->getSetting($this->mxManager, ManiaExchangeManager::SETTING_MP3_BETA_TESTING)) { + if ($self->maniaControl->settingManager->getSetting($self->mxManager, ManiaExchangeManager::SETTING_MP3_BETA_TESTING)) { $url .= '?key=t42kEMjzH7xpAjBFHAvEkC7rqAlw'; } // Download the file - $this->maniaControl->fileReader->loadFile($url, function ($file, $error) use (&$login, &$mapInfo, &$update) { + $self->maniaControl->fileReader->loadFile($url, function ($file, $error) use (&$self, &$login, &$mapInfo, &$update) { if (!$file) { // Download error - $this->maniaControl->chat->sendError('Download failed!', $login); + $self->maniaControl->chat->sendError('Download failed!', $login); return; } - $this->processMapFile($file, $mapInfo, $login, $update); + $self->processMapFile($file, $mapInfo, $login, $update); }); }); } diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index 88f82dd1..8e048506 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -715,13 +715,14 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer $votesPlugin->defineVote('forcespec', "Force $<" . $target->nickname . "$> Spec", true, $startMessage); - $votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) { - $this->maniaControl->chat->sendInformation('$sVote Successfully -> Player $<' . $target->nickname . '$> forced to Spectator!'); + $self = $this; + $votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$self, &$votesPlugin, &$target) { + $self->maniaControl->chat->sendInformation('$sVote Successfully -> Player $<' . $target->nickname . '$> forced to Spectator!'); $votesPlugin->undefineVote('forcespec'); try { - $this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); - $this->maniaControl->client->spectatorReleasePlayerSlot($target->login); + $self->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); + $self->maniaControl->client->spectatorReleasePlayerSlot($target->login); } catch(PlayerIsNotSpectatorException $e) { } }); @@ -738,13 +739,14 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer $votesPlugin->defineVote('kick', "Kick $<" . $target->nickname . "$>", true, $startMessage); - $votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) { - $this->maniaControl->chat->sendInformation('$sVote Successfully -> $<' . $target->nickname . '$> got Kicked!'); + $self = $this; + $votesPlugin->startVote($admin, 'kick', function ($result) use (&$self, &$votesPlugin, &$target) { + $self->maniaControl->chat->sendInformation('$sVote Successfully -> $<' . $target->nickname . '$> got Kicked!'); $votesPlugin->undefineVote('kick'); $message = '$39F You got kicked due a Public vote!$z '; try { - $this->maniaControl->client->kick($target->login, $message); + $self->maniaControl->client->kick($target->login, $message); } catch(LoginUnknownException $e) { } }); diff --git a/application/core/Server/UsageReporter.php b/application/core/Server/UsageReporter.php index 40971ec4..dd9f2d4e 100644 --- a/application/core/Server/UsageReporter.php +++ b/application/core/Server/UsageReporter.php @@ -93,10 +93,11 @@ class UsageReporter implements TimerListener { $json = json_encode($properties); $info = base64_encode($json); - $this->maniaControl->fileReader->loadFile(ManiaControl::URL_WEBSERVICE . "/usagereport?info=" . urlencode($info), function ($response, $error) { + $self = $this; + $this->maniaControl->fileReader->loadFile(ManiaControl::URL_WEBSERVICE . "/usagereport?info=" . urlencode($info), function ($response, $error) use(&$self){ $response = json_decode($response); if ($error || !$response) { - $this->maniaControl->log("Error while Sending data: " . $error); + $self->maniaControl->log("Error while Sending data: " . $error); } }); } diff --git a/application/core/Update/UpdateManager.php b/application/core/Update/UpdateManager.php index 8bbca6d2..d00fd0ce 100644 --- a/application/core/Update/UpdateManager.php +++ b/application/core/Update/UpdateManager.php @@ -195,44 +195,46 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener $updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL); if ($updateChannel != self::CHANNEL_NIGHTLY) { // Check update and send result message - $this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$player) { + $self = $this; + $this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self, &$player) { if (!$updateData) { - $this->maniaControl->chat->sendInformation('No Update available!', $player->login); + $self->maniaControl->chat->sendInformation('No Update available!', $player->login); return; } - $version = $this->maniaControl->client->getVersion(); + $version = $self->maniaControl->client->getVersion(); if($updateData->minDedicatedBuild > $version->build){ - $this->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login); + $self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login); return; } - $this->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login); + $self->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login); }); } else { // Special nightly channel updating - $this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$player) { + $self = $this; + $this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self, &$player) { if (!$updateData) { - $this->maniaControl->chat->sendInformation('No Update available!', $player->login); + $self->maniaControl->chat->sendInformation('No Update available!', $player->login); return; } - $version = $this->maniaControl->client->getVersion(); + $version = $self->maniaControl->client->getVersion(); if($updateData->minDedicatedBuild > $version->build){ - $this->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login); + $self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login); return; } - $buildTime = strtotime($this->currentBuildDate); + $buildTime = strtotime($self->currentBuildDate); $releaseTime = strtotime($updateData->releaseDate); if ($buildTime != '') { if ($buildTime >= $releaseTime) { - $this->maniaControl->chat->sendInformation('No new Build available, current build: ' . date("Y-m-d", $buildTime) . '!', $player->login); + $self->maniaControl->chat->sendInformation('No new Build available, current build: ' . date("Y-m-d", $buildTime) . '!', $player->login); return; } - $this->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available, current build: ' . $this->currentBuildDate . '!', $player->login); + $self->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available, current build: ' . $self->currentBuildDate . '!', $player->login); } else { - $this->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available!', $player->login); + $self->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available!', $player->login); } }, true); } @@ -325,26 +327,27 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener return; } - $this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$player) { + $self = $this; + $this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self,&$player) { if (!$updateData) { - $this->maniaControl->chat->sendError('Update is currently not possible!', $player->login); + $self->maniaControl->chat->sendError('Update is currently not possible!', $player->login); return; } - $version = $this->maniaControl->client->getVersion(); + $version = $self->maniaControl->client->getVersion(); if($updateData->minDedicatedBuild > $version->build){ - $this->maniaControl->chat->sendError("ManiaControl update version requires a newer Dedicated Server version!", $player->login); + $self->maniaControl->chat->sendError("ManiaControl update version requires a newer Dedicated Server version!", $player->login); return; } - $this->maniaControl->chat->sendInformation("Starting Update to Version v{$updateData->version}...", $player->login); - $this->maniaControl->log("Starting Update to Version v{$updateData->version}..."); - $performBackup = $this->maniaControl->settingManager->getSetting($this, self::SETTING_PERFORM_BACKUPS); - if ($performBackup && !$this->performBackup()) { - $this->maniaControl->chat->sendError('Creating backup failed.', $player->login); - $this->maniaControl->log("Creating backup failed."); + $self->maniaControl->chat->sendInformation("Starting Update to Version v{$updateData->version}...", $player->login); + $self->maniaControl->log("Starting Update to Version v{$updateData->version}..."); + $performBackup = $self->maniaControl->settingManager->getSetting($self, UpdateManager::SETTING_PERFORM_BACKUPS); + if ($performBackup && !$self->performBackup()) { + $self->maniaControl->chat->sendError('Creating backup failed.', $player->login); + $self->maniaControl->log("Creating backup failed."); } - $this->performCoreUpdate($updateData, $player); + $self->performCoreUpdate($updateData, $player); }, true); } @@ -467,10 +470,11 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener * @param bool $reopen */ private function updatePlugin($pluginData, Player $player = null, $reopen = false) { - $this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($updateFileContent, $error) use (&$updateData, &$player, &$pluginData, &$reopen) { - $this->maniaControl->log('[UPDATE] Now updating '.$pluginData->name.' ...'); + $self = $this; + $this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player, &$pluginData, &$reopen) { + $self->maniaControl->log('[UPDATE] Now updating '.$pluginData->name.' ...'); if ($player) { - $this->maniaControl->chat->sendInformation('Now updating '.$pluginData->name.' ...', $player->login); + $self->maniaControl->chat->sendInformation('Now updating '.$pluginData->name.' ...', $player->login); } $tempDir = ManiaControlDir . '/temp/'; if (!is_dir($tempDir)) { @@ -482,7 +486,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener if (!$bytes || $bytes <= 0) { trigger_error("Couldn't save plugin Zip."); if ($player) { - $this->maniaControl->chat->sendError('Update failed: Couldn\'t save plugin zip!', $player->login); + $self->maniaControl->chat->sendError('Update failed: Couldn\'t save plugin zip!', $player->login); } return false; } @@ -491,7 +495,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener if ($result !== true) { trigger_error("Couldn't open plugin Zip. ({$result})"); if ($player) { - $this->maniaControl->chat->sendError('Update failed: Couldn\'t open plugin zip!', $player->login); + $self->maniaControl->chat->sendError('Update failed: Couldn\'t open plugin zip!', $player->login); } return false; } @@ -501,15 +505,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener unlink($updateFileName); @rmdir($tempDir); - $this->maniaControl->log('[UPDATE] Successfully updated '.$pluginData->name.'!'); + $self->maniaControl->log('[UPDATE] Successfully updated '.$pluginData->name.'!'); if ($player) { - $this->maniaControl->chat->sendSuccess('Successfully updated '.$pluginData->name.'!', $player->login); - $this->maniaControl->pluginManager->deactivatePlugin($pluginData->pluginClass); - $this->maniaControl->pluginManager->activatePlugin($pluginData->pluginClass); + $self->maniaControl->chat->sendSuccess('Successfully updated '.$pluginData->name.'!', $player->login); + $self->maniaControl->pluginManager->deactivatePlugin($pluginData->pluginClass); + $self->maniaControl->pluginManager->activatePlugin($pluginData->pluginClass); if ($reopen) { - $menuId = $this->maniaControl->configurator->getMenuId('Plugins'); - $this->maniaControl->configurator->reopenMenu($player, $menuId); + $menuId = $self->maniaControl->configurator->getMenuId('Plugins'); + $self->maniaControl->configurator->reopenMenu($player, $menuId); } } }); @@ -523,12 +527,13 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener * @param bool $reopen */ private function installPlugin($pluginData, Player $player, $reopen = false) { - $this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($installFileContent, $error) use (&$updateData, &$player, &$pluginData, &$reopen) { + $self = $this; + $this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($installFileContent, $error) use (&$self, &$updateData, &$player, &$pluginData, &$reopen) { $pluginsDirectory = ManiaControlDir . '/plugins/'; $pluginFiles = scandir($pluginsDirectory); - $this->maniaControl->log('[UPDATE] Now installing '.$pluginData->name.' ...'); - $this->maniaControl->chat->sendInformation('Now installing '.$pluginData->name.' ...', $player->login); + $self->maniaControl->log('[UPDATE] Now installing '.$pluginData->name.' ...'); + $self->maniaControl->chat->sendInformation('Now installing '.$pluginData->name.' ...', $player->login); $tempDir = ManiaControlDir . '/temp/'; if (!is_dir($tempDir)) { @@ -539,14 +544,14 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener $bytes = file_put_contents($installFileName, $installFileContent); if (!$bytes || $bytes <= 0) { trigger_error("Couldn't save plugin Zip."); - $this->maniaControl->chat->sendError('Install failed: Couldn\'t save plugin zip!', $player->login); + $self->maniaControl->chat->sendError('Install failed: Couldn\'t save plugin zip!', $player->login); return false; } $zip = new \ZipArchive(); $result = $zip->open($installFileName); if ($result !== true) { trigger_error("Couldn't open plugin Zip. ({$result})"); - $this->maniaControl->chat->sendError('Install failed: Couldn\'t open plugin zip!', $player->login); + $self->maniaControl->chat->sendError('Install failed: Couldn\'t open plugin zip!', $player->login); return false; } @@ -572,7 +577,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener $dirPath = $pluginsDirectory . $newFile; if (is_dir($dirPath)) { - $this->maniaControl->pluginManager->loadPluginFiles($dirPath); + $self->maniaControl->pluginManager->loadPluginFiles($dirPath); continue; } } @@ -580,28 +585,28 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener $newClasses = array_diff($classesAfter, $classesBefore); foreach($newClasses as $className) { - if (!$this->maniaControl->pluginManager->isPluginClass($className)) { + if (!$self->maniaControl->pluginManager->isPluginClass($className)) { continue; } /** @var Plugin $className */ - $this->maniaControl->pluginManager->addPluginClass($className); - $className::prepare($this->maniaControl); + $self->maniaControl->pluginManager->addPluginClass($className); + $className::prepare($self->maniaControl); - if ($this->maniaControl->pluginManager->isPluginActive($className)) { + if ($self->maniaControl->pluginManager->isPluginActive($className)) { continue; } - if (!$this->maniaControl->pluginManager->getSavedPluginStatus($className)) { + if (!$self->maniaControl->pluginManager->getSavedPluginStatus($className)) { continue; } } - $this->maniaControl->log('[UPDATE] Successfully installed '.$pluginData->name.'!'); - $this->maniaControl->chat->sendSuccess('Successfully installed '.$pluginData->name.'!', $player->login); + $self->maniaControl->log('[UPDATE] Successfully installed '.$pluginData->name.'!'); + $self->maniaControl->chat->sendSuccess('Successfully installed '.$pluginData->name.'!', $player->login); if ($reopen) { - $menuId = $this->maniaControl->configurator->getMenuId('Install Plugins'); - $this->maniaControl->configurator->reopenMenu($player, $menuId); + $menuId = $self->maniaControl->configurator->getMenuId('Install Plugins'); + $self->maniaControl->configurator->reopenMenu($player, $menuId); } }); } @@ -750,7 +755,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener return false; } - $this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use (&$updateData, &$player) { + $self = $this; + $this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player) { $tempDir = ManiaControlDir . '/temp/'; if (!is_dir($tempDir)) { mkdir($tempDir); @@ -761,7 +767,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener if (!$bytes || $bytes <= 0) { trigger_error("Couldn't save Update Zip."); if ($player) { - $this->maniaControl->chat->sendError('Update failed: Couldn\'t save Update zip!', $player->login); + $self->maniaControl->chat->sendError('Update failed: Couldn\'t save Update zip!', $player->login); } return false; } @@ -770,7 +776,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener if ($result !== true) { trigger_error("Couldn't open Update Zip. ({$result})"); if ($player) { - $this->maniaControl->chat->sendError('Update failed: Couldn\'t open Update zip!', $player->login); + $self->maniaControl->chat->sendError('Update failed: Couldn\'t open Update zip!', $player->login); } return false; } @@ -781,14 +787,14 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener @rmdir($tempDir); //Set the Nightly Build Date - $this->setNightlyBuildDate($updateData->releaseDate); + $self->setNightlyBuildDate($updateData->releaseDate); if ($player) { - $this->maniaControl->chat->sendSuccess('Update finished!', $player->login); + $self->maniaControl->chat->sendSuccess('Update finished!', $player->login); } - $this->maniaControl->log("Update finished!"); + $self->maniaControl->log("Update finished!"); - $this->maniaControl->restart(); + $self->maniaControl->restart(); return true; }); diff --git a/application/plugins/CustomVotes.php b/application/plugins/CustomVotes.php index 6195d71b..1b830f77 100644 --- a/application/plugins/CustomVotes.php +++ b/application/plugins/CustomVotes.php @@ -26,7 +26,6 @@ use ManiaControl\Plugins\Plugin; use ManiaControl\Server\Server; use ManiaControl\Server\ServerCommands; use Maniaplanet\DedicatedServer\Structures\VoteRatio; -use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException; diff --git a/application/plugins/Dedimania/Dedimania.php b/application/plugins/Dedimania/Dedimania.php index 617b75eb..ffafd77b 100644 --- a/application/plugins/Dedimania/Dedimania.php +++ b/application/plugins/Dedimania/Dedimania.php @@ -145,7 +145,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu if (is_array($data)) { foreach($data as $index => $methodResponse) { if (xmlrpc_is_fault($methodResponse)) { - $self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPENSESSION); + $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_OPENSESSION); } else if ($index <= 0) { $responseData = $methodResponse[0]; $self->dedimaniaData->sessionId = $responseData['SessionId']; @@ -213,7 +213,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu if (is_array($data)) { foreach($data as $index => $methodResponse) { if (xmlrpc_is_fault($methodResponse)) { - $self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT); + $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_PLAYERCONNECT); } else if ($index <= 0) { $responseData = $methodResponse[0]; $self->dedimaniaData->addPlayer(new DedimaniaPlayer($responseData)); @@ -223,8 +223,8 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu $self->fetchDedimaniaRecords(true); } } - if ($self->maniaControl->settingManager->getSetting($self, self::SETTING_WIDGET_ENABLE)) { - $manialink = $this->buildManialink(); + if ($self->maniaControl->settingManager->getSetting($self, Dedimania::SETTING_WIDGET_ENABLE)) { + $manialink = $self->buildManialink(); $self->maniaControl->manialinkManager->sendManialink($manialink, $player->login); } } @@ -260,7 +260,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu if (is_array($data)) { foreach($data as $methodResponse) { if (xmlrpc_is_fault($methodResponse)) { - $self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT); + $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_PLAYERDISCONNECT); } } } else { @@ -334,11 +334,11 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu $self->maniaControl->log("Dedimania Error: " . $error); } - $data = $this->decode($data); + $data = $self->decode($data); if (is_array($data)) { foreach($data as $index => $methodResponse) { if (xmlrpc_is_fault($methodResponse)) { - $self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SETCHALLENGETIMES); + $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_SETCHALLENGETIMES); } else { if ($index <= 0) { // Called method response @@ -351,6 +351,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu // Warnings and TTR $errors = $methodResponse[0]['methods'][0]['errors']; + //TODO ? } } } @@ -384,7 +385,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu if (is_array($data)) { foreach($data as $methodResponse) { if (xmlrpc_is_fault($methodResponse)) { - $self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATESERVERPLAYERS); + $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_UPDATESERVERPLAYERS); } } } else { @@ -616,7 +617,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu if (is_array($data)) { foreach($data as $index => $methodResponse) { if (xmlrpc_is_fault($methodResponse)) { - $self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GETRECORDS); + $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_GETRECORDS); return false; } else if ($index <= 0) { $responseData = $methodResponse[0]; @@ -633,8 +634,8 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu } } } - $this->updateManialink = true; - $this->maniaControl->callbackManager->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records); + $self->updateManialink = true; + $self->maniaControl->callbackManager->triggerCallback(Dedimania::CB_DEDIMANIA_UPDATED, $self->dedimaniaData->records); return true; }, $content, true); @@ -662,7 +663,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu if (is_array($data)) { foreach($data as $methodResponse) { if (xmlrpc_is_fault($methodResponse)) { - $self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECKSESSION); + $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_CHECKSESSION); } else { $responseData = $methodResponse[0]; if (is_bool($responseData)) { diff --git a/application/plugins/Donations.php b/application/plugins/Donations.php index b7edd685..669ae114 100644 --- a/application/plugins/Donations.php +++ b/application/plugins/Donations.php @@ -331,30 +331,31 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { } //Send and Handle the Bill - $this->maniaControl->billManager->sendBill(function ($data, $status) use (&$player, $amount, $receiver) { + $self = $this; + $this->maniaControl->billManager->sendBill(function ($data, $status) use (&$self, &$player, $amount, $receiver) { switch($status) { case BillManager::DONATED_TO_SERVER: - if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_ANNOUNCE_SERVERDONATION, true) && $amount >= $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, true)) { + if ($self->maniaControl->settingManager->getSetting($self, DonationPlugin::SETTING_ANNOUNCE_SERVERDONATION, true) && $amount >= $self->maniaControl->settingManager->getSetting($self, DonationPlugin::SETTING_MIN_AMOUNT_SHOWN, true)) { $login = null; $message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.'; } else { $login = $player->login; $message = 'Donation successful! Thanks.'; } - $this->maniaControl->chat->sendSuccess($message, $login); - $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->index, $amount); + $self->maniaControl->chat->sendSuccess($message, $login); + $self->maniaControl->statisticManager->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $self->maniaControl->server->index, $amount); break; case BillManager::DONATED_TO_RECEIVER: $message = "Successfully donated {$amount} to '{$receiver}'!"; - $this->maniaControl->chat->sendSuccess($message, $player->login); + $self->maniaControl->chat->sendSuccess($message, $player->login); break; case BillManager::PLAYER_REFUSED_DONATION: $message = 'Transaction cancelled.'; - $this->maniaControl->chat->sendError($message, $player->login); + $self->maniaControl->chat->sendError($message, $player->login); break; case BillManager::ERROR_WHILE_TRANSACTION: $message = $data; - $this->maniaControl->chat->sendError($message, $player->login); + $self->maniaControl->chat->sendError($message, $player->login); break; } }, $player, $amount, $message); @@ -392,19 +393,20 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { } $message = 'Payout from $<' . $this->maniaControl->client->getServerName() . '$>.'; - $this->maniaControl->billManager->sendPlanets(function ($data, $status) use (&$player, $amount, $receiver) { + $self = $this; + $this->maniaControl->billManager->sendPlanets(function ($data, $status) use (&$self, &$player, $amount, $receiver) { switch($status) { case BillManager::PAYED_FROM_SERVER: $message = "Successfully payed out {$amount} to '{$receiver}'!"; - $this->maniaControl->chat->sendSuccess($message, $player->login); + $self->maniaControl->chat->sendSuccess($message, $player->login); break; case BillManager::PLAYER_REFUSED_DONATION: $message = 'Transaction cancelled.'; - $this->maniaControl->chat->sendError($message, $player->login); + $self->maniaControl->chat->sendError($message, $player->login); break; case BillManager::ERROR_WHILE_TRANSACTION: $message = $data; - $this->maniaControl->chat->sendError($message, $player->login); + $self->maniaControl->chat->sendError($message, $player->login); break; } }, $receiver, $amount, $message); diff --git a/application/plugins/Karma.php b/application/plugins/Karma.php index 73788b56..ff9fa734 100644 --- a/application/plugins/Karma.php +++ b/application/plugins/Karma.php @@ -655,23 +655,24 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $this->mxKarma['connectionInProgress'] = true; - $this->maniaControl->fileReader->loadFile($query, function ($data, $error) use ($mxKarmaCode) { + $self = $this; + $this->maniaControl->fileReader->loadFile($query, function ($data, $error) use (&$self, $mxKarmaCode) { if (!$error) { $data = json_decode($data); if ($data->success) { - $this->mxKarma['session'] = $data->data; - $this->activateSession($mxKarmaCode); + $self->mxKarma['session'] = $data->data; + $self->activateSession($mxKarmaCode); } else { - $this->maniaControl->log("Error while authenticating on Mania-Exchange Karma"); + $self->maniaControl->log("Error while authenticating on Mania-Exchange Karma"); //TODO remove temp trigger - $this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message); - $this->mxKarma['connectionInProgress'] = false; + $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message); + $self->mxKarma['connectionInProgress'] = false; } } else { - $this->maniaControl->log($error); + $self->maniaControl->log($error); //TODO remove temp trigger - $this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); - $this->mxKarma['connectionInProgress'] = false; + $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); + $self->mxKarma['connectionInProgress'] = false; } }, "application/json", 1000); } @@ -688,26 +689,27 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $query .= '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey); $query .= '&activationHash=' . urlencode($hash); - $this->maniaControl->fileReader->loadFile($query, function ($data, $error) use ($query) { + $self = $this; + $this->maniaControl->fileReader->loadFile($query, function ($data, $error) use (&$self, $query) { if (!$error) { $data = json_decode($data); if ($data->success && $data->data->activated) { - $this->maniaControl->log("Successfully authenticated on Mania-Exchange Karma"); - $this->mxKarma['connectionInProgress'] = false; + $self->maniaControl->log("Successfully authenticated on Mania-Exchange Karma"); + $self->mxKarma['connectionInProgress'] = false; //Fetch the Mx Karma Votes - $this->getMxKarmaVotes(); + $self->getMxKarmaVotes(); } else { - $this->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message); + $self->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message); //TODO remove temp trigger - $this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query); - $this->mxKarma['connectionInProgress'] = false; + $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query); + $self->mxKarma['connectionInProgress'] = false; } } else { //TODO remove temp trigger - $this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); - $this->maniaControl->log($error); - $this->mxKarma['connectionInProgress'] = false; + $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); + $self->maniaControl->log($error); + $self->mxKarma['connectionInProgress'] = false; } }, "application/json", 1000); } @@ -756,33 +758,34 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } $content = json_encode($properties); - $this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_GETMAPRATING . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use (&$player) { + $self = $this; + $this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_GETMAPRATING . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use (&$self, &$player) { if (!$error) { $data = json_decode($data); if ($data->success) { //Fetch averages if its for the whole server if (!$player) { - $this->mxKarma["voteCount"] = $data->data->votecount; - $this->mxKarma["voteAverage"] = $data->data->voteaverage; - $this->mxKarma["modeVoteCount"] = $data->data->modevotecount; - $this->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage; + $self->mxKarma["voteCount"] = $data->data->votecount; + $self->mxKarma["voteAverage"] = $data->data->voteaverage; + $self->mxKarma["modeVoteCount"] = $data->data->modevotecount; + $self->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage; } foreach($data->data->votes as $votes) { - $this->mxKarma["votes"][$votes->login] = $votes->vote; + $self->mxKarma["votes"][$votes->login] = $votes->vote; } - $this->updateManialink = true; - $this->maniaControl->callbackManager->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma); - $this->maniaControl->log("MX-Karma Votes successfully fetched"); + $self->updateManialink = true; + $self->maniaControl->callbackManager->triggerCallback($self::CB_KARMA_MXUPDATED, $self->mxKarma); + $self->maniaControl->log("MX-Karma Votes successfully fetched"); } else { - $this->maniaControl->log("Error while fetching votes: " . $data->data->message); + $self->maniaControl->log("Error while fetching votes: " . $data->data->message); //TODO remove temp trigger - $this->maniaControl->errorHandler->triggerDebugNotice("Error while fetching votes: " . $data->data->message . " " . self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey)); + $self->maniaControl->errorHandler->triggerDebugNotice("Error while fetching votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . KarmaPlugin::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey)); } } else { - $this->maniaControl->log($error); + $self->maniaControl->log($error); } }, $content, false, 'application/json'); } @@ -911,18 +914,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $properties['isimport'] = $import; $content = json_encode($properties); - $this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) { + + $self = $this; + $this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use(&$self){ if (!$error) { $data = json_decode($data); if ($data->success) { - $this->maniaControl->log("Votes successfully permitted"); + $self->maniaControl->log("Votes successfully permitted"); } else { - $this->maniaControl->log("Error while updating votes: " . $data->data->message); + $self->maniaControl->log("Error while updating votes: " . $data->data->message); //TODO remove temp trigger - $this->maniaControl->errorHandler->triggerDebugNotice("Error while updating votes: " . $data->data->message . " " . self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey)); + $self->maniaControl->errorHandler->triggerDebugNotice("Error while updating votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . $self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey)); } } else { - $this->maniaControl->log($error); + $self->maniaControl->log($error); } }, $content, false, 'application/json'); }