From 4412ff73c1d6efffe7e6fa0b1e963e1ffc667287 Mon Sep 17 00:00:00 2001 From: kremsy Date: Thu, 2 Jan 2014 17:31:58 +0100 Subject: [PATCH] donated Planets statistic --- application/core/Admin/ActionsMenu.php | 1 - application/core/Maps/Map.php | 2 +- application/plugins/Donations.php | 177 ++++++++++++------------- 3 files changed, 87 insertions(+), 93 deletions(-) diff --git a/application/core/Admin/ActionsMenu.php b/application/core/Admin/ActionsMenu.php index 20e17b4f..16edfbb1 100644 --- a/application/core/Admin/ActionsMenu.php +++ b/application/core/Admin/ActionsMenu.php @@ -215,7 +215,6 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener { $testf->add($testq); $script->addTooltip($itemQuad, $testf); - $script->addTooltip($testf, $testf); /** TEST TOOLTIP */ diff --git a/application/core/Maps/Map.php b/application/core/Maps/Map.php index 18bc75fa..6307cc41 100644 --- a/application/core/Maps/Map.php +++ b/application/core/Maps/Map.php @@ -87,7 +87,7 @@ class Map { // TODO: define timeout if mx is down,todo fetch all map infos at once (maybe way faster) $serverInfo = $this->maniaControl->server->getSystemInfo(); $title = strtoupper(substr($serverInfo['TitleId'], 0, 2)); - $this->mx = new \MXInfoFetcher($title, $this->uid, false); + // $this->mx = new \MXInfoFetcher($title, $this->uid, false); } } \ No newline at end of file diff --git a/application/plugins/Donations.php b/application/plugins/Donations.php index 8796c168..f4fcec3a 100644 --- a/application/plugins/Donations.php +++ b/application/plugins/Donations.php @@ -1,9 +1,9 @@ maniaControl = $maniaControl; - + // Register for commands $this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate'); $this->maniaControl->commandManager->registerCommandListener('pay', $this, 'command_Pay', true); $this->maniaControl->commandManager->registerCommandListener('getplanets', $this, 'command_GetPlanets', true); - + // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_BILLUPDATED, $this, 'handleBillUpdated'); - + + // Define player stats + $this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_DONATIONS); return true; } @@ -98,40 +101,37 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { /** * Handle /donate command * - * @param array $chatCallback - * @param Player $player + * @param array $chatCallback + * @param Player $player * @return bool */ public function command_Donate(array $chatCallback, Player $player) { - $text = $chatCallback[1][2]; + $text = $chatCallback[1][2]; $params = explode(' ', $text); - if (count($params) < 2) { + if(count($params) < 2) { $this->sendDonateUsageExample($player); return false; } - $amount = (int) $params[1]; - if (!$amount || $amount <= 0) { + $amount = (int)$params[1]; + if(!$amount || $amount <= 0) { $this->sendDonateUsageExample($player); return false; } - if (count($params) >= 3) { - $receiver = $params[2]; + if(count($params) >= 3) { + $receiver = $params[2]; $receiverPlayer = $this->maniaControl->playerManager->getPlayer($receiver); - $receiverName = ($receiverPlayer ? $receiverPlayer['NickName'] : $receiver); - } - else { - $receiver = ''; + $receiverName = ($receiverPlayer ? $receiverPlayer['NickName'] : $receiver); + } else { + $receiver = ''; $receiverName = $this->maniaControl->server->getName(); } $message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?'; - if (!$this->maniaControl->client->query('SendBill', $player->login, $amount, $message, $receiver)) { - trigger_error( - "Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . - $this->maniaControl->getClientErrorText()); + if(!$this->maniaControl->client->query('SendBill', $player->login, $amount, $message, $receiver)) { + trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText()); $this->maniaControl->chat->sendError("Creating donation failed.", $player->login); return false; } - $bill = $this->maniaControl->client->getResponse(); + $bill = $this->maniaControl->client->getResponse(); $this->openBills[$bill] = array(true, $player->login, $receiver, $amount, time()); return true; } @@ -139,41 +139,38 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { /** * Handle //pay command * - * @param array $chatCallback - * @param Player $player + * @param array $chatCallback + * @param Player $player * @return bool */ public function command_Pay(array $chatCallback, Player $player) { - if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) { + if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return false; } - $text = $chatCallback[1][2]; + $text = $chatCallback[1][2]; $params = explode(' ', $text); - if (count($params) < 2) { + if(count($params) < 2) { $this->sendPayUsageExample($player); return false; } - $amount = (int) $params[1]; - if (!$amount || $amount <= 0) { + $amount = (int)$params[1]; + if(!$amount || $amount <= 0) { $this->sendPayUsageExample($player); return false; } - if (count($params) >= 3) { + if(count($params) >= 3) { $receiver = $params[2]; - } - else { + } else { $receiver = $player->login; } $message = 'Payout from $<' . $this->maniaControl->server->getName() . '$>.'; - if (!$this->maniaControl->client->query('Pay', $receiver, $amount, $message)) { - trigger_error( - "Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . - $this->maniaControl->getClientErrorText()); + if(!$this->maniaControl->client->query('Pay', $receiver, $amount, $message)) { + trigger_error("Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText()); $this->maniaControl->chat->sendError("Creating payout failed.", $player->login); return false; } - $bill = $this->maniaControl->client->getResponse(); + $bill = $this->maniaControl->client->getResponse(); $this->openBills[$bill] = array(false, $player->login, $receiver, $amount, time()); return true; } @@ -181,16 +178,16 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { /** * Handle //getplanets command * - * @param array $chatCallback - * @param Player $player + * @param array $chatCallback + * @param Player $player * @return bool */ public function command_GetPlanets(array $chatCallback, Player $player) { - if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { + if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return false; } - if (!$this->maniaControl->client->query('GetServerPlanets')) { + if(!$this->maniaControl->client->query('GetServerPlanets')) { trigger_error("Couldn't retrieve server planets. " . $this->maniaControl->getClientErrorText()); return false; } @@ -202,65 +199,63 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { /** * Handle bill updated callback * - * @param array $callback + * @param array $callback * @return bool */ public function handleBillUpdated(array $callback) { $billId = $callback[1][0]; - if (!array_key_exists($billId, $this->openBills)) { + if(!array_key_exists($billId, $this->openBills)) { return false; } $billData = $this->openBills[$billId]; - $login = $billData[1]; + $login = $billData[1]; $receiver = $billData[2]; - switch ($callback[1][1]) { + switch($callback[1][1]) { case 4: - { - // Payed - $donation = $billData[0]; - $amount = $billData[3]; - if ($donation) { - // Donation - if (strlen($receiver) > 0) { - // To player - $message = "Successfully donated {$amount} to '{$receiver}'!"; - $this->maniaControl->chat->sendSuccess($message, $login); - } - else { - // To server - if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_ANNOUNCE_SERVERDONATION, true)) { - $player = $this->maniaControl->playerManager->getPlayer($login); - $message = '$<' . ($player ? $player->nickname : $login) . '$> donated ' . $amount . ' Planets! Thanks.'; - } - else { - $message = 'Donation successful! Thanks.'; - } - $this->maniaControl->chat->sendSuccess($message, $login); - } - } - else { - // Payout - $message = "Successfully payed out {$amount} to '{$receiver}'!"; + { + // Payed + $donation = $billData[0]; + $amount = $billData[3]; + if($donation) { + // Donation + if(strlen($receiver) > 0) { + // To player + $message = "Successfully donated {$amount} to '{$receiver}'!"; $this->maniaControl->chat->sendSuccess($message, $login); + } else { + // To server + if($this->maniaControl->settingManager->getSetting($this, self::SETTING_ANNOUNCE_SERVERDONATION, true)) { + $message = '$<' . ($player ? $player->nickname : $login) . '$> donated ' . $amount . ' Planets! Thanks.'; + } else { + $message = 'Donation successful! Thanks.'; + } + $this->maniaControl->chat->sendSuccess($message, $login); + $player = $this->maniaControl->playerManager->getPlayer($login); + $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->getLogin(), $amount); } - unset($this->openBills[$billId]); - break; + } else { + // Payout + $message = "Successfully payed out {$amount} to '{$receiver}'!"; + $this->maniaControl->chat->sendSuccess($message, $login); } + unset($this->openBills[$billId]); + break; + } case 5: - { - // Refused - $message = 'Transaction cancelled.'; - $this->maniaControl->chat->sendError($message, $login); - unset($this->openBills[$billId]); - break; - } + { + // Refused + $message = 'Transaction cancelled.'; + $this->maniaControl->chat->sendError($message, $login); + unset($this->openBills[$billId]); + break; + } case 6: - { - // Error - $this->maniaControl->chat->sendError($callback[1][2], $login); - unset($this->openBills[$billId]); - break; - } + { + // Error + $this->maniaControl->chat->sendError($callback[1][2], $login); + unset($this->openBills[$billId]); + break; + } } return true; } @@ -268,7 +263,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { /** * Send an usage example for /donate to the player * - * @param Player $player + * @param Player $player * @return boolean */ private function sendDonateUsageExample(Player $player) { @@ -279,7 +274,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { /** * Send an usage example for /pay to the player * - * @param Player $player + * @param Player $player * @return boolean */ private function sendPayUsageExample(Player $player) {