removed old php 5.3 compatibility code

This commit is contained in:
Steffen Schröder 2014-06-17 23:27:28 +02:00
parent ea223a6d26
commit 2e0a0359dd
11 changed files with 205 additions and 235 deletions

View File

@ -131,13 +131,12 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
} }
// search for matching maps // search for matching maps
$self = $this; $this->maniaControl->mapManager->mxManager->getMapsAsync(function (array $maps) use (&$player) {
$this->maniaControl->mapManager->mxManager->getMapsAsync(function (array $maps) use (&$self, &$player) {
if (!$maps) { if (!$maps) {
$self->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login); $this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login);
return; return;
} }
$self->showManiaExchangeList($maps, $player); $this->showManiaExchangeList($maps, $player);
}, $searchString, $author, $environment); }, $searchString, $author, $environment);
} }

View File

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

View File

@ -624,16 +624,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message); $votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message);
$self = $this; $votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) {
$votesPlugin->startVote($player, 'switchmap', function ($result) use (&$self, &$votesPlugin, &$map) { $this->maniaControl->chat->sendInformation('$sVote Successful -> Map switched!');
$self->maniaControl->chat->sendInformation('$sVote Successful -> Map switched!');
$votesPlugin->undefineVote('switchmap'); $votesPlugin->undefineVote('switchmap');
//Don't queue on Map-Change //Don't queue on Map-Change
$this->maniaControl->mapManager->mapQueue->dontQueueNextMapChange(); $this->maniaControl->mapManager->mapQueue->dontQueueNextMapChange();
try { try {
$self->maniaControl->client->JumpToMapIdent($map->uid); $this->maniaControl->client->JumpToMapIdent($map->uid);
} catch (NotInListException $e) { } catch (NotInListException $e) {
} }
}); });

View File

