karma plugin fixes + new methods in chat (sendChatToAdmins / sendErrorToAdmins)
This commit is contained in:
parent
a16ddc7bb4
commit
b514a9599c
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace ManiaControl;
|
namespace ManiaControl;
|
||||||
|
|
||||||
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
|
use ManiaControl\Players\Player;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,6 +57,35 @@ class Chat {
|
|||||||
return $this->sendChat($format . $message, $login, $prefix);
|
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
|
* Send a chat message to the given login
|
||||||
*
|
*
|
||||||
|
@ -17,6 +17,7 @@ use ManiaControl\Maps\Map;
|
|||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
use ManiaControl\Plugins\Plugin;
|
use ManiaControl\Plugins\Plugin;
|
||||||
|
use ManiaControl\Plugins\PluginMenu;
|
||||||
use ManiaControl\Settings\SettingManager;
|
use ManiaControl\Settings\SettingManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,6 +160,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
$this->mxKarmaOpenSession();
|
$this->mxKarmaOpenSession();
|
||||||
$this->mxKarma['startTime'] = time();
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,14 +285,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
// Fetch the Mx Karma Votes
|
// Fetch the Mx Karma Votes
|
||||||
$self->getMxKarmaVotes();
|
$self->getMxKarmaVotes();
|
||||||
} else {
|
} else {
|
||||||
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
|
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
|
// TODO remove temp trigger
|
||||||
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query);
|
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query);
|
||||||
|
}
|
||||||
|
$self->maniaControl->log("Error while activating Mania-Exchange Karma Session: " . $data->data->message);
|
||||||
$self->mxKarma['connectionInProgress'] = false;
|
$self->mxKarma['connectionInProgress'] = false;
|
||||||
|
unset($self->mxKarma['session']);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO remove temp trigger
|
// 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->maniaControl->log($error);
|
||||||
$self->mxKarma['connectionInProgress'] = false;
|
$self->mxKarma['connectionInProgress'] = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user