Example #1
0
 public function main()
 {
     $room = intval($_POST['room']);
     $loggedUser = LoggedUser::whoIsLogged();
     $GLOBALS['smarty']->assign('users', Room::getUsers($room));
     echo $GLOBALS['smarty']->fetch('users-box.tpl');
 }
Example #2
0
 /**
  * getter for actual site language
  *
  * @param	string	$lang	language shortcut
  * @return	Language
  */
 public static function getLanguage($lang = NULL)
 {
     $languageRepository = new LanguageRepository(TRUE);
     $language = NULL;
     // ak nemame zadany lang
     if ($lang === NULL) {
         // zistime ci je prihlaseny user a ci ma nastaveny nejaky jazyk
         $loggedUser = LoggedUser::whoIsLogged();
         if ($loggedUser) {
             $lang = $loggedUser['language'];
             if ($lang) {
                 $language = $languageRepository->getOneById($lang);
             }
         }
         // TODO nejaka lokalizacia podla goeip
         // ak stale nemame jazyk, pozrieme sa do url
         if (!$language) {
             $lang = Utils::get('language');
             if ($lang) {
                 $language = $languageRepository->getOneByShortcut($lang);
             } else {
                 // ak nemame zadane nic, vratime anglictinu
                 $language = $languageRepository->getOneByShortcut('sk');
             }
         }
         if (!$language) {
             throw new Exception('Language "' . $lang . '" doesn\'t exist.');
         }
     } else {
         $language = $languageRepository->getOneByShortcut($lang);
     }
     return $language;
 }
Example #3
0
 public function getContent()
 {
     if (LoggedUser::whoIsLogged()) {
         if (isset($_COOKIE['ref_url'])) {
             $url = $_COOKIE['ref_url'];
             $absolute = FALSE;
         } else {
             $page = PageActionMap::getPageByTypeAndLanguage('rooms');
             $url = PageActionMap::createUrl($page['alias']);
             $absolute = TRUE;
         }
         Utils::redirect($url, $absolute);
     }
     if (Utils::post('login')) {
         MySmarty::assign('username', Utils::post('username'));
         $validation = LoggedUser::userLogin();
         //var_Dump($validation);exit();
         if ($validation === TRUE) {
             Utils::redirect(Utils::getActualUrlWithoutGetParameters(), FALSE);
         } else {
             MySmarty::assign('errors', $validation);
         }
     }
     return MySmarty::fetch('login.tpl');
 }
Example #4
0
 public function getContent()
 {
     $loggedUser = LoggedUser::whoIsLogged();
     if ($loggedUser !== NULL) {
         LoggedUser::userLogout();
     }
     Utils::redirect(Utils::getActualUrl(), FALSE);
 }
Example #5
0
 public function main()
 {
     // TODO priamo v hre mi neberie kliknutia akonahle sa vyrenderuju tipy, pravdepodobne to suvisi s tym z-indexom
     $x = intval($_POST['x']);
     $y = intval($_POST['y']);
     $url = addslashes($_POST['url']);
     $loggedUser = LoggedUser::whoIsLogged();
     $params = array('coord_x' => $x, 'coord_y' => $y, 'url' => $url, 'ip' => $_SERVER['REMOTE_ADDR'], 'browser' => $_SERVER['HTTP_USER_AGENT'], 'user' => $loggedUser['id']);
     DB::insert('click', $params);
 }
Example #6
0
 public function main()
 {
     $room = intval($_POST['room']);
     $game = intval($_POST['game']);
     $loggedUser = LoggedUser::whoIsLogged();
     $lastActivity = Room::getUserLastActivityInRoom($loggedUser['id'], $room);
     Room::updateUserLastActivity($loggedUser['id'], $room);
     MySmarty::assign('messages', Chat::getMessages($room, $loggedUser['id'], 0, $game));
     echo MySmarty::fetch('message-box.tpl');
 }
