added auth level communication methods

This commit is contained in:
kremsy 2015-07-11 15:54:15 +02:00
parent bebd2e7353
commit 1ef9d3622a
2 changed files with 49 additions and 3 deletions

View File

@ -5,6 +5,9 @@ namespace ManiaControl\Admin;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\EchoListener;
use ManiaControl\Communication\CommunicationAnswer;
use ManiaControl\Communication\CommunicationListener;
use ManiaControl\Communication\CommunicationMethods;
use ManiaControl\Logger;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
@ -18,7 +21,7 @@ use ManiaControl\Settings\Setting;
* @copyright 2014-2015 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class AuthenticationManager implements CallbackListener, EchoListener {
class AuthenticationManager implements CallbackListener, EchoListener, CommunicationListener {
/*
* Constants
*/
@ -75,6 +78,36 @@ class AuthenticationManager implements CallbackListener, EchoListener {
}
}
});
//Communication Listenings
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::GRANT_AUTH_LEVEL, $this, function ($data) {
if (!is_object($data) || !property_exists($data, 'level') || !property_exists($data, 'login')) {
return new CommunicationAnswer("No valid level or player login provided!", true);
}
$player = $this->maniaControl->getPlayerManager()->getPlayer($data->login);
if ($player) {
$success = $this->grantAuthLevel($player, $data->level);
return new CommunicationAnswer(array("success" => $success));
} else {
return new CommunicationAnswer("Player not found!", true);
}
});
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::REVOKE_AUTH_LEVEL, $this, function ($data) {
if (!is_object($data) || !property_exists($data, 'login')) {
return new CommunicationAnswer("No valid player login provided!", true);
}
$player = $this->maniaControl->getPlayerManager()->getPlayer($data->login);
if ($player) {
$success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($player, self::AUTH_LEVEL_PLAYER);
return new CommunicationAnswer(array("success" => $success));
} else {
return new CommunicationAnswer("Player not found!", true);
}
});
}
/**

View File

@ -16,6 +16,19 @@ interface CommunicationMethods {
*/
const RESTART_MANIA_CONTROL = "ManiaControl.Restart";
/** Grands an Authentication Level on a Player
* Required Parameters
* - login (login of the player)
* - level (integer, 0-3 possible, @see AuthenticationManager)
*/
const GRANT_AUTH_LEVEL = "AuthenticationManager.GrandLevel";
/** Revokes an Authentication Level on a Player
* Required Parameters
* - login (login of the player)
*/
const REVOKE_AUTH_LEVEL = "AuthenticationManager.RevokeLevel";
/** Provides the Server Options
* no Parameters
*/