Пример #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 buildBase(\PDO $pdo_db, array $langvars, int $planet_id, int $sector_id, Reg $tkireg)
 {
     $request = Request::createFromGlobals();
     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>";
     // Get playerinfo from database
     $sql = "SELECT * FROM ::prefix::ships WHERE email=:email LIMIT 1";
     $stmt = $pdo_db->prepare($sql);
     $stmt->bindParam(':email', $_SESSION['username']);
     $stmt->execute();
     $playerinfo = $stmt->fetch(\PDO::FETCH_ASSOC);
     $sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1";
     $stmt = $pdo_db->prepare($sql);
     $stmt->bindParam(':planet_id', $planet_id);
     $stmt->execute();
     $planetinfo = $stmt->fetch(\PDO::FETCH_ASSOC);
     // Error out and return if the Player isn't the owner of the Planet
     // Verify player owns the planet which is to have the base created on.
     if ($planetinfo['owner'] != $playerinfo['ship_id']) {
         echo "<div style='color:#f00; font-size:16px;'>" . $langvars['l_pr_make_base_failed'] . "</div>\n";
         echo "<div style='color:#f00; font-size:16px;'>" . $langvars['l_pr_invalid_info'] . "</div>\n";
         return (bool) false;
     }
     if (!is_numeric($planet_id) || !is_numeric($sector_id)) {
         $ip = $request->query->get('REMOTE_ADDR');
         $hack_id = 0x1337;
         \Tki\AdminLog::writeLog($pdo_db, LOG_ADMIN_PLANETCHEAT, "{$hack_id}|{$ip}|{$planet_id}|{$sector_id}|{$playerinfo['ship_id']}");
         echo "<div style='color:#f00; font-size:16px;'>" . $langvars['l_pr_make_base_failed'] . "</div>\n";
         return (bool) false;
     }
     // Build a base
     \Tki\Realspace\realSpaceMove($pdo_db, $langvars, $sector_id, $tkireg);
     echo "<br>";
     echo str_replace("[here]", "<a href='planet.php?planet_id={$planet_id}'>" . $langvars['l_here'] . "</a>", $langvars['l_pr_click_return_planet']);
     echo "<br><br>";
     if ($planetinfo['ore'] >= $tkireg->base_ore && $planetinfo['organics'] >= $tkireg->base_organics && $planetinfo['goods'] >= $tkireg->base_goods && $planetinfo['credits'] >= $tkireg->base_credits) {
         // Create The Base
         $stmt = $pdo_db->prepare("UPDATE ::prefix::planets SET base='Y', ore = :planetore - :baseore, organics = :planetorg - :baseorg, goods = :planetgoods - :basegoods, credits = :planetcredits - :basecredits WHERE planet_id = :planet_id");
         $stmt->bindParam(':planetore', $planetinfo['ore']);
         $stmt->bindParam(':baseore', $tkireg->base_ore);
         $stmt->bindParam(':planetorg', $planetinfo['organics']);
         $stmt->bindParam(':baseorg', $tkireg->base_organics);
         $stmt->bindParam(':planetgoods', $planetinfo['goods']);
         $stmt->bindParam(':basegoods', $tkireg->base_goods);
         $stmt->bindParam(':planetcredits', $planetinfo['credits']);
         $stmt->bindParam(':basecredits', $tkireg->base_credits);
         $stmt->bindParam(':planet_id', $planet_id);
         $result = $stmt->execute();
         \Tki\Db::logDbErrors($pdo_db, $result, __LINE__, __FILE__);
         // Update User Turns
         $stmt = $pdo_db->prepare("UPDATE ::prefix::ships SET turns = turns - 1, turns_used = turns_used + 1 WHERE ship_id = :ship_id");
         $stmt->bindParam(':ship_id', $playerinfo['ship_id']);
         $result = $stmt->execute();
         \Tki\Db::logDbErrors($pdo_db, $result, __LINE__, __FILE__);
         // Refresh Planet Info
         $sql = "SELECT * FROM ::prefix::planets WHERE planet_id=:planet_id LIMIT 1";
         $stmt = $pdo_db->prepare($sql);
         $stmt->bindParam(':planet_id', $planet_id);
         $stmt->execute();
         $planetinfo = $stmt->fetch(\PDO::FETCH_ASSOC);
         // Notify User Of Base Results
         echo $langvars['l_planet_bbuild'] . "<br><br>";
         // Calc Ownership and Notify User Of Results
         $ownership = \Tki\Ownership::calc($pdo_db, $playerinfo['sector'], $tkireg->min_bases_to_own, $langvars);
         if ($ownership !== null) {
             echo $ownership . "<p>";
         }
         return $planetinfo;
     }
 }