Ejemplo n.º 1
0
 /**
  * @TODO Document me!
  */
 private function configure()
 {
     $char = Player::find(self_char_id());
     // Array that simulates database display information for switching out for an npc database solution.
     $npcs = [['name' => 'Peasant', 'identity' => 'peasant', 'image' => 'fighter.png'], ['name' => 'Thief', 'identity' => 'thief', 'image' => 'thief.png'], ['name' => 'Merchant', 'identity' => 'merchant', 'image' => 'merchant.png'], ['name' => 'Guard', 'identity' => 'guard', 'image' => 'guard.png'], ['name' => 'Samurai', 'identity' => 'samurai', 'image' => 'samurai.png']];
     $peers = $char ? $this->getNearbyPeers($char->id()) : [];
     $active_ninjas = Player::findActive(5, true);
     $char_info = $char ? $char->dataWithClan() : [];
     // Generic/abstracted npcs
     $other_npcs = NpcFactory::npcsData();
     $enemy_list = $char ? $this->getCurrentEnemies($char->id()) : [];
     $enemy_count = rco($enemy_list);
     $recent_attackers = $char ? $this->getRecentAttackers($char) : [];
     return ['logged_in' => (bool) $char, 'enemy_list' => $enemy_list, 'enemy_count' => $enemy_count, 'char_name' => $char ? $char->name() : '', 'npcs' => $npcs, 'other_npcs' => $other_npcs, 'char_info' => $char_info, 'active_ninjas' => $active_ninjas, 'recent_attackers' => $recent_attackers, 'enemy_list' => $enemy_list, 'peers' => $peers, 'max_enemies' => self::ENEMY_LIMIT <= $enemy_count];
 }
Ejemplo n.º 2
0
 /**
  * Pull & display the chats and a chat send if logged in
  **/
 public function index()
 {
     // Initialize variables to pass to the template.
     $field_size = self::FIELD_SIZE;
     $target = $_SERVER['PHP_SELF'];
     $all_chats_count = $this->getChatCount();
     $view_all = in('view_all');
     $error = in('error');
     $chatlength = in('chatlength', self::DEFAULT_LIMIT, 'toInt');
     $chatlength = min(3000, max(30, $chatlength));
     // Min 30, max 3000
     // Output section.
     $chats = $this->getChats($view_all ? null : $chatlength);
     // Limit by chatlength unless a request to view all came in.
     $more_chats_to_see = rco($chats) < $all_chats_count ? true : null;
     $parts = ['field_size' => $field_size, 'target' => $target, 'chats' => $chats, 'error' => $error, 'more_chats_to_see' => $more_chats_to_see];
     return $this->render($parts);
 }
Ejemplo n.º 3
0
 public function index()
 {
     $target = $player = first_value(in('ninja'), in('player'), in('find'), in('target'));
     $target_id = first_value(in('target_id'), in('player_id'), get_char_id($target));
     // Find target_id if possible.
     $target_player_obj = Player::find($target_id);
     $viewed_name_for_title = null;
     if ($target_player_obj !== null) {
         $viewed_name_for_title = $target_player_obj->name();
     }
     if ($target_player_obj === null) {
         $template = 'no-player.tpl';
         $parts = array();
     } else {
         $player_info = $target_player_obj->as_array();
         // Pull the info out of the object.
         if (!$player_info) {
             $template = 'no-player.tpl';
             $parts = array();
         } else {
             $viewing_player_obj = Player::find(self_char_id());
             $self = self_char_id() && self_char_id() == $player_info['player_id'];
             // Record whether this is a self-viewing.
             if ($viewing_player_obj !== null) {
                 $char_info = $viewing_player_obj->dataWithClan();
                 $char_id = $viewing_player_obj->id();
                 $username = $viewing_player_obj->name();
             } else {
                 $char_info = [];
             }
             $player = $target = $player_info['uname'];
             // reset the target and target_id vars.
             $target_id = $player_info['player_id'];
             // Get the player's kills for this date.
             $kills_today = query_item('select sum(killpoints) from levelling_log where _player_id = :player_id and killsdate = CURRENT_DATE and killpoints > 0', array(':player_id' => $target_id));
             $viewers_clan = $viewing_player_obj !== null ? ClanFactory::clanOfMember($viewing_player_obj) : null;
             // Attack Legal section
             $params = array('required_turns' => 0, 'ignores_stealth' => true);
             // 0 for unstealth.
             $attack_error = 'You must become a ninja first.';
             $attack_allowed = false;
             if (null !== $viewing_player_obj) {
                 $AttackLegal = new AttackLegal($viewing_player_obj, $target_player_obj, $params);
                 $attack_allowed = $AttackLegal->check(false);
                 $attack_error = $AttackLegal->getError();
             }
             $sel_rank_spot = "SELECT rank_id FROM rankings WHERE player_id = :char_id limit 1";
             $rank_spot = query_item($sel_rank_spot, array(':char_id' => $player_info['player_id']));
             // Display the player info.
             $status_list = get_status_list($player);
             $gurl = $gravatar_url = $target_player_obj->avatarUrl();
             if ($viewing_player_obj !== null && !$attack_error && !$self) {
                 // They're not dead or otherwise unattackable.
                 // Attack or Duel
                 $skillDAO = new SkillDAO();
                 $is_admin = false;
                 if ($viewing_player_obj) {
                     $is_admin = $viewing_player_obj->isAdmin();
                 }
                 if (!$is_admin) {
                     $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');
                 }
                 // Pull the items and some necessary data about them.
                 $items = inventory_counts($char_id);
                 $valid_items = rco($items);
                 // row count
             }
             // End of the there-was-no-attack-error section
             $set_bounty_section = '';
             $communication_section = '';
             $player_clan_section = '';
             $clan = ClanFactory::clanOfMember($player_info['player_id']);
             $same_clan = false;
             // Player clan and clan members
             if ($clan) {
                 $viewer_clan = $viewing_player_obj ? ClanFactory::clanOfMember($viewing_player_obj) : null;
                 $clan_id = $clan->getID();
                 $clan_name = $clan->getName();
                 if ($viewer_clan) {
                     $same_clan = $clan->getID() == $viewer_clan->getID();
                     $display_clan_options = $viewing_player_obj && !$self && $same_clan && $viewing_player_obj->isClanLeader();
                 } else {
                     $same_clan = $display_clan_options = false;
                 }
             }
             // Send the info to the template.
             $template = 'player.tpl';
             $parts = get_certain_vars(get_defined_vars(), array('char_info', 'viewing_player_obj', 'target_player_obj', 'combat_skills', 'targeted_skills', 'player_info', 'self', 'rank_spot', 'kills_today', 'gravatar_url', 'status_list', 'clan', 'items'));
         }
     }
     return ['template' => $template, 'title' => 'Ninja' . ($viewed_name_for_title ? ": {$viewed_name_for_title}" : ' Profile'), 'parts' => $parts, 'options' => ['quickstat' => 'player']];
 }