@ -263,9 +263,9 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$rightLabel->setZ(3.1); $rightLabel->setZ(3.1);
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($listPlayer->authLevel)); $rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($listPlayer->authLevel));
$rightLabel->setTextSize(0.8); $rightLabel->setTextSize(0.8);
$rightLabel->setTextColor("fff"); $rightLabel->setTextColor('fff');
$description = $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer) . " " . $listPlayer->nickname; $description = $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer) . ' ' . $listPlayer->nickname;
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description); $rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
// Player Statistics // Player Statistics
@ -275,7 +275,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$playerQuad->setZ(3); $playerQuad->setZ(3);
$playerQuad->setSize(2.7, 2.7); $playerQuad->setSize(2.7, 2.7);
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_TrackInfo); $playerQuad->setSubStyle($playerQuad::SUBSTYLE_TrackInfo);
$playerQuad->setAction(self::ACTION_OPEN_PLAYER_DETAILED . "." . $listPlayer->login); $playerQuad->setAction(self::ACTION_OPEN_PLAYER_DETAILED . '.' . $listPlayer->login);
$description = 'View Statistics of $<' . $listPlayer->nickname . '$>'; $description = 'View Statistics of $<' . $listPlayer->nickname . '$>';
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description); $playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
@ -288,7 +288,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Camera); $playerQuad->setSubStyle($playerQuad::SUBSTYLE_Camera);
$description = 'Spectate $<' . $listPlayer->nickname . '$>'; $description = 'Spectate $<' . $listPlayer->nickname . '$>';
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description); $playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
$playerQuad->setAction(self::ACTION_SPECTATE_PLAYER . "." . $listPlayer->login); $playerQuad->setAction(self::ACTION_SPECTATE_PLAYER . '.' . $listPlayer->login);
// Player Profile Quad // Player Profile Quad
$playerQuad = new Quad_UIConstruction_Buttons(); $playerQuad = new Quad_UIConstruction_Buttons();
@ -311,7 +311,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$playerQuad->setZ(0.1); $playerQuad->setZ(0.1);
$playerQuad->setSize(3.8, 3.8); $playerQuad->setSize(3.8, 3.8);
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Buddy); $playerQuad->setSubStyle($playerQuad::SUBSTYLE_Buddy);
$playerQuad->setAction(self::ACTION_PLAYER_ADV . "." . $listPlayer->login); $playerQuad->setAction(self::ACTION_PLAYER_ADV . '.' . $listPlayer->login);
// Description Label // Description Label
$description = 'Advanced Player Actions for $<' . $listPlayer->nickname . '$>'; $description = 'Advanced Player Actions for $<' . $listPlayer->nickname . '$>';
@ -478,7 +478,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$label->setY($height / 2 - 5); $label->setY($height / 2 - 5);
$label->setStyle($style); $label->setStyle($style);
$label->setTextSize($textSize); $label->setTextSize($textSize);
$label->setText("Advanced Actions"); $label->setText('Advanced Actions');
$label->setTextColor($textColor); $label->setTextColor($textColor);
// Show Nickname // Show Nickname
@ -510,11 +510,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$label->setTextColor($textColor); $label->setTextColor($textColor);
if (!$this->maniaControl->playerManager->playerActions->isPlayerMuted($login)) { if (!$this->maniaControl->playerManager->playerActions->isPlayerMuted($login)) {
$label->setText("Mute"); $label->setText('Mute');
$quad->setAction(self::ACTION_MUTE_PLAYER . "." . $login); $quad->setAction(self::ACTION_MUTE_PLAYER . '.' . $login);
} else { } else {
$label->setText("UnMute"); $label->setText('UnMute');
$quad->setAction(self::ACTION_UNMUTE_PLAYER . "." . $login); $quad->setAction(self::ACTION_UNMUTE_PLAYER . '.' . $login);
} }
// Warn Player // Warn Player
@ -522,12 +522,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$quad = clone $quad; $quad = clone $quad;
$frame->add($quad); $frame->add($quad);
$quad->setY($posY); $quad->setY($posY);
$quad->setAction(self::ACTION_WARN_PLAYER . "." . $login); $quad->setAction(self::ACTION_WARN_PLAYER . '.' . $login);
$label = clone $label; $label = clone $label;
$frame->add($label); $frame->add($label);
$label->setY($posY); $label->setY($posY);
$label->setText("Warn"); $label->setText('Warn');
$label->setTextColor($textColor); $label->setTextColor($textColor);
$posY -= 5; $posY -= 5;
@ -536,40 +536,38 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$quad = clone $quad; $quad = clone $quad;
$frame->add($quad); $frame->add($quad);
$quad->setY($posY); $quad->setY($posY);
$quad->setAction(self::ACTION_KICK_PLAYER . "." . $login); $quad->setAction(self::ACTION_KICK_PLAYER . '.' . $login);
$label = clone $label; $label = clone $label;
$frame->add($label); $frame->add($label);
$label->setY($posY); $label->setY($posY);
$label->setText("Kick"); $label->setText('Kick');
$label->setTextColor("F90"); $label->setTextColor('f90');
$posY -= 5; $posY -= 5;
// Show Ban // Show Ban
$quad = clone $quad; $quad = clone $quad;
$frame->add($quad); $frame->add($quad);
$quad->setY($posY); $quad->setY($posY);
$quad->setAction(self::ACTION_BAN_PLAYER . "." . $login); $quad->setAction(self::ACTION_BAN_PLAYER . '.' . $login);
$label = clone $label; $label = clone $label;
$frame->add($label); $frame->add($label);
$label->setY($posY); $label->setY($posY);
$label->setText("Ban"); $label->setText('Ban');
$label->setTextColor("700"); $label->setTextColor('700');
$posY -= 10; $posY -= 10;
// Show Add as Master-Admin // Show Add as Master-Admin
$quad = clone $quad; $quad = clone $quad;
$frame->add($quad); $frame->add($quad);
$quad->setY($posY); $quad->setY($posY);
$quad->setAction(self::ACTION_ADD_AS_MASTER . "." . $login); $quad->setAction(self::ACTION_ADD_AS_MASTER . '.' . $login);
$label = clone $label; $label = clone $label;
$frame->add($label); $frame->add($label);
$label->setY($posY); $label->setY($posY);
$label->setText('Set SuperAdmin');
$label->setText("Set SuperAdmin");
$label->setTextColor($textColor); $label->setTextColor($textColor);
$posY -= 5; $posY -= 5;
@ -577,12 +575,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$quad = clone $quad; $quad = clone $quad;
$frame->add($quad); $frame->add($quad);
$quad->setY($posY); $quad->setY($posY);
$quad->setAction(self::ACTION_ADD_AS_ADMIN . "." . $login); $quad->setAction(self::ACTION_ADD_AS_ADMIN . '.' . $login);
$label = clone $label; $label = clone $label;
$frame->add($label); $frame->add($label);
$label->setY($posY); $label->setY($posY);
$label->setText("Set Admin"); $label->setText('Set Admin');
$label->setTextColor($textColor); $label->setTextColor($textColor);
$posY -= 5; $posY -= 5;
@ -590,12 +588,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$quad = clone $quad; $quad = clone $quad;
$frame->add($quad); $frame->add($quad);
$quad->setY($posY); $quad->setY($posY);
$quad->setAction(self::ACTION_ADD_AS_MOD . "." . $login); $quad->setAction(self::ACTION_ADD_AS_MOD . '.' . $login);
$label = clone $label; $label = clone $label;
$frame->add($label); $frame->add($label);
$label->setY($posY); $label->setY($posY);
$label->setText("Set Moderator"); $label->setText('Set Moderator');
$label->setTextColor($textColor); $label->setTextColor($textColor);
if ($player->authLevel > 0 && $this->maniaControl->authenticationManager->checkRight($admin, $player->authLevel + 1)) { if ($player->authLevel > 0 && $this->maniaControl->authenticationManager->checkRight($admin, $player->authLevel + 1)) {
@ -604,13 +602,13 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$quad = clone $quad; $quad = clone $quad;
$frame->add($quad); $frame->add($quad);
$quad->setY($posY); $quad->setY($posY);
$quad->setAction(self::ACTION_REVOKE_RIGHTS . "." . $login); $quad->setAction(self::ACTION_REVOKE_RIGHTS . '.' . $login);
$label = clone $label; $label = clone $label;
$frame->add($label); $frame->add($label);
$label->setY($posY); $label->setY($posY);
$label->setText("Revoke Rights"); $label->setText('Revoke Rights');
$label->setTextColor("700"); $label->setTextColor('700');
} }
return $frame; return $frame;
@ -628,7 +626,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
return; return;
} }
$action = $actionArray[0] . "." . $actionArray[1]; $action = $actionArray[0] . '.' . $actionArray[1];
$adminLogin = $callback[1][1]; $adminLogin = $callback[1][1];
$targetLogin = $actionArray[2]; $targetLogin = $actionArray[2];
@ -699,16 +697,15 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$startMessage = '$<' . $admin->nickname . '$>$s started a vote to force $<' . $target->nickname . '$> into spectator!'; $startMessage = '$<' . $admin->nickname . '$>$s started a vote to force $<' . $target->nickname . '$> into spectator!';
$votesPlugin->defineVote('forcespec', "Force $<" . $target->nickname . "$> Spec", true, $startMessage); $votesPlugin->defineVote('forcespec', 'Force $<' . $target->nickname . '$> Spec', true, $startMessage);
$self = $this; $votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) {
$votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$self, &$votesPlugin, &$target) { $this->maniaControl->chat->sendInformation('$sVote Successful -> Player $<' . $target->nickname . '$> forced to Spectator!');
$self->maniaControl->chat->sendInformation('$sVote Successfully -> Player $<' . $target->nickname . '$> forced to Spectator!');
$votesPlugin->undefineVote('forcespec'); $votesPlugin->undefineVote('forcespec');
try { try {
$self->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); $this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$self->maniaControl->client->spectatorReleasePlayerSlot($target->login); $this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch (PlayerStateException $e) { } catch (PlayerStateException $e) {
} }
}); });
@ -723,16 +720,15 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$startMessage = '$<' . $admin->nickname . '$>$s started a vote to kick $<' . $target->nickname . '$>!'; $startMessage = '$<' . $admin->nickname . '$>$s started a vote to kick $<' . $target->nickname . '$>!';
$votesPlugin->defineVote('kick', "Kick $<" . $target->nickname . "$>", true, $startMessage); $votesPlugin->defineVote('kick', 'Kick $<' . $target->nickname . '$>', true, $startMessage);
$self = $this; $votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) {
$votesPlugin->startVote($admin, 'kick', function ($result) use (&$self, &$votesPlugin, &$target) { $this->maniaControl->chat->sendInformation('$sVote Successful -> $<' . $target->nickname . '$> got Kicked!');
$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 to a Public Vote!$z ';
try { try {
$self->maniaControl->client->kick($target->login, $message); $this->maniaControl->client->kick($target->login, $message);
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
} }
}); });