Example #7
0
 /**
  * who is actualy logged
  * 
  * @return	User|NULL
  */
 public static function whoIsLogged()
 {
     if (self::$loggedUser === NULL) {
         if (isset($_COOKIE[self::$cookieName]) && $_COOKIE[self::$cookieName] !== '') {
             $userRepository = new UserRepository();
             self::$loggedUser = $userRepository->getOneByCookieValue(addslashes($_COOKIE[self::$cookieName]));
         }
     }
     return self::$loggedUser;
 }
Example #8
0
 /**
  * adds message to database
  *
  * @param	array	$messageParams	(
  *		text	string,
  *		user	int,
  *		room	int,
  *		toUser	int,
  *		localizeKey	string,
  *		localizeParams	array
  * )
  */
 public static function addMessage($messageParams)
 {
     if (!$messageParams['user']) {
         $loggedUser = LoggedUser::whoIsLogged();
         $messageParams['user'] = $loggedUser['id'];
     }
     $params = array('tstamp' => time(), 'text' => addslashes($messageParams['text']), 'user' => intval($messageParams['user']), 'room' => intval($messageParams['room']), 'to_user' => intval($messageParams['toUser']), 'not_to_user' => intval($messageParams['notToUser']), 'localize_key' => addslashes($messageParams['localizeKey']), 'localize_params' => serialize($messageParams['localizeParams']), 'game' => intval($messageParams['game']));
     // TODO use repository
     DB::insert(DB_PREFIX . self::$table, $params);
 }
Example #9
0
 protected function setup()
 {
     $loggedUser = LoggedUser::whoIsLogged();
     if ($loggedUser) {
         MySmarty::assign('loggedUser', $loggedUser);
         $logoutPage = PageActionMap::getPageByTypeAndLanguage('logout');
         MySmarty::assign('logoutPage', $logoutPage);
     } else {
         $loginPage = PageActionMap::getPageByTypeAndLanguage('login');
         MySmarty::assign('loginPage', $loginPage);
     }
     MySmarty::assign('language', Utils::get('language'));
 }
Example #10
0
 protected function setup()
 {
     $loggedUser = LoggedUser::whoIsLogged();
     if ($this->room !== NULL) {
         Room::addUser($loggedUser['id'], $this->room['id']);
         $messages = Chat::getMessages($this->room['id'], $loggedUser['id'], 0, $this->game['id']);
         MySmarty::assign('loggedUser', $loggedUser);
         MySmarty::assign('messages', $messages);
         MySmarty::assign('users', Room::getUsers($this->room['id']));
         MySmarty::assign('emoticonDir', EMOTICONS_DIR);
         MySmarty::assign('emoticons', Emoticons::getEmoticons());
         MySmarty::assign('room', $this->room);
     }
 }
Example #11
0
 protected function setup()
 {
     $loggedUser = LoggedUser::whoIsLogged();
     if (Utils::post('change_settings')) {
         // TODO check if password and confirm password match
         $loggedUser['password'] = md5(Utils::post('password'));
         $loggedUser['name'] = Utils::post('name');
         $loggedUser['surname'] = Utils::post('surname');
         $loggedUser['color'] = intval(Utils::post('color'));
         $loggedUser->save();
     }
     MySmarty::assign('loggedUser', $loggedUser);
     $colorRepository = new ColorRepository();
     $colors = $colorRepository->getAll();
     MySmarty::assign('colors', $colors);
 }
Example #12
0
 protected function initGame($game)
 {
     $roomAlias = Utils::get('identifier');
     $roomRepository = new RoomRepository();
     $room = $roomRepository->getOneByAlias($roomAlias);
     self::$room = $room['id'];
     self::$loggedUser = LoggedUser::whoIsLogged();
     if ($game && self::$loggedUser) {
         self::$game = $game;
         foreach ($game['players'] as $player) {
             if (self::$loggedUser['id'] == $player['user']['id']) {
                 self::$player = $player;
                 break;
             }
         }
     }
 }
