예제 #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']);
 }
 public static function createAccount($ninja_name, $email, $class_identity)
 {
     $found = Player::findByName($ninja_name);
     if ($found) {
         throw new Exception("Test user found [{$found}] with name [{$ninja_name}] already exists");
     }
     $ip = isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     // Create test user, unconfirmed, whatever the default is for activity.
     $confirm = rand(1000, 9999);
     //generate confirmation code
     $class_id = query_item('SELECT class_id FROM class WHERE identity = :class_identity', [':class_identity' => $class_identity]);
     $ninja = new Player();
     $ninja->uname = $ninja_name;
     $ninja->verification_number = $confirm;
     $ninja->active = 1;
     $ninja->_class_id = $class_id;
     $ninja->save();
     Account::create($ninja->id(), $email, TestAccountCreateAndDestroy::$test_password, $confirm, 0, 1, $ip);
     if ($confirm) {
         $ninja->active = 1;
         $ninja->save();
         $account = Account::findByChar($ninja);
         $account->confirmed = 1;
         $account->setOperational(true);
         $account->save();
     }
     return $ninja->id();
 }
예제 #3
0
 public function testAddShouldIncreaseItemCount()
 {
     $inventory = new Inventory($this->char);
     $inventory->add('shuriken', 10);
     $count = query_item('select amount from inventory join item on item.item_id = inventory.item_type where owner = :id', [':id' => $this->char->id()]);
     $this->assertEquals(10, $count);
 }
예제 #4
0
 public function testNonexistentPlayerReturnsNullViaStaticFind()
 {
     $id = query_item('select max(player_id) from players');
     $bad_id = $id + 100;
     $char = Player::find($bad_id);
     $this->assertEquals(null, $char);
 }
예제 #5
0
 public function testViewNonexistentClan()
 {
     $bad_id = query_item('SELECT max(clan_id)+1 AS bad_id FROM clan');
     $request = Request::create('/clan/view', 'GET', ['clan_id' => $bad_id]);
     RequestWrapper::inject($request);
     $response = $this->controller->view($this->m_dependencies);
     $this->assertInstanceOf(StreamedViewResponse::class, $response);
 }
예제 #6
0
 /**
  * Retrieve the password request with the appropriate nonce data
  *
  * @group early
  */
 public function testRetrieveCreatedPasswordReset()
 {
     $account_id = query_item('select account_id from accounts limit 1');
     $this->assertGreaterThan(0, $account_id);
     $this->nonce = '777777';
     $req = PasswordResetRequest::generate(new Account($account_id), $this->nonce);
     $this->assertEquals($this->nonce, $req->nonce);
     // Create
     $req = PasswordResetRequest::match($this->nonce);
     // Match
     $this->assertEquals($this->nonce, $req->nonce);
 }
예제 #7
0
 function setUp()
 {
     $clan_identity = 'randomNewTestClan';
     $id_already_exists = query_item('select clan_id from clan where clan_name = :name', [':name' => $clan_identity]);
     if ($id_already_exists) {
         $this->deleteClan($id_already_exists);
     }
     $this->clan = ClanFactory::create($clan_identity, ['founder' => 'phpunittest', 'description' => 'Some clan description']);
     $this->clan_id = $this->clan->getId();
     $this->char_id = TestAccountCreateAndDestroy::char_id();
     $this->char_id_2 = TestAccountCreateAndDestroy::char_id_2();
 }
예제 #8
0
 /**
  * Stats on recent activity and other aggregate counts/information.
  *
  * @return array
  */
 private function membershipAndCombatStats()
 {
     DatabaseConnection::getInstance();
     $viciousResult = DatabaseConnection::$pdo->query('SELECT stat_result from past_stats where id = 4');
     $todaysViciousKiller = $viciousResult->fetchColumn();
     $stats = [];
     $stats['vicious_killer'] = $todaysViciousKiller;
     $playerCount = DatabaseConnection::$pdo->query("SELECT count(player_id) FROM players WHERE active = 1");
     $stats['player_count'] = $playerCount->fetchColumn();
     $stats['active_chars'] = query_item("SELECT count(*) FROM ppl_online WHERE member = true AND activity > (now() - CAST('15 minutes' AS interval))");
     return $stats;
 }
