/** * @param GameInfos $gameInfos * @return string[] */ function validate(GameInfos $gameInfos) { $errors = array(); foreach ((array) $gameInfos as $key => $value) { try { switch ($key) { case 'gameMode': \DedicatedManager\Utils\Validation::int($value, 0, 6); break; case 'roundsUseNewRules': case 'teamUseNewRules': case 'disableRespawn': \DedicatedManager\Utils\Validation::int($value, 0, 1); break; case 'forceShowAllOpponents': case 'chatTime': case 'finishTimeout': case 'allWarmUpDuration': case 'roundsPointsLimit': case 'roundsForcedLaps': case 'roundsPointsLimitNewRules': case 'teamPointsLimit': case 'teamMaxPoints': case 'teamPointsLimitNewRules': case 'timeAttackLimit': case 'timeAttackSynchStartPeriod': case 'lapsNbLaps': case 'lapsTimeLimit': case 'cupPointsLimit': case 'cupRoundsPerMap': case 'cupNbWinners': case 'cupWarmUpDuration': \DedicatedManager\Utils\Validation::int($value); break; case 'scriptName': default: break; } } catch (\Exception $e) { $errors[] = sprintf(_('Wrong value for field "%s".'), $key); } } if ($gameInfos->gameMode === GameInfos::GAMEMODE_SCRIPT && $gameInfos->scriptName == '') { $errors[] = _('You have to select a script to play in script mode.'); } return $errors; }
protected function configureApplication(InputInterface $input, OutputInterface $output) { /* @var $questionHelper QuestionHelper */ $questionHelper = $this->getHelper('question'); $applicationConfig = ApplicationConfig::getInstance(); $dedicatedManagerConfig = DedicatedManagerConfig::getInstance(); $urlQuestion = new Question('Please enter the URL to the manager: '); $urlQuestion->setMaxAttempts(3)->setValidator(function ($url) { try { Validation::url($url); } catch (InvalidArgumentException $e) { throw new \RuntimeException('Invalid URL'); } if (stripos($url, 'http') !== 0) { throw new \RuntimeException('Invalid URL'); } return $url; }); $dedicatedPathQuestion = new Question('Please enter the path to the dedicated server: '); $dedicatedPathQuestion->setMaxAttempts(3)->setValidator(function ($answer) { $path = realpath($answer); if (!is_dir($path)) { throw new \RuntimeException('Invalid path to Dedicated Server'); } if (!file_exists($path . '/ManiaPlanetServer')) { throw new \RuntimeException('Invalid path to Dedicated Server'); } return $path; }); $adminQuestion = new Question('Please enter the login of an admin for this site: '); $adminQuestion->setMaxAttempts(3)->setValidator(function ($login) { if ($login && strlen($login) <= 25) { if (preg_match('/^[a-zA-Z0-9-_\\.]{1,25}$/iu', $login)) { return $login; } } throw new \RuntimeException('Invalid player login'); }); $moreAdminQuestion = new ConfirmationQuestion('Add another admin [y|N])? ', false); $output->writeln('<info>Application configuration</info>'); $applicationConfig->URL = $questionHelper->ask($input, $output, $urlQuestion); $dedicatedManagerConfig->dedicatedPath = $questionHelper->ask($input, $output, $dedicatedPathQuestion); do { $dedicatedManagerConfig->admins[] = $questionHelper->ask($input, $output, $adminQuestion); } while ($questionHelper->ask($input, $output, $moreAdminQuestion)); }