Example #13
0
 protected function setup()
 {
     $loggedUser = LoggedUser::whoIsLogged();
     if (Utils::post('create_room') && $loggedUser['admin']) {
         $params = array('title' => Utils::post('title'), 'alias' => Utils::createAlias(Utils::post('title'), 'room'), 'description' => Utils::post('description'));
         $room = new Room($params);
         $room->save();
     }
     $roomRepository = new RoomRepository();
     $rooms = $roomRepository->getAll();
     $gameRepository = new GameRepository();
     $games = $gameRepository->getGamesByRooms(array_keys($rooms));
     foreach ($games as $game) {
         $rooms[$game['room']]['game'] = TRUE;
         $rooms[$game['room']]['status'] = Localize::getMessage('room_status_' . $game['status']);
     }
     MySmarty::assign('loggedUser', $loggedUser);
     MySmarty::assign('rooms', $rooms);
 }
Example #14
0
 protected function setup()
 {
     $loggedUser = LoggedUser::whoIsLogged();
     MySmarty::assign('loggedUser', $loggedUser);
     MySmarty::assign('room', $this->room);
     if ($this->game) {
         MySmarty::assign('game', $this->game);
         MySmarty::assign('gameStartedStatus', Game::GAME_STATUS_STARTED);
         $playerRepository = new PlayerRepository();
         $actualPlayer = $playerRepository->getOneByGameAndUser($this->game['id'], $loggedUser['id']);
         // phases when we want to make autoreload
         $refreshGameBox = FALSE;
         if (in_array($actualPlayer['phase'], array(Player::PHASE_NONE, Player::PHASE_WAITING))) {
             if ($this->game['status'] == Game::GAME_STATUS_INITIALIZED && $actualPlayer['possible_choices'] != '') {
                 $refreshGameBox = FALSE;
             } else {
                 $refreshGameBox = TRUE;
             }
         }
         MySmarty::assign('refreshGameBox', $refreshGameBox);
         // zobrazime len hracovi ktory je na tahu resp. v medzitahu
         $playerOnMove = $this->game->getPlayerOnMove();
         if ($playerOnMove['id'] == $actualPlayer['id'] || $this->game['status'] == Game::GAME_STATUS_INITIALIZED) {
             MySmarty::assign('response', $actualPlayer['command_response']);
         }
         if ($this->game['status'] == Game::GAME_STATUS_CREATED) {
             if (!GameUtils::checkUserInGame($loggedUser, $this->game)) {
                 MySmarty::assign('joinGameAvailable', TRUE);
             } elseif ($loggedUser['id'] == $this->game['creator']) {
                 MySmarty::assign('startGameAvailable', Localize::getMessage('start_game'));
             }
         } elseif ($this->game['status'] == Game::GAME_STATUS_ENDED) {
             MySmarty::assign('createGameAvailable', Localize::getMessage('create_game'));
             MySmarty::assign('refreshGameBox', TRUE);
         }
     } else {
         MySmarty::assign('createGameAvailable', Localize::getMessage('create_game'));
         MySmarty::assign('refreshGameBox', TRUE);
     }
 }
