php 5.3 compatiblity

This commit is contained in:
kremsy 2014-04-20 14:52:26 +02:00 committed by Steffen Schröder
parent ea9c929ec3
commit 7408ffb4ac
11 changed files with 165 additions and 148 deletions

View File

@ -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) { 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; return;
} }
$this->showManiaExchangeList($maps, $player); $self->showManiaExchangeList($maps, $player);
}; }, $searchString, $author, $environment);
// search for matching maps
$this->maniaControl->mapManager->mxManager->getMapsAsync($function, $searchString, $author, $environment);
} }
/** /**

View File

@ -86,8 +86,9 @@ class CustomUIManager implements CallbackListener, TimerListener {
$this->updateManialink($player); $this->updateManialink($player);
//send it again after 500ms //send it again after 500ms
$this->maniaControl->timerManager->registerOneTimeListening($this, function($time) use (&$player){ $self = $this;
$this->updateManialink($player); $this->maniaControl->timerManager->registerOneTimeListening($this, function($time) use (&$self, &$player){
$self->updateManialink($player);
},500); },500);
} }

View File

@ -545,18 +545,19 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** @var Map $map */ /** @var Map $map */
$votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message); $votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message);
$votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) { $self = $this;
$this->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!'); $votesPlugin->startVote($player, 'switchmap', function ($result) use (&$self, &$votesPlugin, &$map) {
$self->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!');
$votesPlugin->undefineVote('switchmap'); $votesPlugin->undefineVote('switchmap');
try { try {
$index = $this->maniaControl->mapManager->getMapIndex($map); $index = $self->maniaControl->mapManager->getMapIndex($map);
$this->maniaControl->client->jumpToMapIndex($index); $self->maniaControl->client->jumpToMapIndex($index);
} catch(Exception $e) { } catch(Exception $e) {
//TODO temp added 19.04.2014 //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; break;

View File

@ -586,27 +586,28 @@ class MapManager implements CallbackListener {
public function addMapFromMx($mapId, $login, $update = false) { public function addMapFromMx($mapId, $login, $update = false) {
if (is_numeric($mapId)) { if (is_numeric($mapId)) {
// Check if map exists // 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)) { if (!$mapInfo || !isset($mapInfo->uploaded)) {
// Invalid id // Invalid id
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login); $self->maniaControl->chat->sendError('Invalid MX-Id!', $login);
return; return;
} }
// TODO hardcoded during closed beta, later take just $mapInfo->url again // TODO hardcoded during closed beta, later take just $mapInfo->url again
$url = 'http://' . $mapInfo->prefix . '.mania-exchange.com/' . $mapInfo->dir . '/download/' . $mapInfo->id; $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'; $url .= '?key=t42kEMjzH7xpAjBFHAvEkC7rqAlw';
} }
// Download the file // 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) { if (!$file) {
// Download error // Download error
$this->maniaControl->chat->sendError('Download failed!', $login); $self->maniaControl->chat->sendError('Download failed!', $login);
return; return;
} }
$this->processMapFile($file, $mapInfo, $login, $update); $self->processMapFile($file, $mapInfo, $login, $update);
}); });
}); });
} }

View File

@ -715,13 +715,14 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$votesPlugin->defineVote('forcespec', "Force $<" . $target->nickname . "$> Spec", true, $startMessage); $votesPlugin->defineVote('forcespec', "Force $<" . $target->nickname . "$> Spec", true, $startMessage);
$votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) { $self = $this;
$this->maniaControl->chat->sendInformation('$sVote Successfully -> Player $<' . $target->nickname . '$> forced to Spectator!'); $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'); $votesPlugin->undefineVote('forcespec');
try { try {
$this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); $self->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login); $self->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(PlayerIsNotSpectatorException $e) { } catch(PlayerIsNotSpectatorException $e) {
} }
}); });
@ -738,13 +739,14 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$votesPlugin->defineVote('kick', "Kick $<" . $target->nickname . "$>", true, $startMessage); $votesPlugin->defineVote('kick', "Kick $<" . $target->nickname . "$>", true, $startMessage);
$votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) { $self = $this;
$this->maniaControl->chat->sendInformation('$sVote Successfully -> $<' . $target->nickname . '$> got Kicked!'); $votesPlugin->startVote($admin, 'kick', function ($result) use (&$self, &$votesPlugin, &$target) {
$self->maniaControl->chat->sendInformation('$sVote Successfully -> $<' . $target->nickname . '$> got Kicked!');
$votesPlugin->undefineVote('kick'); $votesPlugin->undefineVote('kick');
$message = '$39F You got kicked due a Public vote!$z '; $message = '$39F You got kicked due a Public vote!$z ';
try { try {
$this->maniaControl->client->kick($target->login, $message); $self->maniaControl->client->kick($target->login, $message);
} catch(LoginUnknownException $e) { } catch(LoginUnknownException $e) {
} }
}); });

