added auth level communication methods
This commit is contained in:
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user