View File

@ -75,12 +75,11 @@ class UsageReporter implements TimerListener {
$json = json_encode($properties); $json = json_encode($properties);
$info = base64_encode($json); $info = base64_encode($json);
$url = ManiaControl::URL_WEBSERVICE . '/usagereport?info=' . urlencode($info); $url = ManiaControl::URL_WEBSERVICE . '/usagereport?info=' . urlencode($info);
$self = $this; $this->maniaControl->fileReader->loadFile($url, function ($response, $error) {
$this->maniaControl->fileReader->loadFile($url, function ($response, $error) use (&$self) {
$response = json_decode($response); $response = json_decode($response);
if ($error || !$response) { if ($error || !$response) {
$self->maniaControl->log('Error while Sending data: ' . print_r($error, true)); $this->maniaControl->log('Error while Sending data: ' . print_r($error, true));
} }
}); });
} }

View File

@ -71,20 +71,18 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
} }
$this->maniaControl->log($message); $this->maniaControl->log($message);
$self = $this; $this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use (&$player) {
$maniaControl = $this->maniaControl;
$this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use (&$self, &$maniaControl, &$player) {
if (!$data || $error) { if (!$data || $error) {
$message = 'Error while checking Plugins for newer Versions!'; $message = 'Error while checking Plugins for newer Versions!';
if ($player) { if ($player) {
$maniaControl->chat->sendError($message, $player); $this->maniaControl->chat->sendError($message, $player);
} }
$maniaControl->log($message); $this->maniaControl->log($message);
return; return;
} }
$pluginsData = $self->parsePluginsData($data); $pluginsData = $this->parsePluginsData($data);
$pluginClasses = $maniaControl->pluginManager->getPluginClasses(); $pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
$pluginUpdates = array(); $pluginUpdates = array();
foreach ($pluginClasses as $pluginClass) { foreach ($pluginClasses as $pluginClass) {
@ -100,25 +98,25 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$pluginUpdates[$pluginId] = $pluginData; $pluginUpdates[$pluginId] = $pluginData;
$message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})"; $message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})";
if ($player) { if ($player) {
$maniaControl->chat->sendSuccess($message, $player); $this->maniaControl->chat->sendSuccess($message, $player);
} }
$maniaControl->log($message); $this->maniaControl->log($message);
} }
} }
if (empty($pluginUpdates)) { if (empty($pluginUpdates)) {
$message = 'Plugins Update Check completed: All Plugins are up-to-date!'; $message = 'Plugins Update Check completed: All Plugins are up-to-date!';
if ($player) { if ($player) {
$maniaControl->chat->sendSuccess($message, $player); $this->maniaControl->chat->sendSuccess($message, $player);
} }
$maniaControl->log($message); $this->maniaControl->log($message);
} else { } else {
$updatesCount = count($pluginUpdates); $updatesCount = count($pluginUpdates);
$message = "Plugins Update Check completed: There are {$updatesCount} Updates available!"; $message = "Plugins Update Check completed: There are {$updatesCount} Updates available!";
if ($player) { if ($player) {
$maniaControl->chat->sendSuccess($message, $player); $this->maniaControl->chat->sendSuccess($message, $player);
} }
$maniaControl->log($message); $this->maniaControl->log($message);
} }
}); });
} }
@ -236,25 +234,25 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
* @param bool $update * @param bool $update
*/ */
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) { private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
$self = $this; $this->maniaControl->fileReader->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (&$pluginUpdateData, &$player, &$update) {
$this->maniaControl->fileReader->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (&$self, &$pluginUpdateData, &$player, &$update) {
if (!$updateFileContent || $error) { if (!$updateFileContent || $error) {
$message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!"; $message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!";
if ($player) { if ($player) {
$self->maniaControl->chat->sendInformation($message, $player); $this->maniaControl->chat->sendInformation($message, $player);
} }
$self->maniaControl->log($message); $this->maniaControl->log($message);
return; return;
} }
$actionNoun = ($update ? 'Update' : 'Install'); $actionNoun = ($update ? 'Update' : 'Install');
$actionVerb = ($update ? 'Updating' : 'Installing'); $actionVerb = ($update ? 'Updating' : 'Installing');
$actionVerbDone = ($update ? 'updated' : 'installed'); $actionVerbDone = ($update ? 'updated' : 'installed');
$message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'..."; $message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'...";
if ($player) { if ($player) {
$self->maniaControl->chat->sendInformation($message, $player); $this->maniaControl->chat->sendInformation($message, $player);
} }
$self->maniaControl->log($message); $this->maniaControl->log($message);
$tempDir = FileUtil::getTempFolder(); $tempDir = FileUtil::getTempFolder();
$updateFileName = $tempDir . $pluginUpdateData->zipfile; $updateFileName = $tempDir . $pluginUpdateData->zipfile;
@ -263,7 +261,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
$message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!"; $message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!";
if ($player) { if ($player) {
$self->maniaControl->chat->sendError($message, $player); $this->maniaControl->chat->sendError($message, $player);
} }
trigger_error($message); trigger_error($message);
return; return;
@ -274,7 +272,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if ($result !== true) { if ($result !== true) {
$message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})"; $message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})";
if ($player) { if ($player) {
$self->maniaControl->chat->sendError($message, $player); $this->maniaControl->chat->sendError($message, $player);
} }
trigger_error($message); trigger_error($message);
return; return;
@ -291,27 +289,27 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
} }
$message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}"; $message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}";
if ($player) { if ($player) {
$self->maniaControl->chat->sendSuccess($message, $player); $this->maniaControl->chat->sendSuccess($message, $player);
} }
$self->maniaControl->log($message); $this->maniaControl->log($message);
if (!$update) { if (!$update) {
$newPluginClasses = $self->maniaControl->pluginManager->loadPlugins(); $newPluginClasses = $this->maniaControl->pluginManager->loadPlugins();
if (empty($newPluginClasses)) { if (empty($newPluginClasses)) {
$message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!"; $message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!";
if ($player) { if ($player) {
$self->maniaControl->chat->sendError($message, $player); $this->maniaControl->chat->sendError($message, $player);
} }
$self->maniaControl->log($message); $this->maniaControl->log($message);
} else { } else {
$message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!"; $message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!";
if ($player) { if ($player) {
$self->maniaControl->chat->sendSuccess($message, $player); $this->maniaControl->chat->sendSuccess($message, $player);
} }
$self->maniaControl->log($message); $this->maniaControl->log($message);
$menuId = $self->maniaControl->configurator->getMenuId('Install Plugins'); $menuId = $this->maniaControl->configurator->getMenuId('Install Plugins');
$self->maniaControl->configurator->reopenMenu($player, $menuId); $this->maniaControl->configurator->reopenMenu($player, $menuId);
} }
} }
}); });
@ -349,24 +347,23 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
} else { } else {
$pluginId = substr($actionId, strlen(PluginInstallMenu::ACTION_PREFIX_INSTALL_PLUGIN)); $pluginId = substr($actionId, strlen(PluginInstallMenu::ACTION_PREFIX_INSTALL_PLUGIN));
$url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId; $url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId;
$self = $this; $this->maniaControl->fileReader->loadFile($url, function ($data, $error) use (&$player) {
$this->maniaControl->fileReader->loadFile($url, function ($data, $error) use (&$self, &$player) {
if ($error || !$data) { if ($error || !$data) {
$message = "Error loading Plugin Install Data! {$error}"; $message = "Error loading Plugin Install Data! {$error}";
$self->maniaControl->chat->sendError($message, $player); $this->maniaControl->chat->sendError($message, $player);
return; return;
} }
$data = json_decode($data); $data = json_decode($data);
if (!$data) { if (!$data) {
$message = "Error loading Plugin Install Data! {$error}"; $message = "Error loading Plugin Install Data! {$error}";
$self->maniaControl->chat->sendError($message, $player); $this->maniaControl->chat->sendError($message, $player);
return; return;
} }
$pluginUpdateData = new PluginUpdateData($data); $pluginUpdateData = new PluginUpdateData($data);
$self->installPlugin($pluginUpdateData, $player); $this->installPlugin($pluginUpdateData, $player);
}); });
} }
} }

