Exemplo n.º 1
1
 public function index()
 {
     $request = RequestWrapper::$request;
     $target = $request->get('player');
     $target_id = $request->get('player_id');
     if ($target_id) {
         $target_player_obj = Player::find($target_id);
     } else {
         $target_player_obj = Player::findByName($target);
     }
     if ($target_player_obj === null) {
         $template = 'no-player.tpl';
         $viewed_name_for_title = null;
         $parts = array();
     } else {
         $attack_error = 'You must become a ninja first.';
         $clan = Clan::findByMember($target_player_obj);
         $combat_skills = null;
         $display_clan_options = false;
         $items = null;
         $same_clan = false;
         $self = false;
         $targeted_skills = null;
         $template = 'player.tpl';
         $viewed_name_for_title = $target_player_obj->name();
         $viewing_player_obj = Player::find(SessionFactory::getSession()->get('player_id'));
         $kills_today = query_item('SELECT sum(killpoints) FROM levelling_log WHERE _player_id = :player_id AND killsdate = CURRENT_DATE AND killpoints > 0', [':player_id' => $target_player_obj->id()]);
         $rank_spot = query_item('SELECT rank_id FROM rankings WHERE player_id = :player_id limit 1', [':player_id' => $target_player_obj->id()]);
         if ($viewing_player_obj !== null) {
             $viewers_clan = Clan::findByMember($viewing_player_obj);
             $self = $viewing_player_obj->id() === $target_player_obj->id();
             $params = ['required_turns' => 0, 'ignores_stealth' => true];
             $AttackLegal = new AttackLegal($viewing_player_obj, $target_player_obj, $params);
             $AttackLegal->check(false);
             $attack_error = $AttackLegal->getError();
             if (!$attack_error && !$self) {
                 // They're not dead or otherwise unattackable.
                 // Pull the items and some necessary data about them.
                 $inventory = new Inventory($viewing_player_obj);
                 $items = $inventory->counts();
                 $skillDAO = new SkillDAO();
                 if (!$viewing_player_obj->isAdmin()) {
                     $combat_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->_class_id, 'combat', $viewing_player_obj->level);
                     $targeted_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->_class_id, 'targeted', $viewing_player_obj->level);
                 } else {
                     $combat_skills = $skillDAO->all('combat');
                     $targeted_skills = $skillDAO->all('targeted');
                 }
             }
             if ($clan && $viewers_clan) {
                 $same_clan = $clan->id == $viewers_clan->id;
                 $display_clan_options = !$self && $same_clan && $viewing_player_obj->isClanLeader();
             }
         }
         $parts = ['viewing_player_obj' => $viewing_player_obj, 'target_player_obj' => $target_player_obj, 'combat_skills' => $combat_skills, 'targeted_skills' => $targeted_skills, 'self' => $self, 'rank_spot' => $rank_spot, 'kills_today' => $kills_today, 'status_list' => Player::getStatusList($target_player_obj->id()), 'clan' => $clan, 'items' => $items, 'account' => Account::findByChar($target_player_obj), 'same_clan' => $same_clan, 'display_clan_options' => $display_clan_options, 'attack_error' => $attack_error];
     }
     $parts['authenticated'] = SessionFactory::getSession()->get('authenticated', false);
     $title = 'Ninja' . ($viewed_name_for_title ? ": {$viewed_name_for_title}" : ' Profile');
     return new StreamedViewResponse($title, $template, $parts, ['quickstat' => 'player']);
 }
Exemplo n.º 2
1
 /**
  * Display the combat/action events and mark them as read when displayed.
  *
  * @return Response
  */
 public function index()
 {
     $char = Player::find(SessionFactory::getSession()->get('player_id'));
     $events = $this->getEvents($char->id(), 300);
     $this->readEvents($char->id());
     // mark events as viewed.
     $parts = ['events' => $events, 'has_clan' => (bool) Clan::findByMember($char), 'char' => $char];
     return new StreamedViewResponse('Events', 'events.tpl', $parts, ['quickstat' => 'player']);
 }
Exemplo n.º 3
1
 /**
  * The standard homepage
  *
  * @return Response
  */
 private function game()
 {
     // Get the actual values of the vars.
     $ninja = Player::find(SessionFactory::getSession()->get('player_id'));
     $playerInfo = $ninja->data();
     $clan = $ninja ? Clan::findByMember($ninja) : null;
     $unreadCount = Message::where(['send_to' => $ninja->id(), 'unread' => 1])->count();
     // Assign these vars to the template.
     $parts = ['main_src' => '/intro', 'body_classes' => 'main-body', 'version' => 'NW Version 1.7.5 2010.12.05', 'ninja' => $ninja, 'player_info' => $playerInfo, 'clan' => $clan, 'unread_message_count' => $unreadCount];
     return new StreamedViewResponse('Live by the Shuriken', 'index.tpl', $parts, ['is_index' => true]);
 }