View File

@ -93,10 +93,11 @@ class UsageReporter implements TimerListener {
$json = json_encode($properties); $json = json_encode($properties);
$info = base64_encode($json); $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); $response = json_decode($response);
if ($error || !$response) { if ($error || !$response) {
$this->maniaControl->log("Error while Sending data: " . $error); $self->maniaControl->log("Error while Sending data: " . $error);
} }
}); });
} }

View File

@ -195,44 +195,46 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL); $updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
if ($updateChannel != self::CHANNEL_NIGHTLY) { if ($updateChannel != self::CHANNEL_NIGHTLY) {
// Check update and send result message // 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) { if (!$updateData) {
$this->maniaControl->chat->sendInformation('No Update available!', $player->login); $self->maniaControl->chat->sendInformation('No Update available!', $player->login);
return; return;
} }
$version = $this->maniaControl->client->getVersion(); $version = $self->maniaControl->client->getVersion();
if($updateData->minDedicatedBuild > $version->build){ 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; 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 { } else {
// Special nightly channel updating // Special nightly channel updating
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$player) { $self = $this;
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self, &$player) {
if (!$updateData) { if (!$updateData) {
$this->maniaControl->chat->sendInformation('No Update available!', $player->login); $self->maniaControl->chat->sendInformation('No Update available!', $player->login);
return; return;
} }
$version = $this->maniaControl->client->getVersion(); $version = $self->maniaControl->client->getVersion();
if($updateData->minDedicatedBuild > $version->build){ 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; return;
} }
$buildTime = strtotime($this->currentBuildDate); $buildTime = strtotime($self->currentBuildDate);
$releaseTime = strtotime($updateData->releaseDate); $releaseTime = strtotime($updateData->releaseDate);
if ($buildTime != '') { if ($buildTime != '') {
if ($buildTime >= $releaseTime) { 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; 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 { } 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); }, true);
} }
@ -325,26 +327,27 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return; return;
} }
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$player) { $self = $this;
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self,&$player) {
if (!$updateData) { 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; return;
} }
$version = $this->maniaControl->client->getVersion(); $version = $self->maniaControl->client->getVersion();
if($updateData->minDedicatedBuild > $version->build){ 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; return;
} }
$this->maniaControl->chat->sendInformation("Starting Update to Version v{$updateData->version}...", $player->login); $self->maniaControl->chat->sendInformation("Starting Update to Version v{$updateData->version}...", $player->login);
$this->maniaControl->log("Starting Update to Version v{$updateData->version}..."); $self->maniaControl->log("Starting Update to Version v{$updateData->version}...");
$performBackup = $this->maniaControl->settingManager->getSetting($this, self::SETTING_PERFORM_BACKUPS); $performBackup = $self->maniaControl->settingManager->getSetting($self, UpdateManager::SETTING_PERFORM_BACKUPS);
if ($performBackup && !$this->performBackup()) { if ($performBackup && !$self->performBackup()) {
$this->maniaControl->chat->sendError('Creating backup failed.', $player->login); $self->maniaControl->chat->sendError('Creating backup failed.', $player->login);
$this->maniaControl->log("Creating backup failed."); $self->maniaControl->log("Creating backup failed.");
} }
$this->performCoreUpdate($updateData, $player); $self->performCoreUpdate($updateData, $player);
}, true); }, true);
} }
@ -467,10 +470,11 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* @param bool $reopen * @param bool $reopen
*/ */
private function updatePlugin($pluginData, Player $player = null, $reopen = false) { private function updatePlugin($pluginData, Player $player = null, $reopen = false) {
$this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($updateFileContent, $error) use (&$updateData, &$player, &$pluginData, &$reopen) { $self = $this;
$this->maniaControl->log('[UPDATE] Now updating '.$pluginData->name.' ...'); $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) { 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/'; $tempDir = ManiaControlDir . '/temp/';
if (!is_dir($tempDir)) { if (!is_dir($tempDir)) {
@ -482,7 +486,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
trigger_error("Couldn't save plugin Zip."); trigger_error("Couldn't save plugin Zip.");
if ($player) { 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; return false;
} }
@ -491,7 +495,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if ($result !== true) { if ($result !== true) {
trigger_error("Couldn't open plugin Zip. ({$result})"); trigger_error("Couldn't open plugin Zip. ({$result})");
if ($player) { 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; return false;
} }
@ -501,15 +505,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
unlink($updateFileName); unlink($updateFileName);
@rmdir($tempDir); @rmdir($tempDir);
$this->maniaControl->log('[UPDATE] Successfully updated '.$pluginData->name.'!'); $self->maniaControl->log('[UPDATE] Successfully updated '.$pluginData->name.'!');
if ($player) { if ($player) {
$this->maniaControl->chat->sendSuccess('Successfully updated '.$pluginData->name.'!', $player->login); $self->maniaControl->chat->sendSuccess('Successfully updated '.$pluginData->name.'!', $player->login);
$this->maniaControl->pluginManager->deactivatePlugin($pluginData->pluginClass); $self->maniaControl->pluginManager->deactivatePlugin($pluginData->pluginClass);
$this->maniaControl->pluginManager->activatePlugin($pluginData->pluginClass); $self->maniaControl->pluginManager->activatePlugin($pluginData->pluginClass);
if ($reopen) { if ($reopen) {
$menuId = $this->maniaControl->configurator->getMenuId('Plugins'); $menuId = $self->maniaControl->configurator->getMenuId('Plugins');
$this->maniaControl->configurator->reopenMenu($player, $menuId); $self->maniaControl->configurator->reopenMenu($player, $menuId);
} }
} }
}); });
@ -523,12 +527,13 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* @param bool $reopen * @param bool $reopen
*/ */
private function installPlugin($pluginData, Player $player, $reopen = false) { 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/'; $pluginsDirectory = ManiaControlDir . '/plugins/';
$pluginFiles = scandir($pluginsDirectory); $pluginFiles = scandir($pluginsDirectory);
$this->maniaControl->log('[UPDATE] Now installing '.$pluginData->name.' ...'); $self->maniaControl->log('[UPDATE] Now installing '.$pluginData->name.' ...');
$this->maniaControl->chat->sendInformation('Now installing '.$pluginData->name.' ...', $player->login); $self->maniaControl->chat->sendInformation('Now installing '.$pluginData->name.' ...', $player->login);
$tempDir = ManiaControlDir . '/temp/'; $tempDir = ManiaControlDir . '/temp/';
if (!is_dir($tempDir)) { if (!is_dir($tempDir)) {
@ -539,14 +544,14 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$bytes = file_put_contents($installFileName, $installFileContent); $bytes = file_put_contents($installFileName, $installFileContent);
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
trigger_error("Couldn't save plugin Zip."); 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; return false;
} }
$zip = new \ZipArchive(); $zip = new \ZipArchive();
$result = $zip->open($installFileName); $result = $zip->open($installFileName);
if ($result !== true) { if ($result !== true) {
trigger_error("Couldn't open plugin Zip. ({$result})"); 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; return false;
} }
@ -572,7 +577,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$dirPath = $pluginsDirectory . $newFile; $dirPath = $pluginsDirectory . $newFile;
if (is_dir($dirPath)) { if (is_dir($dirPath)) {
$this->maniaControl->pluginManager->loadPluginFiles($dirPath); $self->maniaControl->pluginManager->loadPluginFiles($dirPath);
continue; continue;
} }
} }
@ -580,28 +585,28 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$newClasses = array_diff($classesAfter, $classesBefore); $newClasses = array_diff($classesAfter, $classesBefore);
foreach($newClasses as $className) { foreach($newClasses as $className) {
if (!$this->maniaControl->pluginManager->isPluginClass($className)) { if (!$self->maniaControl->pluginManager->isPluginClass($className)) {
continue; continue;
} }
/** @var Plugin $className */ /** @var Plugin $className */
$this->maniaControl->pluginManager->addPluginClass($className); $self->maniaControl->pluginManager->addPluginClass($className);
$className::prepare($this->maniaControl); $className::prepare($self->maniaControl);
if ($this->maniaControl->pluginManager->isPluginActive($className)) { if ($self->maniaControl->pluginManager->isPluginActive($className)) {
continue; continue;
} }
if (!$this->maniaControl->pluginManager->getSavedPluginStatus($className)) { if (!$self->maniaControl->pluginManager->getSavedPluginStatus($className)) {
continue; continue;
} }
} }
$this->maniaControl->log('[UPDATE] Successfully installed '.$pluginData->name.'!'); $self->maniaControl->log('[UPDATE] Successfully installed '.$pluginData->name.'!');
$this->maniaControl->chat->sendSuccess('Successfully installed '.$pluginData->name.'!', $player->login); $self->maniaControl->chat->sendSuccess('Successfully installed '.$pluginData->name.'!', $player->login);
if ($reopen) { if ($reopen) {
$menuId = $this->maniaControl->configurator->getMenuId('Install Plugins'); $menuId = $self->maniaControl->configurator->getMenuId('Install Plugins');
$this->maniaControl->configurator->reopenMenu($player, $menuId); $self->maniaControl->configurator->reopenMenu($player, $menuId);
} }
}); });
} }
@ -750,7 +755,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return false; 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/'; $tempDir = ManiaControlDir . '/temp/';
if (!is_dir($tempDir)) { if (!is_dir($tempDir)) {
mkdir($tempDir); mkdir($tempDir);
@ -761,7 +767,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
trigger_error("Couldn't save Update Zip."); trigger_error("Couldn't save Update Zip.");
if ($player) { 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; return false;
} }
@ -770,7 +776,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if ($result !== true) { if ($result !== true) {
trigger_error("Couldn't open Update Zip. ({$result})"); trigger_error("Couldn't open Update Zip. ({$result})");
if ($player) { 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; return false;
} }
@ -781,14 +787,14 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
@rmdir($tempDir); @rmdir($tempDir);
//Set the Nightly Build Date //Set the Nightly Build Date
$this->setNightlyBuildDate($updateData->releaseDate); $self->setNightlyBuildDate($updateData->releaseDate);
if ($player) { 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; return true;
}); });

