Пример #1
0
 public static function collectCredits(\PDO $pdo_db, \ADODB_mysqli $db, array $langvars, array $planetarray, Reg $tkireg)
 {
     $request = Request::createFromGlobals();
     $CS = "GO";
     // Current State
     // Look up the info for the player that wants to collect the credits.
     $result1 = $db->SelectLimit("SELECT * FROM {$db->prefix}ships WHERE email = ?", 1, -1, array('email' => $_SESSION['username']));
     \Tki\Db::LogDbErrors($pdo_db, $result1, __LINE__, __FILE__);
     $playerinfo = $result1->fields;
     // Set s_p_pair as an array.
     $s_p_pair = array();
     // Create an array of sector -> planet pairs
     $temp_count = count($planetarray);
     for ($i = 0; $i < $temp_count; $i++) {
         $res = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id = ?;", array($planetarray[$i]));
         \Tki\Db::LogDbErrors($pdo_db, $res, __LINE__, __FILE__);
         // Only add to array if the player owns the planet.
         if ($res->fields['owner'] == $playerinfo['ship_id'] && $res->fields['sector_id'] < $tkireg->max_sectors) {
             $s_p_pair[$i] = array($res->fields['sector_id'], $planetarray[$i]);
         } else {
             $hack_id = 20100401;
             $ip = $request->query->get('REMOTE_ADDR');
             $planet_id = $res->fields['planet_id'];
             $sector_id = $res->fields['sector_id'];
             \Tki\AdminLog::writeLog($pdo_db, LOG_ADMIN_PLANETCHEAT, "{$hack_id}|{$ip}|{$planet_id}|{$sector_id}|{$playerinfo['ship_id']}");
             break;
         }
     }
     // Sort the array so that it is in order of sectors, lowest number first, not closest
     sort($s_p_pair);
     reset($s_p_pair);
     // Run through the list of sector planet pairs realspace moving to each sector and then performing the transfer.
     // Based on the way realspace works we don't need a sub loop -- might add a subloop to clean things up later.
     $temp_count2 = count($s_p_pair);
     for ($i = 0; $i < $temp_count2 && $CS == "GO"; $i++) {
         echo "<br>";
         $CS = \Tki\Realspace\realSpaceMove($pdo_db, $langvars, $s_p_pair[$i][0], $tkireg);
         if ($CS == "HOSTILE") {
             $CS = "GO";
         } elseif ($CS == "GO") {
             $CS = self::takeCredits($pdo_db, $db, $langvars, $s_p_pair[$i][1]);
         } else {
             echo "<br>" . $langvars['l_pr_low_turns'] . "<br>";
         }
         echo "<br>";
     }
     if ($CS != "GO" && $CS != "HOSTILE") {
         echo "<br>" . $langvars['l_pr_low_turns'] . "<br>";
     }
     echo "<br>";
     echo str_replace("[here]", "<a href='planet_report.php?preptype=1'>" . $langvars['l_here'] . "</a>", $langvars['l_pr_click_return_status']);
     echo "<br><br>";
 }
