diff --git a/application/core/Maps/MapCommands.php b/application/core/Maps/MapCommands.php index f40e4d23..df2bba55 100644 --- a/application/core/Maps/MapCommands.php +++ b/application/core/Maps/MapCommands.php @@ -46,6 +46,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb $this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true); $this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap', true); $this->maniaControl->commandManager->registerCommandListener(array('removemap', 'removethis', 'erasemap', 'erasethis'), $this, 'command_RemoveMap', true); + $this->maniaControl->commandManager->registerCommandListener('shufflemaps', $this, 'command_ShuffleMap', true); // Register for player chat commands $this->maniaControl->commandManager->registerCommandListener(array('maps', 'list'), $this, 'command_List'); @@ -109,6 +110,23 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb $this->maniaControl->mapManager->removeMap($player, $map->uid); } + /** + * Handle addmap command + * + * @param array $chatCallback + * @param \ManiaControl\Players\Player $player + */ + public function command_ShuffleMaps(array $chatCallback, Player $player) { + if(!$this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_SHUFFLE_MAPS)) { + $this->maniaControl->authenticationManager->sendNotAllowed($player); + return; + } + + // add Map from Mania Exchange + $this->maniaControl->mapManager->shuffleMapList(); + //TODO message + } + /** * Handle addmap command * diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 55015092..b51c9866 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -29,6 +29,7 @@ class MapManager implements CallbackListener { const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated'; const SETTING_PERMISSION_ADD_MAP = 'Add Maps'; const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps'; + const SETTING_PERMISSION_SHUFFLE_MAPS = 'Shuffle Maps'; /** * Public Properties @@ -68,6 +69,7 @@ class MapManager implements CallbackListener { //Define Rights $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ADD_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_REMOVE_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN); + $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SHUFFLE_MAPS, AuthenticationManager::AUTH_LEVEL_ADMIN); } /** @@ -156,6 +158,28 @@ class MapManager implements CallbackListener { unset($this->maps[$uid]); } + /** + * Shuffles the MapList + * + * @return bool + */ + public function shuffleMapList() { + if(!$this->maniaControl->client->query('GetMapList', 100, 0)) { + trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText()); + return false; + } + + $mapList = $this->maniaControl->client->getResponse(); + shuffle($mapList); + + if(!$this->maniaControl->client->query('hooseNextChallengeLis', $mapList)) { + trigger_error("Couldn't shuffle mapList. " . $this->maniaControl->getClientErrorText()); + return false; + } + return true; + } + + /** * Updates the full Map list, needed on Init, addMap and on ShuffleMaps */