From b514a9599cfe8f85b90ea3905408a6a5ce78f0fc Mon Sep 17 00:00:00 2001 From: kremsy Date: Fri, 9 May 2014 10:48:51 +0200 Subject: [PATCH] karma plugin fixes + new methods in chat (sendChatToAdmins / sendErrorToAdmins) --- application/core/Chat.php | 31 ++++++++++++++++++++++ application/plugins/MCTeam/KarmaPlugin.php | 24 ++++++++++++++--- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/application/core/Chat.php b/application/core/Chat.php index cfba7bfb..d54a9f9b 100644 --- a/application/core/Chat.php +++ b/application/core/Chat.php @@ -2,6 +2,8 @@ namespace ManiaControl; +use ManiaControl\Admin\AuthenticationManager; +use ManiaControl\Players\Player; use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException; /** @@ -55,6 +57,35 @@ class Chat { return $this->sendChat($format . $message, $login, $prefix); } + /** + * Sends a Message to all Connected Admins + * + * @param $message + * @param int $minLevel (Constant from AuthenticationManager) + * @param bool $prefix + */ + public function sendMessageToAdmins($message, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, $prefix = true) { + //TODO specifiy in player or adminmanager a getAdmins() with minlevel function + foreach($this->maniaControl->playerManager->getPlayers() as $player){ + /** @var Player $player */ + if($this->maniaControl->authenticationManager->checkRight($player, $minLevel)){ + $this->sendChat($message, $player->login, $prefix); + } + } + } + + /** + * Sends a Error Message to all Connected Admins + * + * @param $message + * @param int $minLevel (Constant from AuthenticationManager) + * @param bool $prefix + */ + public function sendErrorToAdmins($message, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, $prefix = true) { + $format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR); + $this->sendMessageToAdmins($format . $message, $prefix); + } + /** * Send a chat message to the given login * diff --git a/application/plugins/MCTeam/KarmaPlugin.php b/application/plugins/MCTeam/KarmaPlugin.php index 79cf5ead..0cbb7d2b 100644 --- a/application/plugins/MCTeam/KarmaPlugin.php +++ b/application/plugins/MCTeam/KarmaPlugin.php @@ -17,6 +17,7 @@ use ManiaControl\Maps\Map; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\Plugin; +use ManiaControl\Plugins\PluginMenu; use ManiaControl\Settings\SettingManager; /** @@ -159,6 +160,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $this->mxKarmaOpenSession(); $this->mxKarma['startTime'] = time(); + //Check if Karma Code got specified, and inform admin that it would be good to specifiy one + $serverLogin = $this->maniaControl->server->login; + $mxKarmaCode = $this->maniaControl->settingManager->getSetting($this, '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $serverLogin . ']MX Karma Code for ' . $serverLogin . '$l'); + + if ($mxKarmaCode == '') { + $permission = $this->maniaControl->settingManager->getSetting($this->maniaControl->authenticationManager, PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS); + $this->maniaControl->chat->sendErrorToAdmins("Please specify a Mania-Exchange Karma Key in the Karma-Plugin settings!", $permission); + } + return true; } @@ -275,14 +285,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { // Fetch the Mx Karma Votes $self->getMxKarmaVotes(); } else { - $self->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message); - // TODO remove temp trigger - $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query); + if ($data->data->message == "invalid hash") { + $permission = $self->maniaControl->settingManager->getSetting($this->maniaControl->authenticationManager, PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS); + $self->maniaControl->chat->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission); + } else { + // TODO remove temp trigger + $self->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); $self->mxKarma['connectionInProgress'] = false; + unset($self->mxKarma['session']); } } else { // TODO remove temp trigger - $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); + $self->maniaControl->errorHandler->triggerDebugNotice("Error while activating Mania-Exchange Karma Session: " . $error); $self->maniaControl->log($error); $self->mxKarma['connectionInProgress'] = false; }