View File

@ -315,16 +315,14 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->maniaControl->log($message); $this->maniaControl->log($message);
} }
$self = $this; $updateData = $this->coreUpdateData;
$updateData = $this->coreUpdateData; $this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use ($updateData, &$player) {
$maniaControl = $this->maniaControl;
$this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use (&$self, &$maniaControl, &$updateData, &$player) {
if (!$updateFileContent || $error) { if (!$updateFileContent || $error) {
$message = "Update failed: Couldn't load Update zip! {$error}"; $message = "Update failed: Couldn't load Update zip! {$error}";
if ($player) { if ($player) {
$maniaControl->chat->sendError($message, $player); $this->maniaControl->chat->sendError($message, $player);
} }
$maniaControl->log($message); $this->maniaControl->log($message);
return; return;
} }
@ -335,9 +333,9 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
$message = "Update failed: Couldn't save Update zip!"; $message = "Update failed: Couldn't save Update zip!";
if ($player) { if ($player) {
$maniaControl->chat->sendError($message, $player); $this->maniaControl->chat->sendError($message, $player);
} }
$maniaControl->log($message); $this->maniaControl->log($message);
return; return;
} }
@ -346,9 +344,9 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if ($result !== true) { if ($result !== true) {
$message = "Update failed: Couldn't open Update Zip. ({$result})"; $message = "Update failed: Couldn't open Update Zip. ({$result})";
if ($player) { if ($player) {
$maniaControl->chat->sendError($message, $player); $this->maniaControl->chat->sendError($message, $player);
} }
$maniaControl->log($message); $this->maniaControl->log($message);
return; return;
} }
@ -358,15 +356,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
FileUtil::removeTempFolder(); FileUtil::removeTempFolder();
// Set the Nightly Build Date // Set the Nightly Build Date
$self->setNightlyBuildDate($updateData->releaseDate); $this->setNightlyBuildDate($updateData->releaseDate);
$message = 'Update finished!'; $message = 'Update finished!';
if ($player) { if ($player) {
$maniaControl->chat->sendSuccess($message, $player); $this->maniaControl->chat->sendSuccess($message, $player);
} }
$maniaControl->log($message); $this->maniaControl->log($message);
$maniaControl->restart(); $this->maniaControl->restart();
}); });
return true; return true;
@ -427,37 +425,35 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return; return;
} }
$self = $this; $this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
$maniaControl = $this->maniaControl; if (!$this->checkUpdateData($updateData)) {
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$self, &$maniaControl, &$player) { $this->maniaControl->chat->sendInformation('No Update available!', $player->login);
if (!$self->checkUpdateData($updateData)) {
$maniaControl->chat->sendInformation('No Update available!', $player->login);
return; return;
} }
if (!$self->checkUpdateDataBuildVersion($updateData)) { if (!$this->checkUpdateDataBuildVersion($updateData)) {
$maniaControl->chat->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login); $this->maniaControl->chat->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login);
return; return;
} }
$isNightly = $self->isNightlyUpdateChannel(); $isNightly = $this->isNightlyUpdateChannel();
if ($isNightly) { if ($isNightly) {
$buildDate = $self->getNightlyBuildDate(); $buildDate = $this->getNightlyBuildDate();
if ($buildDate) { if ($buildDate) {
if ($updateData->isNewerThan($buildDate)) { if ($updateData->isNewerThan($buildDate)) {
$maniaControl->chat->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login); $this->maniaControl->chat->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login);
return; return;
} else { } else {
$maniaControl->chat->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login); $this->maniaControl->chat->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login);
} }
} else { } else {
$maniaControl->chat->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login); $this->maniaControl->chat->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login);
} }
} else { } else {
$maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login); $this->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
} }
$self->coreUpdateData = $updateData; $this->coreUpdateData = $updateData;
}); });
} }
@ -473,21 +469,19 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return; return;
} }
$self = $this; $this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
$maniaControl = $this->maniaControl;
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$self, &$maniaControl, &$player) {
if (!$updateData) { if (!$updateData) {
$maniaControl->chat->sendError('Update is currently not possible!', $player); $this->maniaControl->chat->sendError('Update is currently not possible!', $player);
return; return;
} }
if (!$self->checkUpdateDataBuildVersion($updateData)) { if (!$this->checkUpdateDataBuildVersion($updateData)) {
$maniaControl->chat->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player); $this->maniaControl->chat->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player);
return; return;
} }
$self->coreUpdateData = $updateData; $this->coreUpdateData = $updateData;
$self->performCoreUpdate($player); $this->performCoreUpdate($player);
}); });
} }
} }