Example #15
0
 protected function setup()
 {
     $roomAlias = Utils::get('identifier');
     $roomRepository = new RoomRepository();
     $room = $roomRepository->getOneByAlias($roomAlias);
     $loggedUser = LoggedUser::whoIsLogged();
     if ($room) {
         $gameRepository = new GameRepository();
         // $gameRepository->addAdditionalWhere(array('column' => 'status', 'value' => Game::GAME_STATUS_ENDED, 'xxx' => '!='));
         $gameRepository->addOrderBy(array('id' => 'DESC'));
         $game = $gameRepository->getOneByRoom($room['id']);
         if (Utils::post()) {
             $message = addslashes(trim(Utils::post('message')));
             if ($message != '') {
                 if (strpos($message, '.') === 0) {
                     $response = Command::setup('command=' . substr($message, 1), $game);
                 } else {
                     $response = Command::setup('command=say&text=' . $message . '&room=' . $room['id'] . '&game=' . $game['id'], $game);
                 }
                 Room::updateUserLastActivity($loggedUser['id'], $room['id']);
             } elseif (Utils::post('create')) {
                 $response = Command::setup('command=create', $game);
             } elseif (Utils::post('join')) {
                 $response = Command::setup('command=join', $game);
             } elseif (Utils::post('add_ai_player')) {
                 $response = Command::setup('command=add_ai_player', $game);
             } elseif (Utils::post('start')) {
                 $response = Command::setup('command=init', $game);
             } elseif (Utils::post('choose_character')) {
                 $response = Command::setup('command=choose_character&selectedCharacter=' . Utils::post('character'), $game);
             } elseif (Utils::post('choose_cards')) {
                 $commandParams = array();
                 $commandParams['command'] = 'choose_cards';
                 $commandParams['selectedCards'] = array();
                 if (Utils::post('card')) {
                     $commandParams['selectedCards'] = implode(',', Utils::post('card'));
                 }
                 $params = array();
                 foreach ($commandParams as $key => $value) {
                     $params[] = $key . '=' . $value;
                 }
                 $commandString = implode('&', $params);
                 $response = Command::setup($commandString, $game);
             }
             Utils::redirect(Utils::getActualUrl(), FALSE);
             // TODO tu by sa mohol spravit redirect asi lebo respons bude v db
             MySmarty::assign('response', $response);
         }
         $gameBox = new GameBox();
         $gameBox->setRoom($room);
         if ($game !== NULL) {
             $gameBox->setGame($game);
         }
         MySmarty::assign('gameBox', $gameBox->render());
         $chatBox = new ChatBox();
         $chatBox->setRoom($room);
         if ($game !== NULL) {
             $chatBox->setGame($game);
         }
         MySmarty::assign('chatBox', $chatBox->render());
     } else {
         // TODO 404 room not found
     }
 }