View File

@ -26,7 +26,6 @@ use ManiaControl\Plugins\Plugin;
use ManiaControl\Server\Server; use ManiaControl\Server\Server;
use ManiaControl\Server\ServerCommands; use ManiaControl\Server\ServerCommands;
use Maniaplanet\DedicatedServer\Structures\VoteRatio; use Maniaplanet\DedicatedServer\Structures\VoteRatio;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException; use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;

View File

@ -145,7 +145,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
if (is_array($data)) { if (is_array($data)) {
foreach($data as $index => $methodResponse) { foreach($data as $index => $methodResponse) {
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPENSESSION); $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_OPENSESSION);
} else if ($index <= 0) { } else if ($index <= 0) {
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
$self->dedimaniaData->sessionId = $responseData['SessionId']; $self->dedimaniaData->sessionId = $responseData['SessionId'];
@ -213,7 +213,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
if (is_array($data)) { if (is_array($data)) {
foreach($data as $index => $methodResponse) { foreach($data as $index => $methodResponse) {
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT); $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_PLAYERCONNECT);
} else if ($index <= 0) { } else if ($index <= 0) {
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
$self->dedimaniaData->addPlayer(new DedimaniaPlayer($responseData)); $self->dedimaniaData->addPlayer(new DedimaniaPlayer($responseData));
@ -223,8 +223,8 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
$self->fetchDedimaniaRecords(true); $self->fetchDedimaniaRecords(true);
} }
} }
if ($self->maniaControl->settingManager->getSetting($self, self::SETTING_WIDGET_ENABLE)) { if ($self->maniaControl->settingManager->getSetting($self, Dedimania::SETTING_WIDGET_ENABLE)) {
$manialink = $this->buildManialink(); $manialink = $self->buildManialink();
$self->maniaControl->manialinkManager->sendManialink($manialink, $player->login); $self->maniaControl->manialinkManager->sendManialink($manialink, $player->login);
} }
} }
@ -260,7 +260,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
if (is_array($data)) { if (is_array($data)) {
foreach($data as $methodResponse) { foreach($data as $methodResponse) {
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT); $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_PLAYERDISCONNECT);
} }
} }
} else { } else {
@ -334,11 +334,11 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
$self->maniaControl->log("Dedimania Error: " . $error); $self->maniaControl->log("Dedimania Error: " . $error);
} }
$data = $this->decode($data); $data = $self->decode($data);
if (is_array($data)) { if (is_array($data)) {
foreach($data as $index => $methodResponse) { foreach($data as $index => $methodResponse) {
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SETCHALLENGETIMES); $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_SETCHALLENGETIMES);
} else { } else {
if ($index <= 0) { if ($index <= 0) {
// Called method response // Called method response
@ -351,6 +351,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
// Warnings and TTR // Warnings and TTR
$errors = $methodResponse[0]['methods'][0]['errors']; $errors = $methodResponse[0]['methods'][0]['errors'];
//TODO ?
} }
} }
} }
@ -384,7 +385,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
if (is_array($data)) { if (is_array($data)) {
foreach($data as $methodResponse) { foreach($data as $methodResponse) {
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATESERVERPLAYERS); $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_UPDATESERVERPLAYERS);
} }
} }
} else { } else {
@ -616,7 +617,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
if (is_array($data)) { if (is_array($data)) {
foreach($data as $index => $methodResponse) { foreach($data as $index => $methodResponse) {
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GETRECORDS); $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_GETRECORDS);
return false; return false;
} else if ($index <= 0) { } else if ($index <= 0) {
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
@ -633,8 +634,8 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
} }
} }
} }
$this->updateManialink = true; $self->updateManialink = true;
$this->maniaControl->callbackManager->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records); $self->maniaControl->callbackManager->triggerCallback(Dedimania::CB_DEDIMANIA_UPDATED, $self->dedimaniaData->records);
return true; return true;
}, $content, true); }, $content, true);
@ -662,7 +663,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
if (is_array($data)) { if (is_array($data)) {
foreach($data as $methodResponse) { foreach($data as $methodResponse) {
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECKSESSION); $self->handleXmlRpcFault($methodResponse, Dedimania::DEDIMANIA_CHECKSESSION);
} else { } else {
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
if (is_bool($responseData)) { if (is_bool($responseData)) {

View File

@ -331,30 +331,31 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
} }
//Send and Handle the Bill //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) { switch($status) {
case BillManager::DONATED_TO_SERVER: 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; $login = null;
$message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.'; $message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.';
} else { } else {
$login = $player->login; $login = $player->login;
$message = 'Donation successful! Thanks.'; $message = 'Donation successful! Thanks.';
} }
$this->maniaControl->chat->sendSuccess($message, $login); $self->maniaControl->chat->sendSuccess($message, $login);
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->index, $amount); $self->maniaControl->statisticManager->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $self->maniaControl->server->index, $amount);
break; break;
case BillManager::DONATED_TO_RECEIVER: case BillManager::DONATED_TO_RECEIVER:
$message = "Successfully donated {$amount} to '{$receiver}'!"; $message = "Successfully donated {$amount} to '{$receiver}'!";
$this->maniaControl->chat->sendSuccess($message, $player->login); $self->maniaControl->chat->sendSuccess($message, $player->login);
break; break;
case BillManager::PLAYER_REFUSED_DONATION: case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.'; $message = 'Transaction cancelled.';
$this->maniaControl->chat->sendError($message, $player->login); $self->maniaControl->chat->sendError($message, $player->login);
break; break;
case BillManager::ERROR_WHILE_TRANSACTION: case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data; $message = $data;
$this->maniaControl->chat->sendError($message, $player->login); $self->maniaControl->chat->sendError($message, $player->login);
break; break;
} }
}, $player, $amount, $message); }, $player, $amount, $message);
@ -392,19 +393,20 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
} }
$message = 'Payout from $<' . $this->maniaControl->client->getServerName() . '$>.'; $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) { switch($status) {
case BillManager::PAYED_FROM_SERVER: case BillManager::PAYED_FROM_SERVER:
$message = "Successfully payed out {$amount} to '{$receiver}'!"; $message = "Successfully payed out {$amount} to '{$receiver}'!";
$this->maniaControl->chat->sendSuccess($message, $player->login); $self->maniaControl->chat->sendSuccess($message, $player->login);
break; break;
case BillManager::PLAYER_REFUSED_DONATION: case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.'; $message = 'Transaction cancelled.';
$this->maniaControl->chat->sendError($message, $player->login); $self->maniaControl->chat->sendError($message, $player->login);
break; break;
case BillManager::ERROR_WHILE_TRANSACTION: case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data; $message = $data;
$this->maniaControl->chat->sendError($message, $player->login); $self->maniaControl->chat->sendError($message, $player->login);
break; break;
} }
}, $receiver, $amount, $message); }, $receiver, $amount, $message);