View File

@ -263,36 +263,35 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $mapInfo, $gameMode, $serverInfo, $playerInfo); $data = array($this->dedimaniaData->sessionId, $mapInfo, $gameMode, $serverInfo, $playerInfo);
$content = $this->encode_request(self::DEDIMANIA_GETRECORDS, $data); $content = $this->encode_request(self::DEDIMANIA_GETRECORDS, $data);
$self = $this; $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self) {
if ($error) { if ($error) {
$self->maniaControl->log('Dedimania Error: ' . $error); $this->maniaControl->log('Dedimania Error: ' . $error);
} }
$data = $self->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GETRECORDS); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GETRECORDS);
return; return;
} }
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
$self->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank']; $this->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
foreach ($responseData['Players'] as $player) { foreach ($responseData['Players'] as $player) {
$dediPlayer = new DedimaniaPlayer($player); $dediPlayer = new DedimaniaPlayer($player);
$self->dedimaniaData->addPlayer($dediPlayer); $this->dedimaniaData->addPlayer($dediPlayer);
} }
foreach ($responseData['Records'] as $key => $record) { foreach ($responseData['Records'] as $key => $record) {
$self->dedimaniaData->records[$key] = new RecordData($record); $this->dedimaniaData->records[$key] = new RecordData($record);
} }
$self->updateManialink = true; $this->updateManialink = true;
$self->maniaControl->callbackManager->triggerCallback(self::CB_DEDIMANIA_UPDATED, $self->dedimaniaData->records); $this->maniaControl->callbackManager->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
}, $content, true); }, $content, true);
return true; return true;
@ -528,27 +527,26 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$content = $this->encode_request(self::DEDIMANIA_CHECKSESSION, array($this->dedimaniaData->sessionId)); $content = $this->encode_request(self::DEDIMANIA_CHECKSESSION, array($this->dedimaniaData->sessionId));
$self = $this; $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self) {
if ($error) { if ($error) {
$self->maniaControl->log("Dedimania Error: " . $error); $this->maniaControl->log("Dedimania Error: " . $error);
} }
$data = $self->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECKSESSION); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECKSESSION);
return; return;
} }
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
if (is_bool($responseData)) { if (is_bool($responseData)) {
if (!$responseData) { if (!$responseData) {
$self->openDedimaniaSession(); $this->openDedimaniaSession();
} }
} }
}, $content, true); }, $content, true);
@ -565,35 +563,34 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $player->login, $player->rawNickname, $player->path, $player->isSpectator); $data = array($this->dedimaniaData->sessionId, $player->login, $player->rawNickname, $player->path, $player->isSpectator);
$content = $this->encode_request(self::DEDIMANIA_PLAYERCONNECT, $data); $content = $this->encode_request(self::DEDIMANIA_PLAYERCONNECT, $data);
$self = $this; $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$player) {
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self, &$player) {
if ($error) { if ($error) {
$self->maniaControl->log("Dedimania Error: " . $error); $this->maniaControl->log("Dedimania Error: " . $error);
} }
$data = $self->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
return; return;
} }
$responseData = $methodResponse[0]; $responseData = $methodResponse[0];
$dediPlayer = new DedimaniaPlayer($responseData); $dediPlayer = new DedimaniaPlayer($responseData);
$self->dedimaniaData->addPlayer($dediPlayer); $this->dedimaniaData->addPlayer($dediPlayer);
// Fetch records if he is the first who joined the server // Fetch records if he is the first who joined the server
if ($self->maniaControl->playerManager->getPlayerCount(false) === 1) { if ($this->maniaControl->playerManager->getPlayerCount(false) === 1) {
$self->fetchDedimaniaRecords(true); $this->fetchDedimaniaRecords(true);
} }
if ($self->maniaControl->settingManager->getSettingValue($self, self::SETTING_WIDGET_ENABLE)) { if ($this->maniaControl->settingManager->getSettingValue($this, self::SETTING_WIDGET_ENABLE)) {
$manialink = $self->buildManialink(); $manialink = $this->buildManialink();
$self->maniaControl->manialinkManager->sendManialink($manialink, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialink, $player->login);
} }
}, $content, true); }, $content, true);
} }
@ -613,20 +610,19 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $player->login, ''); $data = array($this->dedimaniaData->sessionId, $player->login, '');
$content = $this->encode_request(self::DEDIMANIA_PLAYERDISCONNECT, $data); $content = $this->encode_request(self::DEDIMANIA_PLAYERDISCONNECT, $data);
$self = $this; $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self) {
if ($error) { if ($error) {
$self->maniaControl->log("Dedimania Error: " . $error); $this->maniaControl->log("Dedimania Error: " . $error);
} }
$data = $self->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT);
} }
}, $content, true); }, $content, true);
} }
@ -681,21 +677,19 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
//var_dump($data); //var_dump($data);
$content = $this->encode_request(self::DEDIMANIA_SETCHALLENGETIMES, $data); $content = $this->encode_request(self::DEDIMANIA_SETCHALLENGETIMES, $data);
$self = $this; $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) {
$maniaControl = $this->maniaControl;
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self, &$maniaControl) {
if ($error) { if ($error) {
$maniaControl->log("Dedimania Error: " . $error); $this->maniaControl->log("Dedimania Error: " . $error);
} }
$data = $self->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SETCHALLENGETIMES); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SETCHALLENGETIMES);
return; return;
} }
@ -721,20 +715,19 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $serverInfo, $votesInfo, $playerList); $data = array($this->dedimaniaData->sessionId, $serverInfo, $votesInfo, $playerList);
$content = $this->encode_request(self::DEDIMANIA_UPDATESERVERPLAYERS, $data); $content = $this->encode_request(self::DEDIMANIA_UPDATESERVERPLAYERS, $data);
$self = $this; $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self) {
if ($error) { if ($error) {
$self->maniaControl->log("Dedimania Error: " . $error); $this->maniaControl->log("Dedimania Error: " . $error);
} }
$data = $self->decode($data); $data = $this->decode($data);
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return; return;
} }
$methodResponse = $data[0]; $methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATESERVERPLAYERS); $this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATESERVERPLAYERS);
} }
}, $content, true); }, $content, true);
} }