Ejemplo n.º 4
0
function confirm_player($char_name, $confirmation = 0, $autoconfirm = false)
{
    DatabaseConnection::getInstance();
    // Preconfirmed or the email didn't send, so automatically confirm the player.
    $require_confirm = $autoconfirm ? '' : ' AND 
			(account.verification_number = :confirmation OR players.verification_number = :confirmation2) ';
    // Get the account_id for a player
    $params = array(':char_name' => $char_name);
    if ($require_confirm) {
        $params[':confirmation'] = $confirmation;
        $params[':confirmation2'] = $confirmation;
    }
    $info = query_row('select account_id, player_id from players 
		join account_players on _player_id = player_id 
		join accounts on account_id = _account_id 
		 where uname = :char_name ' . $require_confirm, $params);
    if (empty($info)) {
        return false;
    } else {
        $account_id = $info['account_id'];
        $player_id = $info['player_id'];
        if (!$account_id || !$player_id) {
            return false;
        }
    }
    $up = query('update players set active = 1 where player_id = :player_id', array(':player_id' => $player_id));
    $up = "UPDATE accounts set operational = true, confirmed = 1 where account_id = :account_id";
    $params = array(':account_id' => $account_id);
    $result = (bool) rco(query($up, $params));
    return $result;
}
Ejemplo n.º 5
0
 function testGetRankedClanMembersOfAClan()
 {
     $player1 = new Player($this->char_id);
     $clan = ClanFactory::find($this->clan_id);
     $this->assertTrue($clan->addMember($player1, $player1));
     $this->assertEquals(1, rco($clan->getMembers()));
 }
Ejemplo n.º 6
0
 /**
  * Get the ninja list and display it
  *
  * @return ViewSpec
  */
 public function index()
 {
     $session = SessionFactory::getSession();
     $searched = in('searched', null, 'no filter');
     // Don't filter the search setting
     $list_by_rank = $searched && substr_compare($searched, '#', 0, 1) === 0;
     // Whether the search is by rank
     $hide_setting = !$searched && $session->has('hide_dead') ? $session->get('hide_dead') : 'dead';
     // Defaults to hiding dead via session
     $hide = $searched ? 'none' : in('hide', $hide_setting);
     // search override > get setting > session setting
     $alive_only = $hide == 'dead';
     $page = in('page', 1);
     // Page will get changed down below
     $view_type = in('view_type');
     $page = in('page');
     $record_limit = 20;
     // The number of players that gets shown per page
     if (!$searched && $hide_setting != $hide) {
         // Save the toggled state for later
         $session->set('hide_dead', $hide);
     }
     $where_clauses = [];
     // Array to add where clauses to
     $params = [];
     if ($searched) {
         $view_type = 'searched';
         if (strlen($searched) == 1 || !$list_by_rank) {
             $where_clauses[] = " (rankings.uname ilike :searched || '%') ";
             $params[':searched'] = $searched;
         }
         if ($hide == 'dead') {
             $where_clauses[] = " alive = true";
         }
     } else {
         if ($hide == 'dead') {
             $where_clauses[] = " alive";
         }
     }
     $query_count = "SELECT count(player_id) FROM rankings " . (count($where_clauses) ? "WHERE " . implode($where_clauses, ' AND ') : "");
     $totalrows = query_item($query_count, $params);
     // The rankings view automatically filters out inactives, but we have to do it manually when dealing directly with players table.
     $where_clauses[] = " active = 1";
     // ************************ Pagination **************************
     // Determine the current page spot navigated to.
     // If searching, use the page between
     // If no specific rank was requested, use the viewer's rank
     // If a certain rank was requested, use that rank spot.
     // Determine the page, if the dead count is more than the rank spot, default to 1, otherwise use the input page.
     // Determine the number of pages and the limit and offset
     if ($searched && $list_by_rank) {
         $page = ceil(substr($searched, 1) / $record_limit);
     } else {
         if ($page == "searched") {
             $page = in('page', 1);
         } else {
             $page = $page < 1 ? 1 : $page;
             // Prevent the page number from going negative
         }
     }
     $numofpages = ceil($totalrows / $record_limit);
     $offset = (int) max(0, $page * $record_limit - $record_limit);
     $last_page = $totalrows - $record_limit * $page > 0;
     $ninja_rows = $this->getFormattedNinjaRows($where_clauses, $params, $record_limit, $offset);
     $ninja_count = rco($ninja_rows);
     $active_ninjas = null;
     if (!$searched) {
         // Will not display active ninja on a search page.
         $active_ninjas = Player::findActive(5, $alive_only);
         // get  the currently active ninjas
     }
     $dead_count = query_item("SELECT count(player_id) FROM rankings WHERE alive = false");
     $parts = ['searched' => $searched, 'ninja_count' => $ninja_count, 'dead_count' => $dead_count, 'active_ninjas' => $active_ninjas, 'hide' => $hide, 'page' => $page, 'numofpages' => $numofpages, 'last_page' => $last_page, 'ninja_rows' => $ninja_rows];
     $options = ['quickstat' => 'player'];
     $title = 'Ninja List';
     $template = 'list.tpl';
     return ['title' => $title, 'template' => $template, 'parts' => $parts, 'options' => $options];
 }
Ejemplo n.º 7
0
$private = false;
if ($error = init($private, $alive)) {
    display_error($error);
} else {
    $admin_override_pass = '******';
    // Just a weak passphrase for simply confirming players.
    $admin_override_request = in('admin_override');
    $acceptable_admin_override = $admin_override_pass === $admin_override_request;
    $confirm = in('confirm');
    $aid = positive_int(in('aid'));
    $data = query_row('
	SELECT player_id, uname, accounts.verification_number as verification_number, CASE WHEN active = 1 THEN 1 ELSE 0 END AS active, accounts.active_email, 
	CASE WHEN accounts.confirmed = 1 THEN 1 ELSE 0 END as confirmed, status, member, days, ip, players.created_date 
	FROM accounts JOIN account_players ON _account_id = account_id JOIN players ON _player_id = player_id 
	WHERE account_id = :acctId', array(':acctId' => $aid));
    if (rco($data)) {
        $check = $data['verification_number'];
        $confirmed = $data['confirmed'];
        $active = $data['active'];
        $username = $data['uname'];
    } else {
        $active = $check = $confirmed = $username = null;
    }
    //debug($data, $confirm, $check, $confirmed);
    //debug($check, $confirm);
    $confirmation_confirmed = false;
    if ($confirmed == 1) {
        // Confirmation state from the database is already confirmed.
    } else {
        if ($check && $confirm && $confirm == $check || $acceptable_admin_override) {
            // Confirmation number matches whats in the database and neither is null, or the admin override was met.
Ejemplo n.º 8
0
     $combat_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->vo->_class_id, 'combat', $viewing_player_obj->vo->level)->fetchAll();
     $targeted_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->vo->_class_id, 'targeted', $viewing_player_obj->vo->level)->fetchAll();
     // *** todo When Smarty3 is released, remove fetch all and change template to new foreach-as syntax ***
     // Check all the combat toggles to see if they should be checked on the profile page.
     foreach ($combat_skills as &$skill) {
         $skill['checked'] = 0;
         if (isset($combat_toggles[$skill['skill_internal_name']]) && $combat_toggles[$skill['skill_internal_name']]) {
             $skill['checked'] = 1;
             // Save the setting associatively back to the original array.
         }
     }
     $duel_checked = !!$combat_toggles['duel'];
     // Duel isn't in the general combat skills, so it gets set separately.
     // Pull the items and some necessary data about them.
     $items = inventory_counts($char_id, $last_item_used);
     $valid_items = rco($items);
     // row count
     //debug($items);
 }
 // End of the there-was-no-attack-error section
 $set_bounty_section = '';
 $communication_section = '';
 $player_clan_section = '';
 $clan = get_clan_by_player_id($player_info['player_id']);
 $same_clan = false;
 $player_info = format_health_percent($player_info);
 // Player clan and clan members
 if ($clan) {
     $viewer_clan = is_logged_in() ? get_clan_by_player_id($viewing_player_obj->vo->player_id) : null;
     $clan_members = get_clan_members($clan->getID())->fetchAll();
     // TODO - When we switch to Smarty 3, remove fetchAll for foreach