예제 #9
0
/**
 * Return the char id that corresponds with a char name, or the logged in account, if no other source is available.
 *
 * @return int|null
 */
function get_char_id($p_name)
{
    $sql = "SELECT player_id FROM players WHERE lower(uname) = :find";
    return query_item($sql, array(':find' => strtolower($p_name)));
}
예제 #10
0
function get_gold($char_id)
{
    return (int) query_item('SELECT gold FROM players WHERE player_id = :char_id', array(':char_id' => $char_id));
}
예제 #11
0
function class_display_name_from_identity($identity)
{
    return query_item('SELECT class_name from class where identity = :identity', array(':identity' => $identity));
}
예제 #12
0
 /**
  * Checks whether an attack is legal or not.
  *
  * @return boolean
  **/
 public function check($update_timer = true)
 {
     $attacker = $this->attacker;
     $target = $this->target;
     $possible = array('required_turns', 'ignores_stealth', 'self_use', 'clan_forbidden');
     // *** Initializes all the possible param indexes. ***
     foreach ($possible as $loop_index) {
         ${$loop_index} = isset($this->params[$loop_index]) ? $this->params[$loop_index] : NULL;
     }
     if (!is_object($this->attacker)) {
         $this->error = 'Only Ninja can get close enough to attack.';
         return FALSE;
     } elseif (!is_object($this->target)) {
         $this->error = 'No valid target was found.';
         return FALSE;
     } elseif (!isset($this->params['required_turns'])) {
         $this->error = 'The required number of turns was not specified.';
         return FALSE;
     }
     $second_interval_limiter_on_attacks = '.25';
     // Originally .2
     $sel_last_started_attack = "SELECT player_id FROM players\n\t\t\tWHERE player_id = :char_id\n\t\t\tAND ((now() - :interval::interval) >= last_started_attack) LIMIT 1";
     // *** Returns a player id if the enough time has passed, or else or false/null. ***
     $attack_later_than_limit = query_item($sel_last_started_attack, array(':char_id' => intval($this->attacker->id()), ':interval' => $second_interval_limiter_on_attacks . ' second'));
     if ($attack_later_than_limit && $update_timer) {
         // *** If not too soon, update the attack limit. ***
         update_last_attack_time($attacker->id());
         // updates the timestamp of the last_attacked column to slow excessive attacks.
     }
     //  *** START OF ILLEGAL ATTACK ERROR LIST  ***
     if (!$attack_later_than_limit) {
         $this->error = 'Even the fastest ninja cannot act more than four times a second.';
     } else {
         if (empty($target->vo->uname)) {
             $this->error = 'Your target does not exist.';
         } else {
             if ($target->id() == $attacker->id() && !$self_use) {
                 $this->error = 'Commiting suicide is a tactic reserved for samurai.';
             } else {
                 if ($attacker->vo->turns < $required_turns) {
                     $this->error = 'You don\'t have enough turns for that, wait for the half hour or use amanita mushrooms to gain more turns.';
                 } else {
                     if (!$self_use && $this->sameDomain($target, $attacker)) {
                         $this->error = 'You can not attack a ninja from the same domain.';
                     } else {
                         if ($target->vo->active == 0) {
                             $this->error = 'You can not attack an inactive ninja.';
                         } else {
                             if ($attacker->vo->active == 0) {
                                 $this->error = 'You cannot attack when your ninja is retired/inactive.';
                             } else {
                                 if ($target->health() < 1) {
                                     $this->error = "They're already dead.";
                                 } else {
                                     if ($target->hasStatus(STEALTH) && !$ignores_stealth) {
                                         // Attacks that ignore stealth will skip this.
                                         $this->error = 'Your target is stealthed. You can only hit this ninja using certain techniques.';
                                     } else {
                                         if ($clan_forbidden && $target->getClan()->getID() == $attacker->getClan()->getID() && $attacker->getClan() == null && !$self_use) {
                                             $this->error = 'Your clan would outcast you if you attacked one of your own.';
                                         } else {
                                             if ($target->health() > 0) {
                                                 $this->error = null;
                                                 return true;
                                                 //  ***  ATTACK IS LEGAL ***
                                             } else {
                                                 //  *** CATCHALL ERROR MESSAGE ***
                                                 $this->error = 'There was a problem with your attack.';
                                                 error_log('The problem catch-all for attackLegal object was triggered, which should not occur.');
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return empty($this->error);
 }
예제 #13
0
 /**
  * Change the kills amount of a char, and levels them up when necessary.
  * @return int
  */
 private function changeKills($amount)
 {
     $amount = (int) $amount;
     GameLog::updateLevellingLog($this->id(), $amount);
     if ($amount !== 0) {
         // Ignore changes that amount to zero.
         if ($amount > 0) {
             // when adding kills, check if levelling occurs
             $this->levelUp();
         }
         query("UPDATE players SET kills = kills + CASE WHEN kills + :amount1 < 0 THEN kills*(-1) ELSE :amount2 END WHERE player_id = :player_id", [':amount1' => [$amount, PDO::PARAM_INT], ':amount2' => [$amount, PDO::PARAM_INT], ':player_id' => $this->id()]);
     }
     return $this->vo->kills = query_item("SELECT kills FROM players WHERE player_id = :player_id", [':player_id' => [$this->id(), PDO::PARAM_INT]]);
 }
예제 #14
0
function membership_and_combat_stats($update_past_stats = false)
{
    DatabaseConnection::getInstance();
    $vk = DatabaseConnection::$pdo->query('SELECT stat_result from past_stats where id = 4');
    $todaysViciousKiller = $vk->fetchColumn();
    $stats['vicious_killer'] = $todaysViciousKiller;
    $pc = DatabaseConnection::$pdo->query("SELECT count(player_id) FROM players WHERE active = 1");
    $stats['player_count'] = $pc->fetchColumn();
    $po = DatabaseConnection::$pdo->query("SELECT count(*) FROM ppl_online WHERE member = true");
    $stats['players_online'] = $po->fetchColumn();
    $stats['active_chars'] = query_item("SELECT count(*) FROM ppl_online WHERE member = true AND activity > (now() - CAST('15 minutes' AS interval))");
    return $stats;
}
예제 #15
0
     $covert = true;
     $state = 'stealthed';
     if (!$target->hasStatus(STEALTH)) {
         $target->addStatus(STEALTH);
         $generic_state_change = "__TARGET__ is now {$state}.";
     } else {
         $turn_cost = 0;
         $generic_state_change = "__TARGET__ is already {$state}.";
     }
 } else {
     if ($command == 'Kampo') {
         $covert = true;
         // *** Get Special Items From Inventory ***
         $user_id = self_char_id();
         $root_item_type = 7;
         $itemCount = query_item('SELECT sum(amount) AS c FROM inventory WHERE owner = :owner AND item_type = :type GROUP BY item_type', array(':owner' => $user_id, ':type' => $root_item_type));
         $turn_cost = min($itemCount, $starting_turns - 1, 2);
         // Costs 1 or two depending on the number of items.
         if ($turn_cost && $itemCount > 0) {
             // *** If special item count > 0 ***
             removeItem($user_id, 'ginsengroot', $itemCount);
             add_item($user_id, 'tigersalve', $itemCount);
             $generic_skill_result_message = 'With intense focus you grind the ' . $itemCount . ' roots into potent formulas.';
         } else {
             // *** no special items, give error message ***
             $turn_cost = 0;
             $generic_skill_result_message = 'You do not have the necessary ginsengroots or energy to create any Kampo formulas.';
         }
     } else {
         if ($command == 'Poison Touch') {
             $covert = true;
예제 #16
0
 /**
  * Get the members of a clan,
  */
 public function getMembers()
 {
     $membersArray = query_array('SELECT uname, accounts.active_email as email, clan_name, level, days, clan_founder, player_id, member_level ' . 'FROM clan JOIN clan_player ON _clan_id = :clan_id AND clan_id = _clan_id JOIN players ON player_id = clan_player._player_id ' . 'JOIN account_players on player_id = account_players._player_id join accounts on account_id = _account_id ' . 'AND active = 1 ORDER BY level, health DESC', [':clan_id' => $this->id()]);
     $max = query_item('SELECT max(level) AS max ' . 'FROM clan ' . 'JOIN clan_player ON _clan_id = :clan_id AND clan_id = _clan_id ' . 'JOIN players ON player_id = _player_id AND active = 1', [':clan_id' => $this->id()]);
     // Modify the members by reference
     foreach ($membersArray as &$member) {
         $member['leader'] = false;
         $member['size'] = floor(($member['level'] - $member['days'] < 1 ? 0 : $member['level'] - $member['days']) / $max * 2) + 1;
         // Calc the member display size based on their level relative to the max.
         if ($member['member_level'] >= 1) {
             $member['leader'] = true;
             $member['size'] = max($member['size'] + 2, 3);
         }
         $member['gravatar_url'] = (new Player($member['player_id']))->avatarUrl();
     }
     return $membersArray;
 }
예제 #17
0
function class_theme($class_identity)
{
    return query_item('SELECT theme FROM class WHERE identity = :class_identity', array(':class_identity' => $class_identity));
}
예제 #18
0
function validate_signup_phase4($enteredClass)
{
    return (bool) query_item('SELECT identity FROM class WHERE class_active AND identity = :id', array(':id' => $enteredClass));
}
예제 #19
0
파일: list.php 프로젝트: reillo/ninjawars
 // 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::is_set('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.
 $alive_count = 0;
 $record_limit = 20;
 // *** The number of players that gets shown per page.
 $view_type = in('view_type');
 $rank = get_rank($char_id);
 $dead_count = query_item("SELECT count(player_id) FROM rankings WHERE alive = false");
 $page = in('page');
 if (!$searched && $hide_setting != $hide) {
     SESSION::set('hide_dead', $hide);
 }
 // Save the toggled state for later.
 // Display the clear search and create the where clause for searching.
 // If a search was made, specify letter or word-based search.
 // If unless showing dead, check that health is > 0, or alive = true from the ranking.
 // Otherwise, no searching was done, so the score
 $where_clauses = array();
 // Array to add where clauses to.
 // Select some players from the ranking.
 $queryParams = array();
 if ($searched) {
     $view_type = 'searched';
예제 #20
0
 public function testSuccessfulSignupResultsInNoConfirmation()
 {
     $uname = 'KnownGood';
     $email = '*****@*****.**';
     // Due to the nature of hotmail, hotmail emails are listed
     // such that they will not be preconfirmed.  This leaves an account needing confirmation.
     RequestWrapper::inject(new Request(['key' => 'password1', 'cpass' => 'password1', 'send_email' => $email, 'send_name' => $uname]));
     $controller = new SignupController();
     $response = $controller->signup($this->m_dependencies);
     $account = Account::findByEmail($email);
     $player = Player::findByName($uname);
     $this->assertNotNull($player);
     $this->assertNotNull($account);
     $query_relationship = 'SELECT count(*) FROM account_players WHERE _account_id = :id1 AND _player_id = :id2';
     $account_unconfirmed = null;
     if ($account && $player) {
         $relationship_count = query_item($query_relationship, [':id1' => $account->id(), ':id2' => $player->id()]);
         $account_unconfirmed = !$account->isConfirmed();
     } else {
         $relationship_count = 0;
     }
     $delete_player = 'DELETE FROM players WHERE player_id = :id';
     $delete_account = 'DELETE FROM accounts WHERE account_id = :id';
     $delete_relationship = 'DELETE FROM account_players WHERE _account_id = :id1 OR _player_id = :id2';
     query($delete_player, [':id' => $player->id()]);
     query($delete_account, [':id' => $account->id()]);
     query($delete_relationship, [':id1' => $account->id(), ':id2' => $player->id()]);
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $this->assertTrue($response_data['submit_successful'], 'Signup() returned error: ' . $response_data['error']);
     $this->assertEquals($relationship_count, 1);
     $this->assertTrue($account_unconfirmed);
 }
예제 #21
0
require_once realpath(__DIR__) . '/resources.php';
ob_start();
assert(defined('WEB_ROOT'));
assert(defined('DEBUG'));
assert(defined('ROOT'));
assert(defined('SERVER_ROOT'));
assert(defined('DATABASE_PASSWORD'));
assert('' !== WEB_ROOT);
assert('http:///' !== WEB_ROOT);
$out = ob_get_contents();
ob_end_clean();
echo $out;
// How about some includes
require SERVER_ROOT . 'lib/base.inc.php';
require_once VENDOR_ROOT . 'autoload.php';
$connected = (bool) query_item('select 1 from players limit 1');
$is_superuser = (bool) query_item('select usesuper from pg_user where usename = CURRENT_USER;') === true;
if ($is_superuser) {
    echo 'Running as superuser!  This will hide problems later!';
}
if (!$connected) {
    echo 'Unable to select from players table of database!';
}
if ((bool) $out || !$connected || $is_superuser) {
    echo "Failure";
    return 1;
} else {
    echo "Success";
    return 0;
}
예제 #22
0
 public function health()
 {
     $id = $this->id();
     $sel = "SELECT health from players where player_id = :id";
     return query_item($sel, array(':id' => array($id, PDO::PARAM_INT)));
 }
예제 #23
0
 /**
  * Check that attack spamming isn't occurring too fast
  *
  * @return bool
  */
 private function isOverTimeLimit()
 {
     $attackIntervalLimit = '.25';
     // Originally .2
     $lastAttackQuery = "SELECT player_id FROM players\n            WHERE player_id = :char_id\n            AND ((now() - :interval::interval) >= last_started_attack) LIMIT 1";
     // *** Returns a player id if the enough time has passed, or else or false/null. ***
     return (bool) query_item($lastAttackQuery, [':char_id' => intval($this->attacker->id()), ':interval' => $attackIntervalLimit . ' second']);
 }
예제 #24
0
 private function checkTestPasswordMatches($pass)
 {
     $phash = query_item('select phash from accounts where account_id = :id', [':id' => $this->account_id]);
     return password_verify($pass, $phash);
 }
예제 #25
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']];
 }
예제 #26
0
    /**
     * group accountconf
     **/
    function testPauseAccountAndLoginShouldFail()
    {
        $confirm_worked = confirm_player($this->test_ninja_name, false, true);
        // name, no confirm #, just autoconfirm.
        $this->assertTrue((bool) $confirm_worked);
        $char_id = get_char_id($this->test_ninja_name);
        $paused = @pauseAccount($char_id);
        // Fully pause the account, make the operational bit = false
        $this->assertTrue((bool) $paused);
        $account_operational = query_item('select operational from accounts 
				join account_players on account_id = _account_id where _player_id = :char_id', array(':char_id' => $char_id));
        $this->assertFalse($account_operational);
        $res = @login_user($this->test_email, $this->test_password);
        $this->assertFalse($res['success'], 'Login should not be successful when account is paused');
        $this->assertTrue(is_string($res['login_error']));
        $this->assertTrue((bool) $res['login_error']);
    }
예제 #27
0
 /**
  * Get the game environment hour
  * @return int
  */
 private static function gameHour()
 {
     return query_item('select amount from time where time_label = \'hours\'');
 }
예제 #28
0
 /**
  * Get the ninja list and display it
  *
  * @param Container
  * @return Response
  */
 public function index(Container $p_dependencies)
 {
     $request = RequestWrapper::$request;
     $session = $p_dependencies['session'];
     $searched = $request->get('searched', null);
     // 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' : $request->get('hide', $hide_setting);
     // search override > get setting > session setting
     $alive_only = $hide == 'dead';
     $page = $request->get('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) {
         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 = $request->get('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 = count($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 new StreamedViewResponse($title, $template, $parts, $options);
 }
예제 #29
0
function clan_char_is_leader_of($char_id, $clan_id = null)
{
    $sel = 'SELECT clan_id
        FROM clan JOIN clan_player ON clan_id = _clan_id
        WHERE _player_id = :char_id AND member_level > 0 ORDER BY clan_id LIMIT 1';
    $id = query_item($sel, array(':char_id' => array($char_id, PDO::PARAM_INT)));
    return $id ? get_clan($id) : null;
}
예제 #30
0
function get_chat_count()
{
    return query_item("SELECT count(*) FROM chat");
}