View File

@ -282,31 +282,30 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
} }
//Send and Handle the Bill //Send and Handle the Bill
$self = $this; $this->maniaControl->billManager->sendBill(function ($data, $status) use (&$player, $amount, $receiver) {
$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 ($self->maniaControl->settingManager->getSettingValue($self, DonationPlugin::SETTING_ANNOUNCE_SERVERDONATION, true) && $amount >= $self->maniaControl->settingManager->getSettingValue($self, DonationPlugin::SETTING_MIN_AMOUNT_SHOWN, true)) { if ($this->maniaControl->settingManager->getSettingValue($this, DonationPlugin::SETTING_ANNOUNCE_SERVERDONATION, true) && $amount >= $this->maniaControl->settingManager->getSettingValue($this, 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.';
} }
$self->maniaControl->chat->sendSuccess($message, $login); $this->maniaControl->chat->sendSuccess($message, $login);
$self->maniaControl->statisticManager->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $self->maniaControl->server->index, $amount); $this->maniaControl->statisticManager->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $this->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}'!";
$self->maniaControl->chat->sendSuccess($message, $player->login); $this->maniaControl->chat->sendSuccess($message, $player->login);
break; break;
case BillManager::PLAYER_REFUSED_DONATION: case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.'; $message = 'Transaction cancelled.';
$self->maniaControl->chat->sendError($message, $player->login); $this->maniaControl->chat->sendError($message, $player->login);
break; break;
case BillManager::ERROR_WHILE_TRANSACTION: case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data; $message = $data;
$self->maniaControl->chat->sendError($message, $player->login); $this->maniaControl->chat->sendError($message, $player->login);
break; break;
} }
}, $player, $amount, $message); }, $player, $amount, $message);
@ -393,20 +392,19 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
} }
$message = 'Payout from $<' . $this->maniaControl->client->getServerName() . '$>.'; $message = 'Payout from $<' . $this->maniaControl->client->getServerName() . '$>.';
$self = $this; $this->maniaControl->billManager->sendPlanets(function ($data, $status) use (&$player, $amount, $receiver) {
$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}'!";
$self->maniaControl->chat->sendSuccess($message, $player->login); $this->maniaControl->chat->sendSuccess($message, $player->login);
break; break;
case BillManager::PLAYER_REFUSED_DONATION: case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.'; $message = 'Transaction cancelled.';
$self->maniaControl->chat->sendError($message, $player->login); $this->maniaControl->chat->sendError($message, $player->login);
break; break;
case BillManager::ERROR_WHILE_TRANSACTION: case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data; $message = $data;
$self->maniaControl->chat->sendError($message, $player->login); $this->maniaControl->chat->sendError($message, $player->login);
break; break;
} }
}, $receiver, $amount, $message); }, $receiver, $amount, $message);