Пример #2
0
 public static function xenobeHunter(\PDO $pdo_db, \ADODB_mysqli $db, array $playerinfo, $xenobeisdead, array $langvars, Reg $tkireg)
 {
     $targetinfo = array();
     $rescount = $db->Execute("SELECT COUNT(*) AS num_players FROM {$db->prefix}ships WHERE ship_destroyed='N' AND email NOT LIKE '%@xenobe' AND ship_id > 1");
     \Tki\Db::LogDbErrors($pdo_db, $rescount, __LINE__, __FILE__);
     $rowcount = $rescount->fields;
     $topnum = min(10, $rowcount['num_players']);
     // If we have killed all the players in the game then stop here.
     if ($topnum < 1) {
         return;
     }
     $res = $db->SelectLimit("SELECT * FROM {$db->prefix}ships WHERE ship_destroyed='N' AND email NOT LIKE '%@xenobe' AND ship_id > 1 ORDER BY score DESC", $topnum);
     \Tki\Db::LogDbErrors($pdo_db, $res, __LINE__, __FILE__);
     // Choose a target from the top player list
     $i = 1;
     $targetnum = random_int(1, $topnum);
     while (!$res->EOF) {
         if ($i == $targetnum) {
             $targetinfo = $res->fields;
         }
         $i++;
         $res->MoveNext();
     }
     // Make sure we have a target
     if (!$targetinfo) {
         \Tki\PlayerLog::WriteLog($pdo_db, $playerinfo['ship_id'], LOG_RAW, "Hunt Failed: No Target ");
         return;
     }
     // Jump to target sector
     $sectres = $db->Execute("SELECT sector_id, zone_id FROM {$db->prefix}universe WHERE sector_id = ?;", array($targetinfo['sector']));
     \Tki\Db::LogDbErrors($pdo_db, $sectres, __LINE__, __FILE__);
     $sectrow = $sectres->fields;
     $zoneres = $db->Execute("SELECT zone_id,allow_attack FROM {$db->prefix}zones WHERE zone_id = ?;", array($sectrow['zone_id']));
     \Tki\Db::LogDbErrors($pdo_db, $zoneres, __LINE__, __FILE__);
     $zonerow = $zoneres->fields;
     // Only travel there if we can attack in the target sector
     if ($zonerow['allow_attack'] == "Y") {
         $stamp = date("Y-m-d H:i:s");
         $move_result = $db->Execute("UPDATE {$db->prefix}ships SET last_login = ?, turns_used = turns_used + 1, sector = ? WHERE ship_id = ?", array($stamp, $targetinfo['sector'], $playerinfo['ship_id']));
         \Tki\Db::LogDbErrors($pdo_db, $move_result, __LINE__, __FILE__);
         \Tki\PlayerLog::WriteLog($pdo_db, $playerinfo['ship_id'], LOG_RAW, "Xenobe used a wormhole to warp to sector {$targetinfo['sector']} where he is hunting player {$targetinfo['character_name']}.");
         if (!$move_result) {
             $error = $db->ErrorMsg();
             \Tki\PlayerLog::WriteLog($pdo_db, $playerinfo['ship_id'], LOG_RAW, "Move failed with error: {$error} ");
             return;
         }
         // Check for sector defenses
         $i = 0;
         $all_sector_fighters = 0;
         $defenses = array();
         $sql = "SELECT * FROM ::prefix::sector_defense WHERE sector_id = :sector_id AND defense_type = 'F' ORDER BY quantity DESC";
         $stmt = $pdo_db->prepare($sql);
         $stmt->bindParam(':sector_id', $targetinfo['sector']);
         $stmt->execute();
         $defenses_present = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         if ($defenses_present !== null) {
             foreach ($defenses_present as $tmp_defense) {
                 $defenses[$i] = $tmp_defense;
                 $all_sector_fighters += $defenses[$i]['quantity'];
                 $i++;
             }
         }
         $i = 0;
         $total_sector_mines = 0;
         $sql = "SELECT * FROM ::prefix::sector_defense WHERE sector_id = :sector_id AND defense_type = 'M'";
         $stmt = $pdo_db->prepare($sql);
         $stmt->bindParam(':sector_id', $targetinfo['sector']);
         $stmt->execute();
         $defenses_present = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         if ($defenses_present !== null) {
             foreach ($defenses_present as $tmp_defense) {
                 $defenses[$i] = $tmp_defense;
                 $total_sector_mines += $defenses[$i]['quantity'];
                 $i++;
             }
         }
         if ($all_sector_fighters > 0 || $total_sector_mines > 0 || $all_sector_fighters > 0 && $total_sector_mines > 0) {
             // Attack sector defenses
             $targetlink = $targetinfo['sector'];
             self::xenobeToSecDef($pdo_db, $db, $langvars, $playerinfo, $targetlink, $tkireg);
         }
         if ($xenobeisdead > 0) {
             return;
             // Sector defenses killed the Xenobe
         }
         \Tki\PlayerLog::WriteLog($pdo_db, $playerinfo['ship_id'], LOG_RAW, "Xenobe launching an attack on {$targetinfo['character_name']}.");
         // Attack the target
         if ($targetinfo['planet_id'] > 0) {
             self::xenobeToPlanet($pdo_db, $db, $targetinfo['planet_id'], $tkireg, $playerinfo, $langvars);
             // Yes, so move to that planet
         } else {
             self::xenobeToShip($pdo_db, $db, $targetinfo['ship_id'], $tkireg, $playerinfo, $langvars);
             // Not on a planet, so move to the ship
         }
     } else {
         \Tki\PlayerLog::WriteLog($pdo_db, $playerinfo['ship_id'], LOG_RAW, "Xenobe hunt failed, target {$targetinfo['character_name']} was in a no attack zone (sector {$targetinfo['sector']}).");
     }
 }