Exemplo n.º 4
1
 public function testViewAnotherClan()
 {
     // create new character to lead the new clan
     $char_id_2 = TestAccountCreateAndDestroy::char_id_2();
     // create new clan
     $clan = Clan::create(Player::find($char_id_2), 'phpunit_test_clan2');
     // view new clan
     $request = Request::create('/clan/view', 'GET', ['clan_id' => $clan->id]);
     RequestWrapper::inject($request);
     $response = $this->controller->view($this->m_dependencies);
     // delete new clan
     $this->deleteClan($clan->id);
     $this->assertInstanceOf(StreamedViewResponse::class, $response);
 }
Exemplo n.º 5
0
 function testClanNameNegativeValidation()
 {
     $clanName = 'Ù�س اÙ�Ù�Ø·Ø';
     $this->assertFalse((bool) Clan::isValidClanName($clanName));
 }
Exemplo n.º 6
0
 /**
  * ????
  *
  * @todo Simplify this invite system.
  * @param int $user_id
  * @param int $clan_id
  * @return void
  */
 private function sendClanJoinRequest($user_id, $clan_id)
 {
     DatabaseConnection::getInstance();
     $clan_obj = new Clan($clan_id);
     $leader = $clan_obj->getLeaderInfo();
     $leader_id = $leader['player_id'];
     $username = get_char_name($user_id);
     $confirmStatement = DatabaseConnection::$pdo->prepare('SELECT verification_number FROM players WHERE player_id = :user');
     $confirmStatement->bindValue(':user', $user_id);
     $confirmStatement->execute();
     $confirm = $confirmStatement->fetchColumn();
     // These ampersands get encoded later.
     $url = "[href:clan/review/?joiner={$user_id}&confirmation={$confirm}|Confirm Request]";
     $join_request_message = 'CLAN JOIN REQUEST: ' . htmlentities($username) . " has sent a request to join your clan.\n            If you wish to allow this ninja into your clan click the following link:\n                {$url}";
     Message::create(['send_from' => $user_id, 'send_to' => $leader_id, 'message' => $join_request_message, 'type' => 0]);
 }
Exemplo n.º 7
0
 /**
  * View clan messages
  *
  * @param Container
  */
 public function viewClan(Container $p_dependencies)
 {
     $ninja = $p_dependencies['current_player'];
     $page = max(1, (int) RequestWrapper::getPostOrGet('page'));
     $limit = 25;
     $offset = ($page - 1) * $limit;
     $type = 1;
     // Clan chat or normal messages.
     $message_count = Message::countByReceiver($ninja, $type);
     // To count all the messages
     Message::markAsRead($ninja, $type);
     // mark messages as read for next viewing.
     $parts = array_merge($this->configure(), ['messages' => Message::findByReceiver($ninja, $type, $limit, $offset), 'message_count' => $message_count, 'pages' => ceil($message_count / $limit), 'current_page' => $page, 'current_tab' => 'clan', 'has_clan' => (bool) Clan::findByMember($ninja)]);
     return $this->render($parts, 'Clan Messages');
 }
Exemplo n.º 8
0
 /**
  * Display the default stats page
  *
  * @param Container
  */
 public function index(Container $p_dependencies)
 {
     $request = RequestWrapper::$request;
     $char = $p_dependencies['current_player'];
     $parts = ['char' => $char, 'clan' => Clan::findByMember($char), 'status_list' => Player::getStatusList(), 'rank_display' => $this->getRank($char->id()), 'profile_max_length' => self::PROFILE_MAX_LENGTH, 'error' => $request->get('error'), 'successMessage' => '', 'profile_changed' => (bool) $request->get('profile_changed'), 'changed' => (bool) $request->get('changed')];
     return $this->render($parts);
 }
Exemplo n.º 9
0
 /**
  * Save the data of an already created clan.
  */
 public static function save(Clan $clan)
 {
     if (!$clan->id()) {
         throw new \Exception('Clan cannot be saved as it does not yet have an id.');
     }
     $updated = update_query('update clan set clan_name = :name, clan_founder = :founder, clan_avatar_url = :avatar_url, description = :desc where clan_id = :id', [':name' => $clan->getName(), ':founder' => $clan->getFounder(), ':avatar_url' => $clan->getAvatarUrl(), ':desc' => $clan->getDescription(), ':id' => $clan->id()]);
     return (bool) $updated;
 }
Exemplo n.º 10
0
 /**
  * Check whether the player is the leader of their clan.
  * @return boolean
  */
 public function isClanLeader()
 {
     return ($clan = Clan::findByMember($this)) && $this->id() == $clan->getLeaderID();
 }