View File

@ -655,23 +655,24 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$this->mxKarma['connectionInProgress'] = true; $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) { if (!$error) {
$data = json_decode($data); $data = json_decode($data);
if ($data->success) { if ($data->success) {
$this->mxKarma['session'] = $data->data; $self->mxKarma['session'] = $data->data;
$this->activateSession($mxKarmaCode); $self->activateSession($mxKarmaCode);
} else { } 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 //TODO remove temp trigger
$this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message); $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
$this->mxKarma['connectionInProgress'] = false; $self->mxKarma['connectionInProgress'] = false;
} }
} else { } else {
$this->maniaControl->log($error); $self->maniaControl->log($error);
//TODO remove temp trigger //TODO remove temp trigger
$this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
$this->mxKarma['connectionInProgress'] = false; $self->mxKarma['connectionInProgress'] = false;
} }
}, "application/json", 1000); }, "application/json", 1000);
} }
@ -688,26 +689,27 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$query .= '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey); $query .= '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey);
$query .= '&activationHash=' . urlencode($hash); $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) { if (!$error) {
$data = json_decode($data); $data = json_decode($data);
if ($data->success && $data->data->activated) { if ($data->success && $data->data->activated) {
$this->maniaControl->log("Successfully authenticated on Mania-Exchange Karma"); $self->maniaControl->log("Successfully authenticated on Mania-Exchange Karma");
$this->mxKarma['connectionInProgress'] = false; $self->mxKarma['connectionInProgress'] = false;
//Fetch the Mx Karma Votes //Fetch the Mx Karma Votes
$this->getMxKarmaVotes(); $self->getMxKarmaVotes();
} else { } 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 //TODO remove temp trigger
$this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query); $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query);
$this->mxKarma['connectionInProgress'] = false; $self->mxKarma['connectionInProgress'] = false;
} }
} else { } else {
//TODO remove temp trigger //TODO remove temp trigger
$this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
$this->maniaControl->log($error); $self->maniaControl->log($error);
$this->mxKarma['connectionInProgress'] = false; $self->mxKarma['connectionInProgress'] = false;
} }
}, "application/json", 1000); }, "application/json", 1000);
} }
@ -756,33 +758,34 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
$content = json_encode($properties); $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) { if (!$error) {
$data = json_decode($data); $data = json_decode($data);
if ($data->success) { if ($data->success) {
//Fetch averages if its for the whole server //Fetch averages if its for the whole server
if (!$player) { if (!$player) {
$this->mxKarma["voteCount"] = $data->data->votecount; $self->mxKarma["voteCount"] = $data->data->votecount;
$this->mxKarma["voteAverage"] = $data->data->voteaverage; $self->mxKarma["voteAverage"] = $data->data->voteaverage;
$this->mxKarma["modeVoteCount"] = $data->data->modevotecount; $self->mxKarma["modeVoteCount"] = $data->data->modevotecount;
$this->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage; $self->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage;
} }
foreach($data->data->votes as $votes) { foreach($data->data->votes as $votes) {
$this->mxKarma["votes"][$votes->login] = $votes->vote; $self->mxKarma["votes"][$votes->login] = $votes->vote;
} }
$this->updateManialink = true; $self->updateManialink = true;
$this->maniaControl->callbackManager->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma); $self->maniaControl->callbackManager->triggerCallback($self::CB_KARMA_MXUPDATED, $self->mxKarma);
$this->maniaControl->log("MX-Karma Votes successfully fetched"); $self->maniaControl->log("MX-Karma Votes successfully fetched");
} else { } 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 //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 { } else {
$this->maniaControl->log($error); $self->maniaControl->log($error);
} }
}, $content, false, 'application/json'); }, $content, false, 'application/json');
} }
@ -911,18 +914,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$properties['isimport'] = $import; $properties['isimport'] = $import;
$content = json_encode($properties); $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) { if (!$error) {
$data = json_decode($data); $data = json_decode($data);
if ($data->success) { if ($data->success) {
$this->maniaControl->log("Votes successfully permitted"); $self->maniaControl->log("Votes successfully permitted");
} else { } 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 //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 { } else {
$this->maniaControl->log($error); $self->maniaControl->log($error);
} }
}, $content, false, 'application/json'); }, $content, false, 'application/json');
} }