Example #16
0
 public static final function setup($command, $game, $actualPlayer = NULL)
 {
     $loggedUser = NULL;
     if ($actualPlayer === NULL) {
         $loggedUser = LoggedUser::whoIsLogged();
         if ($game && $loggedUser) {
             $players = $game->getAdditionalField('players');
             foreach ($players as $player) {
                 if ($loggedUser['id'] == $player['user']['id']) {
                     $actualPlayer = $player;
                     break;
                 }
             }
         }
     } else {
         $loggedUser = $actualPlayer->getUser();
     }
     $explodedCommand = explode('&', $command);
     $commandArray = array();
     foreach ($explodedCommand as $commandParam) {
         $explodedCommandParam = explode('=', $commandParam);
         $key = $explodedCommandParam[0];
         $value = isset($explodedCommandParam[1]) ? $explodedCommandParam[1] : '';
         if ($key == 'place' && $value == '') {
             $value = 'hand';
         }
         $commandArray[$key] = $value;
     }
     //	print_r($commandArray);
     $commandName = $commandArray['command'];
     $useCharacter = FALSE;
     // check if use character is set
     if ($commandArray[useCharacter] == 1) {
         $useCharacter = TRUE;
     }
     /*
     		$commandAliasRepository = new CommandAliasRepository();
     		$command = $commandAliasRepository->getOneByLocalizedCommandName($commandAlias);
     		
     		// toto asi vyhodime lebo vsetky commandy budu musiet byt v db ale zatial to tu necham lebo sa mi to nechce plnit aj pre en
     		if ($command) {
     			$commandName = $command['default_command_name'];
     		} else {
     			$commandName = $commandAlias;
     		}*/
     if ($useCharacter === TRUE) {
         //			$loggedUser = LoggedUser::whoIsLogged();
         //			$playerRepository = new PlayerRepository();
         //			$actualPlayer = $playerRepository->getOneByUserAndGame($loggedUser['id'], $game['id']);
         if ($actualPlayer->getIsCalamityJanet($game)) {
             // kvoli calamity janet musime vymenit bang a missed ak pouziva svoj charakter
             // uprava sa tyka aj metod v ActualPlayerHasCardsChecker getHasBang/MissedOnHand()
             if (in_array($commandName, array('bang', 'missed'))) {
                 if ($commandName == 'bang') {
                     $commandName = 'missed';
                 } elseif ($commandName == 'missed') {
                     $commandName = 'bang';
                 }
             }
         } elseif ($actualPlayer->getIsElenaFuente($game)) {
             // ak je elena fuente pod utokmi a pouziva svoj charakter, berieme to ako keby pouzivala missed
             // uprava sa tyka aj metody v ActualPlayerHasCardsChecker
             if ($actualPlayer['phase'] == Player::PHASE_UNDER_ATTACK) {
                 $commandName = 'missed';
             }
         } elseif ($actualPlayer->getIsAnnieVersary($game)) {
             // Annie Versary moze pouzit akukolvek kartu z ruky ako Bang!
             // uprava sa tyka aj metody v ActualPlayerHasCardsChecker
             $commandName = 'bang';
         } elseif ($actualPlayer->getIsUncleWill($game)) {
             // Uncle Will moze pouzit akukolvek kartu z ruky ako General store!
             // uprava sa tyka aj metody v ActualPlayerHasCardsChecker
             $commandName = 'generalstore';
         }
     }
     $commandClassName = CommandSetup::getCommandClass($commandName);
     if ($commandClassName !== '') {
         $class = new $commandClassName($commandArray, $commandArray, $game);
         $class->setCommandName($commandName);
         $class->setUseCharacter($useCharacter);
         $class->setActualPlayer($actualPlayer);
         $class->setLoggedUser($loggedUser);
         $precheckers = CommandSetup::getCommandPrecheckers($commandName);
         $class->setPrecheckers($precheckers);
         $precheckParams = CommandSetup::getCommandPrecheckParams($commandName);
         $class->setPrecheckersParams($precheckParams);
         return $class->execute();
     } else {
         throw new Exception('Command "' . $commandName . '" not found', 1332363146);
         // TODO add message command not found
     }
 }
Example #17
0
    BangSeo::addTitlePart('Bang!');
    $language = Utils::get('language');
    if (!$language) {
        // TODO check user and country, then default en
        $url = PageActionMap::createUrl(array(), 'sk');
        Utils::redirect($url);
    }
    $actionAlias = Utils::get('action');
    $pageRepository = new PageRepository(TRUE);
    $page = $pageRepository->getOneByAlias($actionAlias);
    $pageTypeRepository = new PageTypeRepository(TRUE);
    $pageType = $pageTypeRepository->getOneById($page['page_type']);
    $action = PageActionMap::getActionByPageAndLanguage(Utils::get('action'));
    $actionClassName = ucfirst($action) . 'Action';
    // TODO caching
    if (LoggedUser::whoIsLogged() === NULL && $pageType['needs_login'] == 1) {
        if ($pageType['action'] != 'logout') {
            setcookie('ref_url', Utils::getActualUrl(), NULL, '/');
        }
        $page = PageActionMap::getPageByTypeAndLanguage('login', $language);
        $url = PageActionMap::createUrl($page['alias']);
        Utils::redirect($url);
    }
    $actionClass = new $actionClassName();
    MySmarty::assign('content', $actionClass->getContent());
} catch (Exception $e) {
    // TODO vsetky exceptions lokalizovat a hadzat uz lokalizovane aby sa tu mohli vypisat
    $pageNotFoundBox = new PageNotFoundBox();
    $pageNotFoundBox->setMessage($e->getMessage());
    $content = $pageNotFoundBox->render();
    MySmarty::assign('content', $content);