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) {
$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);
}
/**

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
});
});
}

View File

@ -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) {
}
});

View File

@ -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);
}
});
}

View File

@ -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;
});