diff --git a/core/Admin/AuthenticationManager.php b/core/Admin/AuthenticationManager.php index dd6ef9c1..8d4b5ab6 100644 --- a/core/Admin/AuthenticationManager.php +++ b/core/Admin/AuthenticationManager.php @@ -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); + } + }); } /** diff --git a/core/Communication/CommunicationMethods.php b/core/Communication/CommunicationMethods.php index 6451890c..c4384a34 100644 --- a/core/Communication/CommunicationMethods.php +++ b/core/Communication/CommunicationMethods.php @@ -11,11 +11,24 @@ namespace ManiaControl\Communication; */ interface CommunicationMethods { /** Restarts Mania Control - * Optional Params - * - message + * Optional Params + * - message */ 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 */