View File

@ -253,24 +253,23 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$this->mxKarma['connectionInProgress'] = true; $this->mxKarma['connectionInProgress'] = true;
$self = $this; $this->maniaControl->fileReader->loadFile($query, function ($data, $error) use ($mxKarmaCode) {
$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) {
$self->mxKarma['session'] = $data->data; $this->mxKarma['session'] = $data->data;
$self->activateSession($mxKarmaCode); $this->activateSession($mxKarmaCode);
} else { } else {
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma"); $this->maniaControl->log("Error while authenticating on Mania-Exchange Karma");
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message); $this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
$self->mxKarma['connectionInProgress'] = false; $this->mxKarma['connectionInProgress'] = false;
} }
} else { } else {
$self->maniaControl->log($error); $this->maniaControl->log($error);
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); $this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
$self->mxKarma['connectionInProgress'] = false; $this->mxKarma['connectionInProgress'] = false;
} }
}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000);
} }
@ -288,33 +287,32 @@ 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);
$self = $this; $this->maniaControl->fileReader->loadFile($query, function ($data, $error) use ($query) {
$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) {
$self->maniaControl->log("Successfully authenticated on Mania-Exchange Karma"); $this->maniaControl->log("Successfully authenticated on Mania-Exchange Karma");
$self->mxKarma['connectionInProgress'] = false; $this->mxKarma['connectionInProgress'] = false;
// Fetch the Mx Karma Votes // Fetch the Mx Karma Votes
$self->getMxKarmaVotes(); $this->getMxKarmaVotes();
} else { } else {
if ($data->data->message === "invalid hash") { if ($data->data->message === "invalid hash") {
$permission = $self->maniaControl->settingManager->getSettingValue($this->maniaControl->authenticationManager, PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS); $permission = $this->maniaControl->settingManager->getSettingValue($this->maniaControl->authenticationManager, PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS);
$self->maniaControl->chat->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission); $this->maniaControl->chat->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission);
} else { } else {
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query); $this->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query);
} }
$self->maniaControl->log("Error while activating Mania-Exchange Karma Session: " . $data->data->message); $this->maniaControl->log("Error while activating Mania-Exchange Karma Session: " . $data->data->message);
$self->mxKarma['connectionInProgress'] = false; $this->mxKarma['connectionInProgress'] = false;
unset($self->mxKarma['session']); unset($this->mxKarma['session']);
} }
} else { } else {
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while activating Mania-Exchange Karma Session: " . $error); $this->maniaControl->errorHandler->triggerDebugNotice("Error while activating Mania-Exchange Karma Session: " . $error);
$self->maniaControl->log($error); $this->maniaControl->log($error);
$self->mxKarma['connectionInProgress'] = false; $this->mxKarma['connectionInProgress'] = false;
} }
}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000);
} }
@ -372,38 +370,37 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
$content = json_encode($properties); $content = json_encode($properties);
$self = $this; $this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_GETMAPRATING . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use (&$player) {
$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) {
$self->mxKarma["voteCount"] = $data->data->votecount; $this->mxKarma["voteCount"] = $data->data->votecount;
$self->mxKarma["voteAverage"] = $data->data->voteaverage; $this->mxKarma["voteAverage"] = $data->data->voteaverage;
$self->mxKarma["modeVoteCount"] = $data->data->modevotecount; $this->mxKarma["modeVoteCount"] = $data->data->modevotecount;
$self->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage; $this->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage;
} }
foreach ($data->data->votes as $votes) { foreach ($data->data->votes as $votes) {
$self->mxKarma["votes"][$votes->login] = $votes->vote; $this->mxKarma["votes"][$votes->login] = $votes->vote;
} }
$self->updateManialink = true; $this->updateManialink = true;
$self->maniaControl->callbackManager->triggerCallback($self::CB_KARMA_MXUPDATED, $self->mxKarma); $this->maniaControl->callbackManager->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma);
$self->maniaControl->log("MX-Karma Votes successfully fetched"); $this->maniaControl->log("MX-Karma Votes successfully fetched");
} else { } else {
$self->maniaControl->log("Error while fetching votes: " . $data->data->message); $this->maniaControl->log("Error while fetching votes: " . $data->data->message);
if ($data->data->message === 'invalid session') { if ($data->data->message === 'invalid session') {
unset($this->mxKarma['session']); unset($this->mxKarma['session']);
return; return;
} }
// TODO remove temp trigger // TODO remove temp trigger
$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)); $this->maniaControl->errorHandler->triggerDebugNotice("Error while fetching votes: '{$data->data->message}' " . KarmaPlugin::MX_KARMA_URL . KarmaPlugin::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey));
} }
} else { } else {
$self->maniaControl->log($error); $this->maniaControl->log($error);
} }
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
} }
@ -482,23 +479,22 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$content = json_encode($properties); $content = json_encode($properties);
$self = $this; $this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) {
$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) {
$self->maniaControl->log("Votes successfully submitted"); $this->maniaControl->log("Votes successfully submitted");
} else { } else {
$self->maniaControl->log("Error while updating votes: " . $data->data->message); $this->maniaControl->log("Error while updating votes: " . $data->data->message);
if ($data->data->message === "invalid session") { if ($data->data->message === "invalid session") {
unset($this->mxKarma['session']); unset($this->mxKarma['session']);
return; return;
} }
// TODO remove temp trigger // TODO remove temp trigger
$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)); $this->maniaControl->errorHandler->triggerDebugNotice("Error while updating votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey));
} }
} else { } else {
$self->maniaControl->log($error); $this->maniaControl->log($error);
} }
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
} }

