/** * @param string $login * @param string $password * @param bool $rememberMe * @return Token */ public function login($login, $password, $rememberMe = true) { try { $account = $this->accountService->getRepository()->findByLogin($login); if ($rememberMe === true) { $config = Game::getInstance()->getConfig(); $rememberDays = $config["app"]["remember_days"]; $endTime = time() + 3600 * 24 * $rememberDays; } else { $endTime = time() + 600; } $endDate = new \DateTime(); $endDate->setTimestamp($endTime); if (is_null($account->getAuthToken())) { $token = $this->tokenService->generateToken($account, $endDate); $account->setAuthToken($token); } elseif (!$this->tokenService->isValid($account->getAuthToken()->getValue())) { $token = $this->tokenService->generateToken($account, $endDate); $account->setAuthToken($token); } $this->accountService->getRepository()->save($account); return $account->getAuthToken(); } catch (EntityNotFoundException $e) { return false; } }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var $helpers LikedimionCommandHelper */ $helpers = $this->getHelperSet()->get("helpers"); /** @var $translations TranslationsHelperInterface */ $translations = $this->getHelper("translations"); $authData = $helpers->authDialog($this, $output, false); /** @var $authService AuthServiceInterface */ $authService = Game::getInstance()->getContainer()->get("auth_service"); $token = $authService->login($authData->getLogin(), $authData->getPassword(), $authData->getRememberMe()); if ($token !== false) { Game::getInstance()->setAuthToken($token); $player = $helpers->createPlayerDialog($this, $output); /** @var $playerRegistrationService PlayerRegistrationServiceInterface */ $playerRegistrationService = Game::getInstance()->getContainer()->get("player_registration_service"); try { $player = $playerRegistrationService->createPlayer($player); $output->writeln(sprintf($translations->getLine("player_create_complete"), $player->getName())); } catch (RegistrationException $e) { $output->writeln($translations->getLine($e->getMessage())); } } else { $output->writeln($translations->getLine("auth_fail")); } }
public function __construct($config) { if (isset($config["doctrine"])) { $dbParams = $config["doctrine"]["db_params"]; $paths = StringCommon::replaceKeyWords($config["doctrine"]["entity_paths"]); $isDevMode = $config["doctrine"]["is_dev_mode"]; $proxyDir = StringCommon::replaceKeyWords($config["doctrine"]["proxy_dir"]); $proxyNamespace = $config["doctrine"]["proxy_namespace"]; $applicationMode = Game::getInstance()->getApplicationMode(); if ($applicationMode == Game::DEVELOPMENT_MODE) { $cache = new \Doctrine\Common\Cache\ArrayCache(); } else { $cache = new \Doctrine\Common\Cache\ApcCache(); } $doctrineConfig = new Configuration(); $doctrineConfig->setMetadataCacheImpl($cache); $driverImpl = $doctrineConfig->newDefaultAnnotationDriver($paths); $doctrineConfig->setMetadataDriverImpl($driverImpl); $doctrineConfig->setQueryCacheImpl($cache); $doctrineConfig->setProxyDir($proxyDir); $doctrineConfig->setProxyNamespace($proxyNamespace); if ($applicationMode == Game::DEVELOPMENT_MODE) { $doctrineConfig->setAutoGenerateProxyClasses(true); } else { $doctrineConfig->setAutoGenerateProxyClasses(false); } $entityManager = EntityManager::create($dbParams, $doctrineConfig); Game::getInstance()->getContainer()->set("entity_manager", $entityManager); } else { throw new \RuntimeException("You need add Doctrine config in your res/config.yml"); } }
/** * @param \Likedimion\Tools\Helper\PlayerDataHelper $playerData * @throws \Likedimion\Exception\RegistrationException * @return Player */ public function createPlayer(PlayerDataHelper $playerData) { try { $findPlayer = $this->playerService->getRepository()->findPlayerByName($playerData->name); throw new RegistrationException("player_name_exists"); } catch (EntityNotFoundException $e) { $player = new Player(); $player->setName($playerData->name); $player->setSex($playerData->sex); $player->setClass($playerData->class); $player->setRace($playerData->race); $stats = $player->getStats(); $cfg = Game::getInstance()->getConfig(); $stats->setStrenge($cfg["new_player"][$player->getClass()]["str"]); $stats->setDexterity($cfg["new_player"][$player->getClass()]["dex"]); $stats->setIntelligence($cfg["new_player"][$player->getClass()]["int"]); $stats->setSpirituality($cfg["new_player"][$player->getClass()]["spr"]); $stats->setEndurance($cfg["new_player"][$player->getClass()]["end"]); $player->setStats($stats); $this->playerCalculatingService->calculate($player); $this->playerService->getRepository()->save($player); $account = $this->authService->getAccount(Game::getInstance()->getAuthToken()->getValue()); $player->setAccount($account); $this->accountService->getRepository()->save($account); $this->playerService->getRepository()->save($player); return $player; } }
protected function setUp() { $this->game = Game::getInstance(); $this->tokenService = $this->game->get("token_service"); $this->email = "*****@*****.**"; $this->password = "******"; $this->confirmPassword = "******"; $this->entityAccountClass = "Likedimion\\Database\\Entity\\Account"; }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var $helpers LikedimionCommandHelper */ $helpers = $this->getHelperSet()->get("helpers"); $authData = $helpers->authDialog($this, $output); /** @var $authService AuthServiceInterface */ $authService = Game::getInstance()->getContainer()->get("auth_service"); $token = $authService->login($authData->getLogin(), $authData->getPassword(), $authData->getRememberMe()); $output->writeln($token->getValue()); }
/** * @param string $name * @param int $sex * @param int $class * @return Player */ public function createPlayer($name, $sex, $class) { $account = $this->authService->getAccount(Game::getInstance()->getAuthToken()->getValue()); $player = new Player(); $statistic = new PlayerStatistic(); $player->setAccount($account); $player->setName($name); $player->setStatistic($statistic); $player->setSex($sex); $player->setClass($class); $this->getRepository()->save($player); }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var $dialog DialogHelper */ $dialog = $this->getHelperSet()->get("dialog"); /** @var $translations TranslationsHelperInterface */ $translations = $this->getHelper("translations"); $login = $dialog->ask($output, $translations->getLine("please_input_login"), false); $password = $dialog->askHiddenResponse($output, $translations->getLine("please_input_password"), "password"); $passwordConfirm = $dialog->askHiddenResponse($output, $translations->getLine("please_confirm_password"), "password"); /** @var $accountService AccountServiceInterface */ $accountService = Game::getInstance()->getContainer()->get("account_service"); try { $accountService->registration($login, $password, $passwordConfirm); $output->writeln(sprintf("<info>%s</info>", $translations->getLine("registration_complete"))); } catch (AccountServiceException $e) { $output->writeln(sprintf("<comment>%s</comment>", $translations->getLine($e->getMessage()))); } }
<?php /** * Created by PhpStorm. * User: maksim * Date: 30.11.13 * Time: 21:52 */ require __DIR__ . "/../index.php"; $em = \Likedimion\Game::getInstance()->getContainer()->get("entity_manager"); return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($em);
/** * @param $data * @return string|\Symfony\Component\Serializer\Encoder\scalar */ protected function serialize($data) { $cfg = Game::getInstance()->getConfig(); return $this->getSerializer()->serialize($data, $cfg["app"]["serialize_format"]); }
public function addListeners() { $container = Game::getInstance()->getContainer(); $this->addListener(EventsStore::LVL_UP, array($container->get("player_listener"), "onLvlUp")); $this->addListener(EventsStore::ADD_EXP, array($container->get("player_listener"), "onAddExp")); }
<?php use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; use Likedimion\Tools\Helper\LikedimionCommandHelper; use Symfony\Component\Console\Helper\DialogHelper; /** * Created by PhpStorm. * User: maksim * Date: 30.11.13 * Time: 22:40 */ require __DIR__ . "/../index.php"; $cli = new \Symfony\Component\Console\Application('Likedimion CLI', \Likedimion\Game::getInstance()->getVersion()); $entityManager = \Likedimion\Game::getInstance()->getContainer()->get("entity_manager"); $config = \Likedimion\Game::getInstance()->getConfig(); $translationsHelper = new \Likedimion\Tools\Helper\TranslationHelper(); $translationsHelper->setLocale(\Likedimion\Common\StringCommon::replaceKeyWords($config["app"]["locale"])); $translationsHelper->load(); $helperSet = \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager); $helperSet->set(new DialogHelper(), 'dialog'); $helperSet->set($translationsHelper, 'translations'); $helperSet->set(new LikedimionCommandHelper(), "helpers"); $cli->setHelperSet($helperSet); $cli->addCommands(array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand(), new \Likedimion\Tools\Command\AccountRegistrationCommand(), new \Likedimion\Tools\Command\AuthorisationCommand(), new \Likedimion\Tools\Command\PlayerCreateCommand(), new \Likedimion\Tools\Command\LoadDefaultDataCommand())); \Doctrine\ORM\Tools\Console\ConsoleRunner::addCommands($cli); $cli->run();
<?php use Symfony\Component\Yaml\Yaml; date_default_timezone_set('Europe/Moscow'); ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); define("ROOT_DIR", dirname(__FILE__)); define("RES_DIR", dirname(__FILE__) . DIRECTORY_SEPARATOR . "res"); define("SRC_DIR", dirname(__FILE__) . DIRECTORY_SEPARATOR . "src"); $loader = (require ROOT_DIR . "/vendor/autoload.php"); $loader->add("Likedimion\\", SRC_DIR . "/likedimion/lib"); $loader->add("Likedimion\\Proxies", RES_DIR . "/doctrine/proxy"); $loader->add("Likedimion\\Client", SRC_DIR . "/ldc/lib"); $loader->add("Likedimion\\", SRC_DIR . "/data-loader/lib"); $loader->add("Migrations\\", RES_DIR . "/doctrine/migrations"); $game = \Likedimion\Game::getInstance(); $config = Yaml::parse(file_get_contents(RES_DIR . "/config.yml")); define("DATA_DIR", dirname(__FILE__) . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "" . $config["app"]["base_locale"]); $game->setConfig($config); $game->play();