View File

@ -100,21 +100,21 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$this->initTables(); $this->initTables();
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING, 100); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING, 100);
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING, 15); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING, 15);
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_REQUIRED_RECORDS, 3); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_REQUIRED_RECORDS, 3);
$maniaControl->settingManager->initSetting($this, self::SETTING_MAX_STORED_RECORDS, 50); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MAX_STORED_RECORDS, 50);
$script = $this->maniaControl->client->getScriptName(); $script = $this->maniaControl->client->getScriptName();
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() === 'tm') { if ($this->maniaControl->mapManager->getCurrentMap()->getGame() === 'tm') {
//TODO also add obstacle here as default //TODO also add obstacle here as default
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_RANKING_TYPE, self::RANKING_TYPE_RECORDS); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_RANKING_TYPE, self::RANKING_TYPE_RECORDS);
} else if ($script["CurrentValue"] === 'InstaDM.Script.txt') { } else if ($script["CurrentValue"] === 'InstaDM.Script.txt') {
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_RANKING_TYPE, self::RANKING_TYPE_RATIOS); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_RANKING_TYPE, self::RANKING_TYPE_RATIOS);
} else { } else {
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_RANKING_TYPE, self::RANKING_TYPE_POINTS); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_RANKING_TYPE, self::RANKING_TYPE_POINTS);
} }
//Check if the type is Correct //Check if the type is Correct